ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBDatabase.pas
(Generate patch)

Comparing ibx/trunk/runtime/IBDatabase.pas (file contents):
Revision 33 by tony, Sat Jul 18 12:30:52 2015 UTC vs.
Revision 37 by tony, Mon Feb 15 14:44:25 2016 UTC

# Line 183 | Line 183 | type
183      FDataSets: TList;
184      FLoginCalled: boolean;
185      FCharSetSizes: array of integer;
186 +    FCharSetNames: array of string;
187      procedure EnsureInactive;
188      function GetDBSQLDialect: Integer;
189      function GetSQLDialect: Integer;
# Line 443 | Line 444 | type
444      procedure DoAfterInsert(Sender: TObject); virtual;
445      procedure DoAfterPost(Sender: TObject); virtual;
446      function GetCharSetSize(CharSetID: integer): integer;
447 +    function GetDefaultCharSetSize: integer;
448 +    function GetCharSetName(CharSetID: integer): string;
449 +    function GetDefaultCharSetName: string;
450      procedure HandleException(Sender: TObject);
451      procedure SetCursor;
452      procedure RestoreCursor;
# Line 590 | Line 594 | end;
594  
595   procedure TIBDataBase.CheckDatabaseName;
596   begin
597 <  if (FDBName = '') then
597 >  if (Trim(FDBName) = '') then
598      IBError(ibxeDatabaseNameMissing, [nil]);
599   end;
600  
# Line 630 | Line 634 | begin
634      InternalClose(False);
635    FDBSQLDialect := 1;
636    SetLength(FCharSetSizes,0);
637 +  SetLength(FCharSetNames,0);
638   end;
639  
640   procedure TIBDataBase.CreateDatabase;
# Line 834 | Line 839 | begin
839    try
840      Query.Database := Self;
841      Query.Transaction := FInternalTransaction;
842 <    Query.SQL.Text := 'Select RDB$CHARACTER_SET_ID, RDB$BYTES_PER_CHARACTER ' +
842 >    Query.SQL.Text := 'Select RDB$CHARACTER_SET_ID, RDB$BYTES_PER_CHARACTER, RDB$CHARACTER_SET_NAME ' +
843                        'From RDB$CHARACTER_SETS Order by 1 DESC'; {do not localize}
844      Query.Prepare;
845      Query.ExecQuery;
846      if not Query.EOF then
847      begin
848        SetLength(FCharSetSizes,Query.FieldByName('RDB$CHARACTER_SET_ID').AsInteger + 1);
849 +      SetLength(FCharSetNames,Query.FieldByName('RDB$CHARACTER_SET_ID').AsInteger + 1);
850        for i := 0 to Length(FCharSetSizes) - 1 do FCharSetSizes[i] := 1;
851        repeat
852          FCharSetSizes[Query.FieldByName('RDB$CHARACTER_SET_ID').AsInteger] :=
853                   Query.FieldByName('RDB$BYTES_PER_CHARACTER').AsInteger;
854 +        FCharSetNames[Query.FieldByName('RDB$CHARACTER_SET_ID').AsInteger] :=
855 +                 Query.FieldByName('RDB$CHARACTER_SET_NAME').AsString;
856          Query.Next;
857        until Query.EOF;
858      end;
# Line 1006 | Line 1014 | var
1014    TempDBParams: TStrings;
1015    I: integer;
1016    aDBName: string;
1017 +
1018 +  {Call error analysis}
1019 +  sqlcode: Long;
1020 +  IBErrorCode: Long;
1021 +  status_vector: PISC_STATUS;
1022   begin
1023    CheckInactive;
1024    CheckDatabaseName;
# Line 1022 | Line 1035 | begin
1035    try
1036     TempDBParams.Assign(FDBParams);
1037     aDBName := FDBName;
1038 <   {Opportuning to override defaults}
1038 >   {Opportunity to override defaults}
1039     for i := 0 to FSQLObjects.Count - 1 do
1040     begin
1041         if FSQLObjects[i] <> nil then
# Line 1046 | Line 1059 | begin
1059    finally
1060     TempDBParams.Free;
1061    end;
1062 <  if Call(isc_attach_database(StatusVector, Length(aDBName),
1062 >  repeat
1063 >    if Call(isc_attach_database(StatusVector, Length(aDBName),
1064                           PChar(aDBName), @FHandle,
1065                           FDPBLength, FDPB), False) > 0 then
1066 <  begin
1067 <    FHandle := nil;
1068 <    IBDataBaseError;
1069 <  end;
1066 >    begin
1067 >      {$IFDEF UNIX}
1068 >      if IsEmbeddedServer and (Pos(':',aDBName) = 0) then
1069 >      begin
1070 >        status_vector := StatusVector;
1071 >        IBErrorCode := StatusVectorArray[1];
1072 >        sqlcode := isc_sqlcode(StatusVector);
1073 >
1074 >        if ((sqlcode = -901) and (IBErrorCode = 335544382)) {Access permissions on firebird temp}
1075 >           or
1076 >           ((sqlcode = -902) and (IBErrorCode = 335544373)) {Security DB Problem}
1077 >           then
1078 >           begin
1079 >             aDBName := 'localhost:' + aDBName;
1080 >             Continue;
1081 >           end;
1082 >      end;
1083 >      {$ENDIF}
1084 >      FHandle := nil;
1085 >      IBDataBaseError;
1086 >    end;
1087 >  until FHandle <> nil;
1088    if not (csDesigning in ComponentState) then
1089      FDBName := aDBName; {Synchronise at run time}
1090    FDBSQLDialect := GetDBSQLDialect;
# Line 2023 | Line 2055 | begin
2055      Result := 1; {Unknown character set}
2056   end;
2057  
2058 + function TIBBase.GetDefaultCharSetSize: integer;
2059 + var DefaultCharSetName: string;
2060 +    i: integer;
2061 + begin
2062 +  DefaultCharSetName := GetDefaultCharSetName;
2063 +  Result := 4; {worse case}
2064 +  for i := 0 to Length(Database.FCharSetSizes) - 1 do
2065 +    if Database.FCharSetNames[i] = DefaultCharSetName then
2066 +    begin
2067 +      Result := Database.FCharSetSizes[i];
2068 +      break;
2069 +    end;
2070 + end;
2071 +
2072 + function TIBBase.GetCharSetName(CharSetID: integer): string;
2073 + begin
2074 +  if (CharSetID >= 0) and (CharSetID < Length(Database.FCharSetNames)) then
2075 +    Result := Database.FCharSetNames[CharSetID]
2076 +  else
2077 +    Result := ''; {Unknown character set}
2078 + end;
2079 +
2080 + function TIBBase.GetDefaultCharSetName: string;
2081 + begin
2082 +  Result := AnsiUpperCase(Database.Params.Values['lc_ctype']);
2083 + end;
2084 +
2085   procedure TIBBase.HandleException(Sender: TObject);
2086   begin
2087    if assigned(Database) then

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines