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

Comparing ibx/trunk/runtime/IBTable.pas (file contents):
Revision 4 by tony, Mon Jul 31 16:43:00 2000 UTC vs.
Revision 5 by tony, Fri Feb 18 16:26:16 2011 UTC

# Line 28 | Line 28
28  
29   unit IBTable;
30  
31 < interface
31 > {$Mode Delphi}
32  
33 < uses Windows, SysUtils, Graphics, Classes, Controls, Db, StdVCL,
34 <     IB, IBDatabase, IBCustomDataSet, IBHeader, IBSQL, IBUtils;
33 > interface
34  
35 + uses SysUtils, Classes, DB, IB,  IBCustomDataSet,
36 +     IBHeader, IBSQL, IBUtils;
37 +    
38   type
39  
40   { TIBTable }
# Line 103 | Line 105 | type
105      procedure Reopen;
106  
107    protected
106    { IProviderSupport }
107    function PSGetDefaultOrder: TIndexDef; override;
108    function PSGetKeyFields: string; override;
109    function PSGetTableName: string; override;
110    function PSGetIndexDefs(IndexTypes: TIndexOptions): TIndexDefs; override;
111    procedure PSSetCommandText(const CommandText: string); override;
112    procedure PSSetParams(AParams: TParams); override;
108  
109      procedure DoOnNewRecord; override;
110      procedure GetIndexParams(const IndexName: string; FieldsIndex: Boolean;
111        var IndexedName: string);
112      function GetCanModify: Boolean; override;
113      procedure UpdateIndexDefs; override;
114 <    procedure DataEvent(Event: TDataEvent; Info: Longint); override;
115 <    procedure DefChanged(Sender: TObject); override;
114 >    procedure DataEvent(Event: TDataEvent; Info: Ptrint); override;
115 >    procedure DefChanged(Sender: TObject); virtual;
116      function GetDataSource: TDataSource; override;
117      procedure InitFieldDefs; override;
118      procedure InternalClose; override;
# Line 137 | Line 132 | type
132      procedure DeleteIndex(const Name: string);
133      procedure DeleteTable;
134      procedure EmptyTable;
135 <    procedure GetDetailLinkFields(MasterFields, DetailFields: TList); override;
135 >    procedure GetDetailLinkFields(MasterFields, DetailFields: TList); virtual;
136      procedure GetIndexNames(List: TStrings);
137      procedure GotoCurrent(Table: TIBTable);
138      property CurrentDBKey: TIBDBKey read GetCurrentDBKey;
# Line 285 | Line 280 | begin
280      QRefresh.SQL.Assign(WherePrimaryRefreshSQL)
281    else
282      QRefresh.SQL.Assign(WhereAllRefreshSQL);
283 <  inherited;
283 >  inherited InternalRefreshRow;
284   end;
285  
286   procedure TIBTable.DefChanged(Sender: TObject);
# Line 316 | Line 311 | begin
311                          'from RDB$RELATION_FIELDS R, RDB$FIELDS F ' + {do not localize}
312                          'where R.RDB$RELATION_NAME = ' + {do not localize}
313                          '''' +
314 <                        FormatIdentifierValue(Database.SQLDialect, FTableName) +
314 >                        FormatIdentifierValue(Database.SQLDialect,
315 >                          QuoteIdentifier(DataBase.SQLDialect, FTableName)) +
316                          ''' ' +
317                          'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize}
318                          'order by R.RDB$FIELD_POSITION'; {do not localize}
# Line 329 | Line 325 | begin
325        begin
326            with FieldDefs.AddFieldDef do
327            begin
328 <            FieldNo := Query.Current.ByName('RDB$FIELD_POSITION').AsInteger; {do not localize}
328 > (*           FieldNo := Query.Current.ByName('RDB$FIELD_POSITION').AsInteger; {do not localize}*)
329              Name := TrimRight(Query.Current.ByName('RDB$FIELD_NAME').AsString); {do not localize}
330              case Query.Current.ByName('RDB$FIELD_TYPE').AsInteger of {do not localize}
331 <              blr_varying, blr_text: begin
331 >              blr_varying, blr_text:
332 >              begin
333                  DataType := ftString;
334                  Size := Query.Current.ByName('RDB$FIELD_LENGTH').AsInteger; {do not localize}
335                end;
336                blr_float, blr_double, blr_d_float: DataType := ftFloat;
337 <              blr_short: begin
337 >              blr_short:
338 >              begin
339                  sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize}
340                  if (sqlscale = 0) then
341                    DataType := ftSmallInt
342 <                else begin
342 >                else
343 >                begin
344                    DataType := ftBCD;
345                    Precision := 4;
346                  end;
347                end;
348 <              blr_long: begin
348 >              blr_long:
349 >              begin
350                  sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize}
351                  if (sqlscale = 0) then
352                    DataType := ftInteger
353 <                else if (sqlscale >= (-4)) then begin
353 >                else if (sqlscale >= (-4)) then
354 >                begin
355                    DataType := ftBCD;
356                    Precision := 9;
357 <                end else
357 >                end
358 >                else
359                    DataType := ftFloat;
360                end;
361 <              blr_int64: begin
361 >              blr_int64:
362 >              begin
363                  sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize}
364                  if (sqlscale = 0) then
365                    DataType := ftLargeInt
366 <                else if (sqlscale >= (-4)) then begin
366 >                else if (sqlscale >= (-4)) then
367 >                begin
368                    DataType := ftBCD;
369                    Precision := 18;
370 <                end else
370 >                end
371 >                else
372                    DataType := ftFloat;
373                end;
374                blr_timestamp: DataType := ftDateTime;
# Line 374 | Line 379 | begin
379                    DataType := ftMemo
380                  else
381                    DataType := ftBlob;
382 <              blr_quad: begin
382 >              blr_quad:
383 >              begin
384                  DataType := ftUnknown;
385                  Size := sizeof (TISC_QUAD);
386                end;
# Line 390 | Line 396 | begin
396                InternalCalcField := False;
397              if ((not InternalCalcField) and
398                   Query.Current.ByName('RDB$DEFAULT_VALUE').IsNull and {do not localize}
399 <                 (Query.Current.ByName('RDB$NULL_FLAG').AsInteger = 1) )then begin {do not localize}
399 >                 (Query.Current.ByName('RDB$NULL_FLAG').AsInteger = 1) )then {do not localize}
400 >            begin
401                Attributes := [faRequired];
402                Required := True;
403              end;
# Line 425 | Line 432 | begin
432      if (ixPrimary in Options) then
433      begin
434       Query.SQL.Text := 'Alter Table ' + {do not localize}
435 <       FormatIdentifier(Database.SQLDialect, FTableName) +
435 >       QuoteIdentifier(Database.SQLDialect, FTableName) +
436         ' Add CONSTRAINT ' +   {do not localize}
437 <       FormatIdentifier(Database.SQLDialect, Name)
437 >       QuoteIdentifier(Database.SQLDialect, Name)
438         + ' Primary Key (' + {do not localize}
439         FormatFieldsList(Fields) +
440         ')';
441      end
442      else if ([ixUnique, ixDescending] * Options = [ixUnique, ixDescending]) then
443        Query.SQL.Text := 'Create unique Descending Index ' + {do not localize}
444 <                        FormatIdentifier(Database.SQLDialect, Name) +
444 >                        QuoteIdentifier(Database.SQLDialect, Name) +
445                          ' on ' + {do not localize}
446 <                        FormatIdentifier(Database.SQLDialect, FTableName) +
446 >                        QuoteIdentifier(Database.SQLDialect, FTableName) +
447                          ' (' + FieldList + ')'
448      else if (ixUnique in Options) then
449        Query.SQL.Text := 'Create unique Index ' + {do not localize}
450 <                        FormatIdentifier(Database.SQLDialect, Name) +
450 >                        QuoteIdentifier(Database.SQLDialect, Name) +
451                          ' on ' + {do not localize}
452 <                        FormatIdentifier(Database.SQLDialect, FTableName) +
452 >                        QuoteIdentifier(Database.SQLDialect, FTableName) +
453                          ' (' + FieldList + ')'
454      else if (ixDescending in Options) then
455        Query.SQL.Text := 'Create Descending Index ' + {do not localize}
456 <                        FormatIdentifier(Database.SQLDialect, Name) +
456 >                        QuoteIdentifier(Database.SQLDialect, Name) +
457                          ' on ' + {do not localize}
458 <                        FormatIdentifier(Database.SQLDialect, FTableName) +
458 >                        QuoteIdentifier(Database.SQLDialect, FTableName) +
459                          ' (' + FieldList + ')'
460      else
461        Query.SQL.Text := 'Create Index ' + {do not localize}
462 <                        FormatIdentifier(Database.SQLDialect, Name) +
462 >                        QuoteIdentifier(Database.SQLDialect, Name) +
463                          ' on ' + {do not localize}
464 <                        FormatIdentifier(Database.SQLDialect, FTableName) +
464 >                        QuoteIdentifier(Database.SQLDialect, FTableName) +
465                          ' (' + FieldList + ')';
466      Query.Prepare;
467      Query.ExecQuery;
# Line 475 | Line 482 | var
482        Query.Database := DataBase;
483        Query.Transaction := Transaction;
484        Query.SQL.Text := 'Drop index ' +  {do not localize}
485 <                         FormatIdentifier(Database.SQLDialect, Name);
485 >                         QuoteIdentifier(Database.SQLDialect, Name);
486        Query.Prepare;
487        Query.ExecQuery;
488        IndexDefs.Updated := False;
# Line 494 | Line 501 | var
501        Query.SQL.Text := 'Select ''foo'' from RDB$RELATION_CONSTRAINTS ' +
502          'where RDB$RELATION_NAME = ' +
503          '''' +
504 <        FormatIdentifierValue(Database.SQLDialect, FTableName) +
504 >        FormatIdentifierValue(Database.SQLDialect,
505 >          QuoteIdentifier(DataBase.SQLDialect, FTableName)) +
506          ''' ' +
507          ' AND RDB$CONSTRAINT_NAME = ' +
508          '''' +
509 <        FormatIdentifierValue(Database.SQLDialect, Name) +
509 >        FormatIdentifierValue(Database.SQLDialect,
510 >          QuoteIdentifier(DataBase.SQLDialect, Name)) +
511          ''' ' +
512          'AND RDB$CONSTRAINT_TYPE = ''PRIMARY KEY''';
513        Query.Prepare;
# Line 507 | Line 516 | var
516        begin
517          Query.Close;
518          Query.SQL.Text := 'Alter Table ' +  {do not localize}
519 <          FormatIdentifier(Database.SQLDialect, FTableName) +
519 >          QuoteIdentifier(DataBase.SQLDialect, FTableName) +
520            ' Drop Constraint ' +
521 <          FormatIdentifier(Database.SQLDialect, Name);
521 >          QuoteIdentifier(DataBase.SQLDialect, Name);
522          Query.Prepare;
523          Query.ExecQuery;
524          IndexDefs.Updated := False;
# Line 529 | Line 538 | var
538        Query.SQL.Text := 'Select RDB$CONSTRAINT_NAME from RDB$RELATION_CONSTRAINTS ' +
539          'where RDB$RELATION_NAME = ' +
540          '''' +
541 <        FormatIdentifierValue(Database.SQLDialect, FTableName) +
541 >        FormatIdentifierValue(Database.SQLDialect,
542 >          QuoteIdentifier(DataBase.SQLDialect, FTableName)) +
543          ''' ' +
544          'AND RDB$INDEX_NAME = ' +
545          '''' +
546 <        FormatIdentifierValue(Database.SQLDialect, Name) +
546 >        FormatIdentifierValue(Database.SQLDialect,
547 >          QuoteIdentifier(DataBase.SQLDialect, Name)) +
548          ''' ' +
549          'AND RDB$CONSTRAINT_TYPE = ''PRIMARY KEY''';
550        Query.Prepare;
# Line 542 | Line 553 | var
553        begin
554          Query.Close;
555          Query.SQL.Text := 'Alter Table ' +  {do not localize}
556 <          FormatIdentifier(Database.SQLDialect, FTableName) +
556 >          QuoteIdentifier(DataBase.SQLDialect, FTableName) +
557            ' Drop Constraint ' +
558 <          FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$CONSTRAINT_NAME').AsString);
558 >          QuoteIdentifier(DataBase.SQLDialect, Query.Current.ByName('RDB$CONSTRAINT_NAME').AsString);
559          Query.Prepare;
560          Query.ExecQuery;
561          IndexDefs.Updated := False;
# Line 646 | Line 657 | begin
657      'I.RDB$SEGMENT_COUNT, S.RDB$FIELD_NAME from RDB$INDICES I, ' + {do not localize}
658      'RDB$INDEX_SEGMENTS S where I.RDB$INDEX_NAME = S.RDB$INDEX_NAME '+ {do not localize}
659      'and I.RDB$RELATION_NAME = ' + '''' + {do not localize}
660 <     FormatIdentifierValue(Database.SQLDialect, FTableName) + '''';
660 >     FormatIdentifierValue(Database.SQLDialect,
661 >       QuoteIdentifier(DataBase.SQLDialect, FTableName)) + '''';
662      Query.Prepare;
663      Query.ExecQuery;
664      while (not Query.EOF) and (Query.Next <> nil) do
# Line 670 | Line 682 | begin
682            SubQuery.SQL.Text :=
683           'Select RDB$FIELD_NAME from RDB$INDEX_SEGMENTS where RDB$INDEX_NAME = ' + {do not localize}
684            '''' +
685 <          FormatIdentifierValue(Database.SQLDialect, Name) +
685 >          FormatIdentifierValue(Database.SQLDialect,
686 >            QuoteIdentifier(DataBase.SQLDialect, Name)) +
687            '''' + 'ORDER BY RDB$FIELD_POSITION'; {do not localize}
688            SubQuery.Prepare;
689            SubQuery.ExecQuery;
# Line 716 | Line 729 | begin
729      Query.SQL.Text :=
730      'Select USER from RDB$RELATIONS where RDB$RELATION_NAME = ' + {do not localize}
731      '''' +
732 <    FormatIdentifierValue(Database.SQLDialect, FTableName) + '''';
732 >    FormatIdentifierValue(Database.SQLDialect,
733 >      QuoteIdentifier(DataBase.SQLDialect, FTableName)) + '''';
734      Query.Prepare;
735      Query.ExecQuery;
736      Result := not Query.EOF;
# Line 758 | Line 772 | var
772          case DataType of
773            ftString:
774              FieldList := FieldList +
775 <              FormatIdentifier(Database.SQLDialect, Name) +
775 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
776                ' VARCHAR(' + IntToStr(Size) + ')'; {do not localize}
777            ftFixedChar:
778              FieldList := FieldList +
779 <              FormatIdentifier(Database.SQLDialect, Name) +
779 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
780                ' CHAR(' + IntToStr(Size) + ')'; {do not localize}
781            ftBoolean, ftSmallint, ftWord:
782              FieldList := FieldList +
783 <              FormatIdentifier(Database.SQLDialect, Name) +
783 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
784                ' SMALLINT'; {do not localize}
785            ftInteger:
786              FieldList := FieldList +
787 <              FormatIdentifier(Database.SQLDialect, Name) +
787 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
788                ' INTEGER'; {do not localize}
789            ftFloat, ftCurrency:
790              FieldList := FieldList +
791 <              FormatIdentifier(Database.SQLDialect, Name) +
791 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
792                ' DOUBLE PRECISION'; {do not localize}
793            ftBCD: begin
794              if (Database.SQLDialect = 1) then begin
# Line 785 | Line 799 | var
799              end;
800              if (Precision <= 4 ) then
801                FieldList := FieldList +
802 <                FormatIdentifier(Database.SQLDialect, Name) +
802 >                QuoteIdentifier(DataBase.SQLDialect, Name) +
803                  ' Numeric(18, 4)' {do not localize}
804              else
805                FieldList := FieldList +
806 <                FormatIdentifier(Database.SQLDialect, Name) +
806 >                QuoteIdentifier(DataBase.SQLDialect, Name) +
807                  ' Numeric(' + IntToStr(Precision) + ', 4)'; {do not localize}
808            end;
809            ftDate:
810              FieldList := FieldList +
811 <              FormatIdentifier(Database.SQLDialect, Name) +
811 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
812                ' DATE'; {do not localize}
813            ftTime:
814              FieldList := FieldList +
815 <              FormatIdentifier(Database.SQLDialect, Name) +
815 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
816                ' TIME'; {do not localize}
817            ftDateTime:
818              if (Database.SQLDialect = 1) then
819                FieldList := FieldList +
820 <              FormatIdentifier(Database.SQLDialect, Name) +
820 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
821                ' DATE' {do not localize}
822              else
823                FieldList := FieldList +
824 <              FormatIdentifier(Database.SQLDialect, Name) +
824 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
825                ' TIMESTAMP'; {do not localize}
826            ftLargeInt:
827              if (Database.SQLDialect = 1) then
828                IBError(ibxeFieldUnsupportedType,[nil])
829              else
830                FieldList := FieldList +
831 <                FormatIdentifier(Database.SQLDialect, Name) +
831 >                QuoteIdentifier(DataBase.SQLDialect, Name) +
832                  ' Numeric(18, 0)'; {do not localize}
833            ftBlob, ftMemo:
834              FieldList := FieldList +
835 <              FormatIdentifier(Database.SQLDialect, Name) +
835 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
836                ' BLOB SUB_TYPE 1'; {do not localize}
837            ftBytes, ftVarBytes, ftGraphic..ftTypedBinary:
838              FieldList := FieldList +
839 <              FormatIdentifier(Database.SQLDialect, Name) +
839 >              QuoteIdentifier(DataBase.SQLDialect, Name) +
840                ' BLOB SUB_TYPE 0'; {do not localize}
841            ftUnknown, ftADT, ftArray, ftReference, ftDataSet,
842            ftCursor, ftWideString, ftAutoInc:
# Line 848 | Line 862 | var
862        Query.Database := Database;
863        Query.transaction := Transaction;
864        Query.SQL.Text := 'Create Table ' +
865 <        FormatIdentifier(Database.SQLDialect, FTableName) +
865 >        QuoteIdentifier(DataBase.SQLDialect, FTableName) +
866          ' (' + FieldList; {do not localize}
867        for I := 0 to IndexDefs.Count - 1 do
868        with IndexDefs[I] do
869          if ixPrimary in Options then
870          begin
871            Query.SQL.Text := Query.SQL.Text + ', CONSTRAINT ' +
872 <            FormatIdentifier(Database.SQLDialect, Name) +
872 >            QuoteIdentifier(DataBase.SQLDialect, Name) +
873              ' Primary Key (' +
874              FormatFieldsList(Fields) +
875              ')';
# Line 895 | Line 909 | begin
909      Query.Database := DataBase;
910      Query.Transaction := Transaction;
911      Query.SQL.Text := 'drop table ' +  {do not localize}
912 <      FormatIdentifier(Database.SQLDialect, FTableName);
912 >      QuoteIdentifier(DataBase.SQLDialect, FTableName);
913      Query.Prepare;
914      Query.ExecQuery;
915    finally
# Line 914 | Line 928 | begin
928      Query.Database := DataBase;
929      Query.Transaction := Transaction;
930      Query.SQL.Text := 'delete from ' + {do not localize}
931 <      FormatIdentifier(Database.SQLDialect, FTableName);
931 >      QuoteIdentifier(DataBase.SQLDialect, FTableName);
932      Query.Prepare;
933      Query.ExecQuery;
934      if Active then
# Line 927 | Line 941 | begin
941    end;
942   end;
943  
944 < procedure TIBTable.DataEvent(Event: TDataEvent; Info: Longint);
944 > procedure TIBTable.DataEvent(Event: TDataEvent; Info: Ptrint);
945   begin
946    if Event = dePropertyChange then begin
947      IndexDefs.Updated := False;
# Line 958 | Line 972 | begin
972      Query.SQL.Text := 'Select RDB$SYSTEM_FLAG, RDB$DBKEY_LENGTH ' + {do not localize}
973                      'from RDB$RELATIONS where RDB$RELATION_NAME = ' + {do not localize}
974                      '''' +
975 <                    FormatIdentifierValue(Database.SQLDialect, FTableName) + '''';
975 >                    FormatIdentifierValue(Database.SQLDialect,
976 >                      QuoteIdentifier(DataBase.SQLDialect, FTableName)) + '''';
977      Query.Prepare;
978      Query.ExecQuery;
979      if (Query.Current[0].AsInteger <> 0) or
# Line 1048 | Line 1063 | var
1063    i: Integer;
1064   begin
1065    if Database.SQLDialect = 1 then begin
1066 <    Value := FormatIdentifier(Database.SQLDialect, Value);
1066 >    Value := QuoteIdentifier(Database.SQLDialect, Value);
1067      Result := StringReplace (Value, ';', ', ', [rfReplaceAll]);
1068    end
1069    else begin
# Line 1058 | Line 1073 | begin
1073      begin
1074        FieldName := ExtractFieldName(Value, i);
1075        if Result = '' then
1076 <        Result := FormatIdentifier(Database.SQLDialect, FieldName)
1076 >        Result := QuoteIdentifier(Database.SQLDialect, FieldName)
1077        else
1078 <        Result := Result + ', ' + FormatIdentifier(Database.SQLDialect, FieldName);
1078 >        Result := Result + ', ' + QuoteIdentifier(Database.SQLDialect, FieldName);
1079      end;
1080    end;
1081   end;
# Line 1293 | Line 1308 | begin
1308      OrderByStr := FormatFieldsList(FPrimaryIndexFields);
1309    SQL := TStringList.Create;
1310    SQL.Text := 'select ' + {do not localize}
1311 <    FormatIdentifier(Database.SQLDialect, FTableName) + '.*, '
1311 >    QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize}
1312      + 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize}
1313 <    + FormatIdentifier(Database.SQLDialect, FTableName);
1313 >    + QuoteIdentifier(DataBase.SQLDialect, FTableName);
1314    if Filtered and (Filter <> '') then
1315    begin
1316      SQL.Text := SQL.Text + ' where ' + Filter; {do not localize}
# Line 1315 | Line 1330 | begin
1330        if i > 0 then
1331          SQL.Text := SQL.Text + 'AND ';
1332        SQL.Text := SQL.Text +
1333 <        FormatIdentifier(Database.SQLDialect, FDetailFieldsList.Strings[i]) +
1333 >        QuoteIdentifier(DataBase.SQLDialect, FDetailFieldsList.Strings[i]) +
1334          ' = :' +
1335 <        FormatIdentifier(Database.SQLDialect, FMasterFieldsList.Strings[i]);
1335 >        QuoteIdentifier(DataBase.SQLDialect, FMasterFieldsList.Strings[i]);
1336      end;
1337    end;
1338    if OrderByStr <> '' then
1339      SQL.Text := SQL.Text + ' order by ' + OrderByStr; {do not localize}
1340    SelectSQL.Assign(SQL);
1341    RefreshSQL.Text := 'select ' + {do not localize}
1342 <    FormatIdentifier(Database.SQLDialect, FTableName) + '.*, '
1342 >    QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize}
1343      + 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize}
1344 <    + FormatIdentifier(Database.SQLDialect, FTableName) +
1344 >    + QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1345      ' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY'; {do not localize}
1346    WhereDBKeyRefreshSQL.Assign(RefreshSQL);
1347    InternalPrepare;
# Line 1355 | Line 1370 | var
1370                WhereAllFieldList := WhereAllFieldList + ' AND ';
1371            end;
1372            InsertFieldList := InsertFieldList +
1373 <            FormatIdentifier(Database.SQLDialect, Name);
1373 >            QuoteIdentifier(DataBase.SQLDialect, Name);
1374            InsertParamList := InsertParamList + ':' +
1375 <            FormatIdentifier(Database.SQLDialect, Name);
1375 >            QuoteIdentifier(DataBase.SQLDialect, Name);
1376            UpdateFieldList := UpdateFieldList +
1377 <            FormatIdentifier(Database.SQLDialect, Name) +
1377 >            QuoteIdentifier(DataBase.SQLDialect, Name) +
1378              ' = :' +
1379 <            FormatIdentifier(Database.SQLDialect, Name);
1379 >            QuoteIdentifier(DataBase.SQLDialect, Name);
1380            if (DataType <> ftBlob) and (DataType <>ftMemo) then
1381              WhereAllFieldList := WhereAllFieldList +
1382 <              FormatIdentifier(Database.SQLDialect, Name) + ' = :' +
1383 <              FormatIdentifier(Database.SQLDialect, Name);{do not localize}
1382 >              QuoteIdentifier(DataBase.SQLDialect, Name) + ' = :' +
1383 >              QuoteIdentifier(DataBase.SQLDialect, Name);{do not localize}
1384          end;
1385        end;
1386      end;
# Line 1381 | Line 1396 | var
1396      begin
1397        tmp := ExtractFieldName(FPrimaryIndexFields, i);
1398        tmp :=
1399 <        FormatIdentifier(Database.SQLDialect, tmp) +  ' = :' +
1400 <        FormatIdentifier(Database.SQLDialect, tmp);{do not localize}
1399 >        QuoteIdentifier(DataBase.SQLDialect, tmp) +  ' = :' +
1400 >        QuoteIdentifier(DataBase.SQLDialect, tmp);{do not localize}
1401        if WherePrimaryFieldList <> '' then
1402          WherePrimaryFieldList :=
1403            WherePrimaryFieldList + ' AND ' + tmp
# Line 1397 | Line 1412 | begin
1412    else
1413    begin
1414      DeleteSQL.Text := 'delete from ' + {do not localize}
1415 <      FormatIdentifier(Database.SQLDialect, FTableName) +
1415 >      QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1416        ' where RDB$DB_KEY = ' + ':IBX_INTERNAL_DBKEY'; {do not localize}
1417      GenerateFieldLists;
1418      InsertSQL.Text := 'insert into ' + {do not localize}
1419 <      FormatIdentifier(Database.SQLDialect, FTableName) +
1419 >      QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1420      ' (' + InsertFieldList + {do not localize}
1421        ') values (' + InsertParamList + ')'; {do not localize}
1422      ModifySQL.Text := 'update ' +
1423 <      FormatIdentifier(Database.SQLDialect, FTableName) +
1423 >      QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1424        ' set ' + UpdateFieldList + {do not localize}
1425        ' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY'; {do not localize}
1426      WhereAllRefreshSQL.Text := 'select ' +  {do not localize}
1427 <      FormatIdentifier(Database.SQLDialect, FTableName) + '.*, '
1427 >      QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, '
1428        + 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize}
1429 <      + FormatIdentifier(Database.SQLDialect, FTableName) +
1429 >      + QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1430        ' where ' + WhereAllFieldList; {do not localize}
1431      if FPrimaryIndexFields <> '' then
1432      begin
1433        GenerateWherePrimaryFieldList;
1434        WherePrimaryRefreshSQL.Text := 'select ' + {do not localize}
1435 <        FormatIdentifier(Database.SQLDialect, FTableName) + '.*, ' {do not localize}
1435 >        QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize}
1436          + 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize}
1437 <        + FormatIdentifier(Database.SQLDialect, FTableName) +
1437 >        + QuoteIdentifier(DataBase.SQLDialect, FTableName) +
1438          ' where ' + WherePrimaryFieldList; {do not localize}
1439      end;
1440      try
# Line 1499 | Line 1514 | begin
1514      begin
1515        SetState(dsInactive);
1516        CloseCursor;
1517 <      OpenCursor;
1517 >      OpenCursor(false);
1518        SetState(dsBrowse);
1519      end;
1520    finally
# Line 1507 | Line 1522 | begin
1522    end;
1523   end;
1524  
1510 { TIBTable IProviderSupport }
1511
1512 function TIBTable.PSGetDefaultOrder: TIndexDef;
1513
1514  function GetIdx(IdxType: TIndexOption): TIndexDef;
1515  var
1516    i: Integer;
1517  begin
1518    Result := nil;
1519    for i := 0 to IndexDefs.Count - 1 do
1520      if IdxType in IndexDefs[i].Options then
1521      try
1522        Result := IndexDefs[i];
1523        GetFieldList(nil, Result.Fields);
1524        break;
1525      except
1526        Result := nil;
1527      end;
1528  end;
1529
1530 var
1531  DefIdx: TIndexDef;
1532 begin
1533  DefIdx := nil;
1534  IndexDefs.Update;
1535  try
1536    if IndexName <> '' then
1537      DefIdx := IndexDefs.Find(IndexName)
1538    else if IndexFieldNames <> '' then
1539      DefIdx := IndexDefs.FindIndexForFields(IndexFieldNames);
1540    if Assigned(DefIdx) then
1541      GetFieldList(nil, DefIdx.Fields);
1542  except
1543    DefIdx := nil;
1544  end;
1545  if not Assigned(DefIdx) then
1546    DefIdx := GetIdx(ixPrimary);
1547  if not Assigned(DefIdx) then
1548    DefIdx := GetIdx(ixUnique);
1549  if Assigned(DefIdx) then
1550  begin
1551    Result := TIndexDef.Create(nil);
1552    Result.Assign(DefIdx);
1553  end else
1554    Result := nil;
1555 end;
1556
1557 function TIBTable.PSGetIndexDefs(IndexTypes: TIndexOptions): TIndexDefs;
1558 begin
1559  Result := GetIndexDefs(IndexDefs, IndexTypes);
1560 end;
1561
1562 function TIBTable.PSGeTTableName: string;
1563 begin
1564  Result := FTableName;
1565 end;
1566
1567 procedure TIBTable.PSSetParams(AParams: TParams);
1568 begin
1569  if AParams.Count > 0 then
1570    Open;
1571  PSReset;
1572 end;
1573
1574 procedure TIBTable.PSSetCommandText(const CommandText: string);
1575 begin
1576  if CommandText <> '' then
1577    TableName := CommandText;
1578 end;
1579
1580 function TIBTable.PSGetKeyFields: string;
1581 var
1582  i, Idx: Integer;
1583  IndexFound: Boolean;
1584 begin
1585  Result := inherited PSGetKeyFields;
1586  if Result = '' then
1587  begin
1588    if not Exists then Exit;
1589    IndexFound := False;
1590    IndexDefs.Update;
1591    FieldDefs.Update;
1592    for i := 0 to IndexDefs.Count - 1 do
1593      if ixUnique in IndexDefs[I].Options then
1594      begin
1595        Idx := 1;
1596        Result := IndexDefs[I].Fields;
1597        IndexFound := False;
1598        while Idx <= Length(Result) do
1599        begin
1600          IndexFound := FindField(ExtractFieldName(Result, Idx)) <> nil;
1601          if not IndexFound then Break;
1602        end;
1603        if IndexFound then Break;
1604      end;
1605    if not IndexFound then
1606      Result := '';
1607  end;
1608 end;
1609
1525   end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines