@@ -70,7 +70,7 @@ TAnsiSQLGenerator = class(TAbstractSQLGenerator)
70
70
function GetTempTableName : string; virtual ;
71
71
function GetPrimaryKeyDefinition (const field: TSQLCreateField): string; virtual ;
72
72
function GetSplitStatementSymbol : string; virtual ;
73
- procedure ParseFullTablename (const fullTableName: string;
73
+ procedure ParseFullTableName (const fullTableName: string;
74
74
out tableName, schemaName: string); virtual ;
75
75
function GetEscapeChar : Char; override;
76
76
function GetUpdateVersionFieldQuery (const command: TUpdateCommand;
@@ -126,20 +126,20 @@ function TAnsiSQLGenerator.DoGenerateBackupTable(
126
126
begin
127
127
// select old data to temporary table
128
128
SetLength(Result, 2 );
129
- Result[0 ] := Format(' SELECT * INTO %0:S FROM %1:S ' ,
129
+ Result[0 ] := Format(' SELECT * INTO %0:s FROM %1:s ' ,
130
130
[GetTempTableName, tableName]);
131
131
// drop table
132
- Result[1 ] := Format(' DROP TABLE %0:S ' , [tableName]);
132
+ Result[1 ] := Format(' DROP TABLE %0:s ' , [tableName]);
133
133
end ;
134
134
135
135
function TAnsiSQLGenerator.DoGenerateBackupTableUsingCreate (
136
136
const tableName: string): TArray<string>;
137
137
begin
138
138
SetLength(Result, 2 );
139
- Result[0 ] := Format(' CREATE TABLE %0:S AS SELECT * FROM %1:S ' ,
139
+ Result[0 ] := Format(' CREATE TABLE %0:s AS SELECT * FROM %1:s ' ,
140
140
[GetTempTableName, tableName]);
141
141
// drop table
142
- Result[1 ] := Format(' DROP TABLE %0:S ' , [tableName]);
142
+ Result[1 ] := Format(' DROP TABLE %0:s ' , [tableName]);
143
143
end ;
144
144
145
145
function TAnsiSQLGenerator.DoGenerateCreateTable (const tableName: string;
@@ -151,7 +151,7 @@ function TAnsiSQLGenerator.DoGenerateCreateTable(const tableName: string;
151
151
begin
152
152
sqlBuilder := TStringBuilder.Create;
153
153
try
154
- sqlBuilder.AppendFormat(' CREATE TABLE %0:S ' , [tableName])
154
+ sqlBuilder.AppendFormat(' CREATE TABLE %0:s ' , [tableName])
155
155
.Append(' (' )
156
156
.AppendLine;
157
157
for i := 0 to columns.Count - 1 do
@@ -161,7 +161,7 @@ function TAnsiSQLGenerator.DoGenerateCreateTable(const tableName: string;
161
161
sqlBuilder.Append(' , ' ).AppendLine;
162
162
163
163
// 0 - Column name, 1 - Column data type name, 2 - NOT NULL condition
164
- sqlBuilder.AppendFormat(' %0:S %1:S %2:S %3:S ' , [
164
+ sqlBuilder.AppendFormat(' %0:s %1:s %2:s %3:s ' , [
165
165
GetEscapedFieldName(field),
166
166
GetSQLDataTypeName(field),
167
167
IfThen(cpNotNull in field.Properties, ' NOT NULL' , ' NULL' ),
@@ -182,12 +182,12 @@ function TAnsiSQLGenerator.DoGenerateRestoreTable(const tableName: string;
182
182
begin
183
183
SetLength(Result, 2 );
184
184
185
- Result[0 ] := Format(' INSERT INTO %0:S (%2:S ) SELECT %3:S FROM %1:S ' + sLineBreak,
185
+ Result[0 ] := Format(' INSERT INTO %0:s (%2:s ) SELECT %3:s FROM %1:s ' + sLineBreak,
186
186
[tableName, GetTempTableName, GetCreateFieldsAsString(createColumns),
187
187
GetCopyFieldsAsString(createColumns, dbColumns)]);
188
188
189
189
// drop temporary table
190
- Result[1 ] := Format(' DROP TABLE %0:S ' , [GetTempTableName]);
190
+ Result[1 ] := Format(' DROP TABLE %0:s ' , [GetTempTableName]);
191
191
end ;
192
192
193
193
function TAnsiSQLGenerator.GenerateCreateForeignKey (
@@ -202,13 +202,13 @@ function TAnsiSQLGenerator.GenerateCreateForeignKey(
202
202
for field in command.ForeignKeys do
203
203
begin
204
204
sqlBuilder.Clear;
205
- sqlBuilder.AppendFormat(' ALTER TABLE %0:S ' , [command.Table.Name ])
205
+ sqlBuilder.AppendFormat(' ALTER TABLE %0:s ' , [command.Table.Name ])
206
206
.AppendLine
207
- .AppendFormat(' ADD CONSTRAINT %0:S ' , [field.ForeignKeyName])
207
+ .AppendFormat(' ADD CONSTRAINT %0:s ' , [field.ForeignKeyName])
208
208
.AppendLine
209
- .AppendFormat(' FOREIGN KEY(%0:S )' , [GetEscapedFieldName(field)])
209
+ .AppendFormat(' FOREIGN KEY(%0:s )' , [GetEscapedFieldName(field)])
210
210
.AppendLine
211
- .AppendFormat(' REFERENCES %0:S (%1:S )' , [field.ReferencedTableName,
211
+ .AppendFormat(' REFERENCES %0:s (%1:s )' , [field.ReferencedTableName,
212
212
AnsiQuotedStr(field.ReferencedColumnName, GetEscapeChar)])
213
213
.AppendLine
214
214
.Append(field.ConstraintsAsString);
@@ -252,7 +252,7 @@ function TAnsiSQLGenerator.GenerateDelete(const command: TDeleteCommand): string
252
252
253
253
sqlBuilder := TStringBuilder.Create;
254
254
try
255
- sqlBuilder.AppendFormat(' DELETE FROM %0:S ' , [command.Table.Name ]);
255
+ sqlBuilder.AppendFormat(' DELETE FROM %0:s ' , [command.Table.Name ]);
256
256
257
257
for i := 0 to command.WhereFields.Count - 1 do
258
258
begin
@@ -264,7 +264,7 @@ function TAnsiSQLGenerator.GenerateDelete(const command: TDeleteCommand): string
264
264
265
265
{ TODO -oLinas -cGeneral : implement where operators}
266
266
267
- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
267
+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
268
268
[GetEscapedFieldName(field), field.ParamName]);
269
269
end ;
270
270
@@ -349,9 +349,9 @@ function TAnsiSQLGenerator.GeneratePagedQuery(const sql: string;
349
349
begin
350
350
sqlStatement := sql;
351
351
if EndsStr(' ;' , sqlStatement) then
352
- SetLength(sqlStatement, Length(sqlStatement)- 1 );
352
+ SetLength(sqlStatement, Length(sqlStatement) - 1 );
353
353
354
- Result := sqlStatement + Format(' LIMIT %1:D ,%0:D %2:S ' ,
354
+ Result := sqlStatement + Format(' LIMIT %1:d ,%0:d %2:s ' ,
355
355
[limit, offset, GetSplitStatementSymbol]);
356
356
end ;
357
357
@@ -403,7 +403,7 @@ function TAnsiSQLGenerator.GenerateUpdate(const command: TUpdateCommand): string
403
403
if i > 0 then
404
404
sqlBuilder.Append(' , ' );
405
405
406
- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
406
+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
407
407
[GetEscapedFieldName(updateField), updateField.ParamName]);
408
408
end ;
409
409
@@ -415,7 +415,7 @@ function TAnsiSQLGenerator.GenerateUpdate(const command: TUpdateCommand): string
415
415
else
416
416
sqlBuilder.Append(' AND ' );
417
417
418
- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
418
+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
419
419
[GetEscapedFieldName(whereField), whereField.ParamName]);
420
420
end ;
421
421
@@ -617,17 +617,21 @@ function TAnsiSQLGenerator.GetQueryLanguage: TQueryLanguage;
617
617
Result := qlAnsiSQL;
618
618
end ;
619
619
620
- procedure TAnsiSQLGenerator.ParseFullTablename (const fullTableName: string; out tableName, schemaName: string);
620
+ procedure TAnsiSQLGenerator.ParseFullTableName (const fullTableName: string;
621
+ out tableName, schemaName: string);
621
622
var
622
623
i: Integer;
623
624
begin
624
625
i := Pos(' .' , fullTableName);
625
- tableName := fullTableName;
626
- schemaName := ' ' ;
627
626
if i > 1 then
628
627
begin
629
628
schemaName := Copy(fullTableName, 1 , i - 1 );
630
- tableName := Copy(fullTableName, i + 1 , Length(fullTableName) - 1 );
629
+ tableName := Copy(fullTableName, i + 1 );
630
+ end
631
+ else
632
+ begin
633
+ tableName := fullTableName;
634
+ schemaName := ' ' ;
631
635
end ;
632
636
end ;
633
637
@@ -666,7 +670,7 @@ function TAnsiSQLGenerator.GetSQLDataTypeName(const field: TSQLCreateField): str
666
670
tkUnknown: ;
667
671
tkInteger, tkInt64, tkEnumeration, tkSet:
668
672
if field.Precision > 0 then
669
- Result := Format(' NUMERIC(%0:D , %1:D )' , [field.Precision, field.Scale])
673
+ Result := Format(' NUMERIC(%0:d , %1:d )' , [field.Precision, field.Scale])
670
674
else
671
675
if typeInfo = System.TypeInfo(Boolean) then
672
676
Result := ' BIT'
@@ -682,7 +686,7 @@ function TAnsiSQLGenerator.GetSQLDataTypeName(const field: TSQLCreateField): str
682
686
Result := ' TIME'
683
687
else
684
688
if field.Precision > 0 then
685
- Result := Format(' NUMERIC(%0:D , %1:D )' , [field.Precision, field.Scale])
689
+ Result := Format(' NUMERIC(%0:d , %1:d )' , [field.Precision, field.Scale])
686
690
else
687
691
Result := ' FLOAT' ;
688
692
tkString, tkLString: Result := Format(' VARCHAR(%D)' , [field.Length]);
@@ -715,7 +719,7 @@ function TAnsiSQLGenerator.GetSQLSequenceCount(const sequenceName: string): stri
715
719
716
720
function TAnsiSQLGenerator.GetSQLTableCount (const tableName: string): string;
717
721
begin
718
- Result := Format(' SELECT COUNT(*) FROM %0:S %1:S ' , [tableName, GetSplitStatementSymbol]);
722
+ Result := Format(' SELECT COUNT(*) FROM %0:s %1:s ' , [tableName, GetSplitStatementSymbol]);
719
723
end ;
720
724
721
725
function TAnsiSQLGenerator.GetSQLTableExists (const tableName: string): string;
@@ -725,7 +729,7 @@ function TAnsiSQLGenerator.GetSQLTableExists(const tableName: string): string;
725
729
726
730
function TAnsiSQLGenerator.GetTableColumns (const tableName: string): string;
727
731
begin
728
- Result := Format(' SELECT * FROM %0:S WHERE 1<>2 %1:S ' , [tableName, GetSplitStatementSymbol]);
732
+ Result := Format(' SELECT * FROM %0:s WHERE 1<>2 %1:s ' , [tableName, GetSplitStatementSymbol]);
729
733
end ;
730
734
731
735
function TAnsiSQLGenerator.GetTableNameWithAlias (const table: TSQLTable): string;
@@ -742,7 +746,7 @@ function TAnsiSQLGenerator.GetUpdateVersionFieldQuery(
742
746
const command: TUpdateCommand; const versionColumn: VersionAttribute;
743
747
const version, primaryKey: Variant): Variant;
744
748
begin
745
- Result := Format(' UPDATE %0:S SET %1:S = coalesce(%1:S ,0) + 1 WHERE (%2:S = %3:S ) AND (coalesce(%1:S ,0) = %4:S )' ,
749
+ Result := Format(' UPDATE %0:s SET %1:s = coalesce(%1:s ,0) + 1 WHERE (%2:s = %3:s ) AND (coalesce(%1:s ,0) = %4:s )' ,
746
750
[command.Table.Name , versionColumn.ColumnName,
747
751
command.PrimaryKeyColumn.ColumnName, VarToStr(primaryKey), VarToStr(version)]);
748
752
end ;
0 commit comments