24 |
|
{ Corporation. All Rights Reserved. } |
25 |
|
{ Contributor(s): Jeff Overcash } |
26 |
|
{ } |
27 |
+ |
{ IBX For Lazarus (Firebird Express) } |
28 |
+ |
{ Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk } |
29 |
+ |
{ Portions created by MWA Software are copyright McCallum Whyman } |
30 |
+ |
{ Associates Ltd 2011 } |
31 |
+ |
{ } |
32 |
|
{************************************************************************} |
33 |
|
|
34 |
|
unit IBTable; |
35 |
|
|
36 |
< |
interface |
36 |
> |
{$Mode Delphi} |
37 |
|
|
38 |
< |
uses Windows, SysUtils, Graphics, Classes, Controls, Db, StdVCL, |
34 |
< |
IB, IBDatabase, IBCustomDataSet, IBHeader, IBSQL, IBUtils; |
38 |
> |
interface |
39 |
|
|
40 |
+ |
uses SysUtils, Classes, DB, IB, IBCustomDataSet, |
41 |
+ |
IBHeader, IBSQL, IBUtils; |
42 |
+ |
|
43 |
|
type |
44 |
|
|
45 |
|
{ TIBTable } |
110 |
|
procedure Reopen; |
111 |
|
|
112 |
|
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; |
113 |
|
|
114 |
|
procedure DoOnNewRecord; override; |
115 |
|
procedure GetIndexParams(const IndexName: string; FieldsIndex: Boolean; |
116 |
|
var IndexedName: string); |
117 |
|
function GetCanModify: Boolean; override; |
118 |
|
procedure UpdateIndexDefs; override; |
119 |
< |
procedure DataEvent(Event: TDataEvent; Info: Longint); override; |
120 |
< |
procedure DefChanged(Sender: TObject); override; |
119 |
> |
procedure DataEvent(Event: TDataEvent; Info: Ptrint); override; |
120 |
> |
procedure DefChanged(Sender: TObject); virtual; |
121 |
|
function GetDataSource: TDataSource; override; |
122 |
|
procedure InitFieldDefs; override; |
123 |
|
procedure InternalClose; override; |
137 |
|
procedure DeleteIndex(const Name: string); |
138 |
|
procedure DeleteTable; |
139 |
|
procedure EmptyTable; |
140 |
< |
procedure GetDetailLinkFields(MasterFields, DetailFields: TList); override; |
140 |
> |
procedure GetDetailLinkFields(MasterFields, DetailFields: TList); virtual; |
141 |
|
procedure GetIndexNames(List: TStrings); |
142 |
|
procedure GotoCurrent(Table: TIBTable); |
143 |
|
property CurrentDBKey: TIBDBKey read GetCurrentDBKey; |
150 |
|
property Active; |
151 |
|
property BufferChunks; |
152 |
|
property CachedUpdates; |
153 |
< |
property Constraints stored ConstraintsStored; |
153 |
> |
// property Constraints stored ConstraintsStored; |
154 |
|
property DefaultIndex: Boolean read FDefaultIndex write FDefaultIndex default True; |
155 |
|
property FieldDefs stored FieldDefsStored; |
156 |
|
property Filter; |
285 |
|
QRefresh.SQL.Assign(WherePrimaryRefreshSQL) |
286 |
|
else |
287 |
|
QRefresh.SQL.Assign(WhereAllRefreshSQL); |
288 |
< |
inherited; |
288 |
> |
inherited InternalRefreshRow; |
289 |
|
end; |
290 |
|
|
291 |
|
procedure TIBTable.DefChanged(Sender: TObject); |
316 |
|
'from RDB$RELATION_FIELDS R, RDB$FIELDS F ' + {do not localize} |
317 |
|
'where R.RDB$RELATION_NAME = ' + {do not localize} |
318 |
|
'''' + |
319 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + |
319 |
> |
FormatIdentifierValue(Database.SQLDialect, |
320 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + |
321 |
|
''' ' + |
322 |
|
'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize} |
323 |
|
'order by R.RDB$FIELD_POSITION'; {do not localize} |
330 |
|
begin |
331 |
|
with FieldDefs.AddFieldDef do |
332 |
|
begin |
333 |
< |
FieldNo := Query.Current.ByName('RDB$FIELD_POSITION').AsInteger; {do not localize} |
333 |
> |
(* FieldNo := Query.Current.ByName('RDB$FIELD_POSITION').AsInteger; {do not localize}*) |
334 |
|
Name := TrimRight(Query.Current.ByName('RDB$FIELD_NAME').AsString); {do not localize} |
335 |
|
case Query.Current.ByName('RDB$FIELD_TYPE').AsInteger of {do not localize} |
336 |
< |
blr_varying, blr_text: begin |
336 |
> |
blr_varying, blr_text: |
337 |
> |
begin |
338 |
|
DataType := ftString; |
339 |
|
Size := Query.Current.ByName('RDB$FIELD_LENGTH').AsInteger; {do not localize} |
340 |
|
end; |
341 |
|
blr_float, blr_double, blr_d_float: DataType := ftFloat; |
342 |
< |
blr_short: begin |
342 |
> |
blr_short: |
343 |
> |
begin |
344 |
|
sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize} |
345 |
|
if (sqlscale = 0) then |
346 |
|
DataType := ftSmallInt |
347 |
< |
else begin |
347 |
> |
else |
348 |
> |
begin |
349 |
|
DataType := ftBCD; |
350 |
|
Precision := 4; |
351 |
|
end; |
352 |
|
end; |
353 |
< |
blr_long: begin |
353 |
> |
blr_long: |
354 |
> |
begin |
355 |
|
sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize} |
356 |
|
if (sqlscale = 0) then |
357 |
|
DataType := ftInteger |
358 |
< |
else if (sqlscale >= (-4)) then begin |
358 |
> |
else if (sqlscale >= (-4)) then |
359 |
> |
begin |
360 |
|
DataType := ftBCD; |
361 |
|
Precision := 9; |
362 |
< |
end else |
362 |
> |
end |
363 |
> |
else |
364 |
|
DataType := ftFloat; |
365 |
|
end; |
366 |
< |
blr_int64: begin |
366 |
> |
blr_int64: |
367 |
> |
begin |
368 |
|
sqlscale := Query.Current.ByName('RDB$FIELD_SCALE').AsInteger; {do not localize} |
369 |
|
if (sqlscale = 0) then |
370 |
|
DataType := ftLargeInt |
371 |
< |
else if (sqlscale >= (-4)) then begin |
371 |
> |
else if (sqlscale >= (-4)) then |
372 |
> |
begin |
373 |
|
DataType := ftBCD; |
374 |
|
Precision := 18; |
375 |
< |
end else |
375 |
> |
end |
376 |
> |
else |
377 |
|
DataType := ftFloat; |
378 |
|
end; |
379 |
|
blr_timestamp: DataType := ftDateTime; |
384 |
|
DataType := ftMemo |
385 |
|
else |
386 |
|
DataType := ftBlob; |
387 |
< |
blr_quad: begin |
387 |
> |
blr_quad: |
388 |
> |
begin |
389 |
|
DataType := ftUnknown; |
390 |
|
Size := sizeof (TISC_QUAD); |
391 |
|
end; |
401 |
|
InternalCalcField := False; |
402 |
|
if ((not InternalCalcField) and |
403 |
|
Query.Current.ByName('RDB$DEFAULT_VALUE').IsNull and {do not localize} |
404 |
< |
(Query.Current.ByName('RDB$NULL_FLAG').AsInteger = 1) )then begin {do not localize} |
404 |
> |
(Query.Current.ByName('RDB$NULL_FLAG').AsInteger = 1) )then {do not localize} |
405 |
> |
begin |
406 |
|
Attributes := [faRequired]; |
407 |
|
Required := True; |
408 |
|
end; |
437 |
|
if (ixPrimary in Options) then |
438 |
|
begin |
439 |
|
Query.SQL.Text := 'Alter Table ' + {do not localize} |
440 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
440 |
> |
QuoteIdentifier(Database.SQLDialect, FTableName) + |
441 |
|
' Add CONSTRAINT ' + {do not localize} |
442 |
< |
FormatIdentifier(Database.SQLDialect, Name) |
442 |
> |
QuoteIdentifier(Database.SQLDialect, Name) |
443 |
|
+ ' Primary Key (' + {do not localize} |
444 |
|
FormatFieldsList(Fields) + |
445 |
|
')'; |
446 |
|
end |
447 |
|
else if ([ixUnique, ixDescending] * Options = [ixUnique, ixDescending]) then |
448 |
|
Query.SQL.Text := 'Create unique Descending Index ' + {do not localize} |
449 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
449 |
> |
QuoteIdentifier(Database.SQLDialect, Name) + |
450 |
|
' on ' + {do not localize} |
451 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
451 |
> |
QuoteIdentifier(Database.SQLDialect, FTableName) + |
452 |
|
' (' + FieldList + ')' |
453 |
|
else if (ixUnique in Options) then |
454 |
|
Query.SQL.Text := 'Create unique Index ' + {do not localize} |
455 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
455 |
> |
QuoteIdentifier(Database.SQLDialect, Name) + |
456 |
|
' on ' + {do not localize} |
457 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
457 |
> |
QuoteIdentifier(Database.SQLDialect, FTableName) + |
458 |
|
' (' + FieldList + ')' |
459 |
|
else if (ixDescending in Options) then |
460 |
|
Query.SQL.Text := 'Create Descending Index ' + {do not localize} |
461 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
461 |
> |
QuoteIdentifier(Database.SQLDialect, Name) + |
462 |
|
' on ' + {do not localize} |
463 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
463 |
> |
QuoteIdentifier(Database.SQLDialect, FTableName) + |
464 |
|
' (' + FieldList + ')' |
465 |
|
else |
466 |
|
Query.SQL.Text := 'Create Index ' + {do not localize} |
467 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
467 |
> |
QuoteIdentifier(Database.SQLDialect, Name) + |
468 |
|
' on ' + {do not localize} |
469 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
469 |
> |
QuoteIdentifier(Database.SQLDialect, FTableName) + |
470 |
|
' (' + FieldList + ')'; |
471 |
|
Query.Prepare; |
472 |
|
Query.ExecQuery; |
487 |
|
Query.Database := DataBase; |
488 |
|
Query.Transaction := Transaction; |
489 |
|
Query.SQL.Text := 'Drop index ' + {do not localize} |
490 |
< |
FormatIdentifier(Database.SQLDialect, Name); |
490 |
> |
QuoteIdentifier(Database.SQLDialect, Name); |
491 |
|
Query.Prepare; |
492 |
|
Query.ExecQuery; |
493 |
|
IndexDefs.Updated := False; |
506 |
|
Query.SQL.Text := 'Select ''foo'' from RDB$RELATION_CONSTRAINTS ' + |
507 |
|
'where RDB$RELATION_NAME = ' + |
508 |
|
'''' + |
509 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + |
509 |
> |
FormatIdentifierValue(Database.SQLDialect, |
510 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + |
511 |
|
''' ' + |
512 |
|
' AND RDB$CONSTRAINT_NAME = ' + |
513 |
|
'''' + |
514 |
< |
FormatIdentifierValue(Database.SQLDialect, Name) + |
514 |
> |
FormatIdentifierValue(Database.SQLDialect, |
515 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name)) + |
516 |
|
''' ' + |
517 |
|
'AND RDB$CONSTRAINT_TYPE = ''PRIMARY KEY'''; |
518 |
|
Query.Prepare; |
521 |
|
begin |
522 |
|
Query.Close; |
523 |
|
Query.SQL.Text := 'Alter Table ' + {do not localize} |
524 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
524 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
525 |
|
' Drop Constraint ' + |
526 |
< |
FormatIdentifier(Database.SQLDialect, Name); |
526 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name); |
527 |
|
Query.Prepare; |
528 |
|
Query.ExecQuery; |
529 |
|
IndexDefs.Updated := False; |
543 |
|
Query.SQL.Text := 'Select RDB$CONSTRAINT_NAME from RDB$RELATION_CONSTRAINTS ' + |
544 |
|
'where RDB$RELATION_NAME = ' + |
545 |
|
'''' + |
546 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + |
546 |
> |
FormatIdentifierValue(Database.SQLDialect, |
547 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + |
548 |
|
''' ' + |
549 |
|
'AND RDB$INDEX_NAME = ' + |
550 |
|
'''' + |
551 |
< |
FormatIdentifierValue(Database.SQLDialect, Name) + |
551 |
> |
FormatIdentifierValue(Database.SQLDialect, |
552 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name)) + |
553 |
|
''' ' + |
554 |
|
'AND RDB$CONSTRAINT_TYPE = ''PRIMARY KEY'''; |
555 |
|
Query.Prepare; |
558 |
|
begin |
559 |
|
Query.Close; |
560 |
|
Query.SQL.Text := 'Alter Table ' + {do not localize} |
561 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
561 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
562 |
|
' Drop Constraint ' + |
563 |
< |
FormatIdentifier(Database.SQLDialect, Query.Current.ByName('RDB$CONSTRAINT_NAME').AsString); |
563 |
> |
QuoteIdentifier(DataBase.SQLDialect, Query.Current.ByName('RDB$CONSTRAINT_NAME').AsString); |
564 |
|
Query.Prepare; |
565 |
|
Query.ExecQuery; |
566 |
|
IndexDefs.Updated := False; |
662 |
|
'I.RDB$SEGMENT_COUNT, S.RDB$FIELD_NAME from RDB$INDICES I, ' + {do not localize} |
663 |
|
'RDB$INDEX_SEGMENTS S where I.RDB$INDEX_NAME = S.RDB$INDEX_NAME '+ {do not localize} |
664 |
|
'and I.RDB$RELATION_NAME = ' + '''' + {do not localize} |
665 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + ''''; |
665 |
> |
FormatIdentifierValue(Database.SQLDialect, |
666 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + ''''; |
667 |
|
Query.Prepare; |
668 |
|
Query.ExecQuery; |
669 |
|
while (not Query.EOF) and (Query.Next <> nil) do |
687 |
|
SubQuery.SQL.Text := |
688 |
|
'Select RDB$FIELD_NAME from RDB$INDEX_SEGMENTS where RDB$INDEX_NAME = ' + {do not localize} |
689 |
|
'''' + |
690 |
< |
FormatIdentifierValue(Database.SQLDialect, Name) + |
690 |
> |
FormatIdentifierValue(Database.SQLDialect, |
691 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name)) + |
692 |
|
'''' + 'ORDER BY RDB$FIELD_POSITION'; {do not localize} |
693 |
|
SubQuery.Prepare; |
694 |
|
SubQuery.ExecQuery; |
734 |
|
Query.SQL.Text := |
735 |
|
'Select USER from RDB$RELATIONS where RDB$RELATION_NAME = ' + {do not localize} |
736 |
|
'''' + |
737 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + ''''; |
737 |
> |
FormatIdentifierValue(Database.SQLDialect, |
738 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + ''''; |
739 |
|
Query.Prepare; |
740 |
|
Query.ExecQuery; |
741 |
|
Result := not Query.EOF; |
777 |
|
case DataType of |
778 |
|
ftString: |
779 |
|
FieldList := FieldList + |
780 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
780 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
781 |
|
' VARCHAR(' + IntToStr(Size) + ')'; {do not localize} |
782 |
|
ftFixedChar: |
783 |
|
FieldList := FieldList + |
784 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
784 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
785 |
|
' CHAR(' + IntToStr(Size) + ')'; {do not localize} |
786 |
|
ftBoolean, ftSmallint, ftWord: |
787 |
|
FieldList := FieldList + |
788 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
788 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
789 |
|
' SMALLINT'; {do not localize} |
790 |
|
ftInteger: |
791 |
|
FieldList := FieldList + |
792 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
792 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
793 |
|
' INTEGER'; {do not localize} |
794 |
|
ftFloat, ftCurrency: |
795 |
|
FieldList := FieldList + |
796 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
796 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
797 |
|
' DOUBLE PRECISION'; {do not localize} |
798 |
|
ftBCD: begin |
799 |
|
if (Database.SQLDialect = 1) then begin |
804 |
|
end; |
805 |
|
if (Precision <= 4 ) then |
806 |
|
FieldList := FieldList + |
807 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
807 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
808 |
|
' Numeric(18, 4)' {do not localize} |
809 |
|
else |
810 |
|
FieldList := FieldList + |
811 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
811 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
812 |
|
' Numeric(' + IntToStr(Precision) + ', 4)'; {do not localize} |
813 |
|
end; |
814 |
|
ftDate: |
815 |
|
FieldList := FieldList + |
816 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
816 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
817 |
|
' DATE'; {do not localize} |
818 |
|
ftTime: |
819 |
|
FieldList := FieldList + |
820 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
820 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
821 |
|
' TIME'; {do not localize} |
822 |
|
ftDateTime: |
823 |
|
if (Database.SQLDialect = 1) then |
824 |
|
FieldList := FieldList + |
825 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
825 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
826 |
|
' DATE' {do not localize} |
827 |
|
else |
828 |
|
FieldList := FieldList + |
829 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
829 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
830 |
|
' TIMESTAMP'; {do not localize} |
831 |
|
ftLargeInt: |
832 |
|
if (Database.SQLDialect = 1) then |
833 |
|
IBError(ibxeFieldUnsupportedType,[nil]) |
834 |
|
else |
835 |
|
FieldList := FieldList + |
836 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
836 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
837 |
|
' Numeric(18, 0)'; {do not localize} |
838 |
|
ftBlob, ftMemo: |
839 |
|
FieldList := FieldList + |
840 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
840 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
841 |
|
' BLOB SUB_TYPE 1'; {do not localize} |
842 |
|
ftBytes, ftVarBytes, ftGraphic..ftTypedBinary: |
843 |
|
FieldList := FieldList + |
844 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
844 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
845 |
|
' BLOB SUB_TYPE 0'; {do not localize} |
846 |
|
ftUnknown, ftADT, ftArray, ftReference, ftDataSet, |
847 |
|
ftCursor, ftWideString, ftAutoInc: |
867 |
|
Query.Database := Database; |
868 |
|
Query.transaction := Transaction; |
869 |
|
Query.SQL.Text := 'Create Table ' + |
870 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
870 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
871 |
|
' (' + FieldList; {do not localize} |
872 |
|
for I := 0 to IndexDefs.Count - 1 do |
873 |
|
with IndexDefs[I] do |
874 |
|
if ixPrimary in Options then |
875 |
|
begin |
876 |
|
Query.SQL.Text := Query.SQL.Text + ', CONSTRAINT ' + |
877 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
877 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
878 |
|
' Primary Key (' + |
879 |
|
FormatFieldsList(Fields) + |
880 |
|
')'; |
914 |
|
Query.Database := DataBase; |
915 |
|
Query.Transaction := Transaction; |
916 |
|
Query.SQL.Text := 'drop table ' + {do not localize} |
917 |
< |
FormatIdentifier(Database.SQLDialect, FTableName); |
917 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName); |
918 |
|
Query.Prepare; |
919 |
|
Query.ExecQuery; |
920 |
|
finally |
933 |
|
Query.Database := DataBase; |
934 |
|
Query.Transaction := Transaction; |
935 |
|
Query.SQL.Text := 'delete from ' + {do not localize} |
936 |
< |
FormatIdentifier(Database.SQLDialect, FTableName); |
936 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName); |
937 |
|
Query.Prepare; |
938 |
|
Query.ExecQuery; |
939 |
|
if Active then |
946 |
|
end; |
947 |
|
end; |
948 |
|
|
949 |
< |
procedure TIBTable.DataEvent(Event: TDataEvent; Info: Longint); |
949 |
> |
procedure TIBTable.DataEvent(Event: TDataEvent; Info: Ptrint); |
950 |
|
begin |
951 |
|
if Event = dePropertyChange then begin |
952 |
|
IndexDefs.Updated := False; |
977 |
|
Query.SQL.Text := 'Select RDB$SYSTEM_FLAG, RDB$DBKEY_LENGTH ' + {do not localize} |
978 |
|
'from RDB$RELATIONS where RDB$RELATION_NAME = ' + {do not localize} |
979 |
|
'''' + |
980 |
< |
FormatIdentifierValue(Database.SQLDialect, FTableName) + ''''; |
980 |
> |
FormatIdentifierValue(Database.SQLDialect, |
981 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName)) + ''''; |
982 |
|
Query.Prepare; |
983 |
|
Query.ExecQuery; |
984 |
|
if (Query.Current[0].AsInteger <> 0) or |
1068 |
|
i: Integer; |
1069 |
|
begin |
1070 |
|
if Database.SQLDialect = 1 then begin |
1071 |
< |
Value := FormatIdentifier(Database.SQLDialect, Value); |
1071 |
> |
Value := QuoteIdentifier(Database.SQLDialect, Value); |
1072 |
|
Result := StringReplace (Value, ';', ', ', [rfReplaceAll]); |
1073 |
|
end |
1074 |
|
else begin |
1078 |
|
begin |
1079 |
|
FieldName := ExtractFieldName(Value, i); |
1080 |
|
if Result = '' then |
1081 |
< |
Result := FormatIdentifier(Database.SQLDialect, FieldName) |
1081 |
> |
Result := QuoteIdentifier(Database.SQLDialect, FieldName) |
1082 |
|
else |
1083 |
< |
Result := Result + ', ' + FormatIdentifier(Database.SQLDialect, FieldName); |
1083 |
> |
Result := Result + ', ' + QuoteIdentifier(Database.SQLDialect, FieldName); |
1084 |
|
end; |
1085 |
|
end; |
1086 |
|
end; |
1313 |
|
OrderByStr := FormatFieldsList(FPrimaryIndexFields); |
1314 |
|
SQL := TStringList.Create; |
1315 |
|
SQL.Text := 'select ' + {do not localize} |
1316 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + '.*, ' |
1316 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize} |
1317 |
|
+ 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize} |
1318 |
< |
+ FormatIdentifier(Database.SQLDialect, FTableName); |
1318 |
> |
+ QuoteIdentifier(DataBase.SQLDialect, FTableName); |
1319 |
|
if Filtered and (Filter <> '') then |
1320 |
|
begin |
1321 |
|
SQL.Text := SQL.Text + ' where ' + Filter; {do not localize} |
1335 |
|
if i > 0 then |
1336 |
|
SQL.Text := SQL.Text + 'AND '; |
1337 |
|
SQL.Text := SQL.Text + |
1338 |
< |
FormatIdentifier(Database.SQLDialect, FDetailFieldsList.Strings[i]) + |
1338 |
> |
QuoteIdentifier(DataBase.SQLDialect, FDetailFieldsList.Strings[i]) + |
1339 |
|
' = :' + |
1340 |
< |
FormatIdentifier(Database.SQLDialect, FMasterFieldsList.Strings[i]); |
1340 |
> |
QuoteIdentifier(DataBase.SQLDialect, FMasterFieldsList.Strings[i]); |
1341 |
|
end; |
1342 |
|
end; |
1343 |
|
if OrderByStr <> '' then |
1344 |
|
SQL.Text := SQL.Text + ' order by ' + OrderByStr; {do not localize} |
1345 |
|
SelectSQL.Assign(SQL); |
1346 |
|
RefreshSQL.Text := 'select ' + {do not localize} |
1347 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + '.*, ' |
1347 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize} |
1348 |
|
+ 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize} |
1349 |
< |
+ FormatIdentifier(Database.SQLDialect, FTableName) + |
1349 |
> |
+ QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1350 |
|
' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY'; {do not localize} |
1351 |
|
WhereDBKeyRefreshSQL.Assign(RefreshSQL); |
1352 |
|
InternalPrepare; |
1375 |
|
WhereAllFieldList := WhereAllFieldList + ' AND '; |
1376 |
|
end; |
1377 |
|
InsertFieldList := InsertFieldList + |
1378 |
< |
FormatIdentifier(Database.SQLDialect, Name); |
1378 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name); |
1379 |
|
InsertParamList := InsertParamList + ':' + |
1380 |
< |
FormatIdentifier(Database.SQLDialect, Name); |
1380 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name); |
1381 |
|
UpdateFieldList := UpdateFieldList + |
1382 |
< |
FormatIdentifier(Database.SQLDialect, Name) + |
1382 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + |
1383 |
|
' = :' + |
1384 |
< |
FormatIdentifier(Database.SQLDialect, Name); |
1384 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name); |
1385 |
|
if (DataType <> ftBlob) and (DataType <>ftMemo) then |
1386 |
|
WhereAllFieldList := WhereAllFieldList + |
1387 |
< |
FormatIdentifier(Database.SQLDialect, Name) + ' = :' + |
1388 |
< |
FormatIdentifier(Database.SQLDialect, Name);{do not localize} |
1387 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name) + ' = :' + |
1388 |
> |
QuoteIdentifier(DataBase.SQLDialect, Name);{do not localize} |
1389 |
|
end; |
1390 |
|
end; |
1391 |
|
end; |
1401 |
|
begin |
1402 |
|
tmp := ExtractFieldName(FPrimaryIndexFields, i); |
1403 |
|
tmp := |
1404 |
< |
FormatIdentifier(Database.SQLDialect, tmp) + ' = :' + |
1405 |
< |
FormatIdentifier(Database.SQLDialect, tmp);{do not localize} |
1404 |
> |
QuoteIdentifier(DataBase.SQLDialect, tmp) + ' = :' + |
1405 |
> |
QuoteIdentifier(DataBase.SQLDialect, tmp);{do not localize} |
1406 |
|
if WherePrimaryFieldList <> '' then |
1407 |
|
WherePrimaryFieldList := |
1408 |
|
WherePrimaryFieldList + ' AND ' + tmp |
1417 |
|
else |
1418 |
|
begin |
1419 |
|
DeleteSQL.Text := 'delete from ' + {do not localize} |
1420 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
1420 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1421 |
|
' where RDB$DB_KEY = ' + ':IBX_INTERNAL_DBKEY'; {do not localize} |
1422 |
|
GenerateFieldLists; |
1423 |
|
InsertSQL.Text := 'insert into ' + {do not localize} |
1424 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
1424 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1425 |
|
' (' + InsertFieldList + {do not localize} |
1426 |
|
') values (' + InsertParamList + ')'; {do not localize} |
1427 |
|
ModifySQL.Text := 'update ' + |
1428 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + |
1428 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1429 |
|
' set ' + UpdateFieldList + {do not localize} |
1430 |
|
' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY'; {do not localize} |
1431 |
|
WhereAllRefreshSQL.Text := 'select ' + {do not localize} |
1432 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + '.*, ' |
1432 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' |
1433 |
|
+ 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize} |
1434 |
< |
+ FormatIdentifier(Database.SQLDialect, FTableName) + |
1434 |
> |
+ QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1435 |
|
' where ' + WhereAllFieldList; {do not localize} |
1436 |
|
if FPrimaryIndexFields <> '' then |
1437 |
|
begin |
1438 |
|
GenerateWherePrimaryFieldList; |
1439 |
|
WherePrimaryRefreshSQL.Text := 'select ' + {do not localize} |
1440 |
< |
FormatIdentifier(Database.SQLDialect, FTableName) + '.*, ' {do not localize} |
1440 |
> |
QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' {do not localize} |
1441 |
|
+ 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize} |
1442 |
< |
+ FormatIdentifier(Database.SQLDialect, FTableName) + |
1442 |
> |
+ QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1443 |
|
' where ' + WherePrimaryFieldList; {do not localize} |
1444 |
|
end; |
1445 |
|
try |
1519 |
|
begin |
1520 |
|
SetState(dsInactive); |
1521 |
|
CloseCursor; |
1522 |
< |
OpenCursor; |
1522 |
> |
OpenCursor(false); |
1523 |
|
SetState(dsBrowse); |
1524 |
|
end; |
1525 |
|
finally |
1527 |
|
end; |
1528 |
|
end; |
1529 |
|
|
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 |
– |
|
1530 |
|
end. |