@@ -70,7 +70,7 @@ TAnsiSQLGenerator = class(TAbstractSQLGenerator)
7070 function GetTempTableName : string; virtual ;
7171 function GetPrimaryKeyDefinition (const field: TSQLCreateField): string; virtual ;
7272 function GetSplitStatementSymbol : string; virtual ;
73- procedure ParseFullTablename (const fullTableName: string;
73+ procedure ParseFullTableName (const fullTableName: string;
7474 out tableName, schemaName: string); virtual ;
7575 function GetEscapeChar : Char; override;
7676 function GetUpdateVersionFieldQuery (const command: TUpdateCommand;
@@ -126,20 +126,20 @@ function TAnsiSQLGenerator.DoGenerateBackupTable(
126126begin
127127 // select old data to temporary table
128128 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 ' ,
130130 [GetTempTableName, tableName]);
131131 // drop table
132- Result[1 ] := Format(' DROP TABLE %0:S ' , [tableName]);
132+ Result[1 ] := Format(' DROP TABLE %0:s ' , [tableName]);
133133end ;
134134
135135function TAnsiSQLGenerator.DoGenerateBackupTableUsingCreate (
136136 const tableName: string): TArray<string>;
137137begin
138138 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 ' ,
140140 [GetTempTableName, tableName]);
141141 // drop table
142- Result[1 ] := Format(' DROP TABLE %0:S ' , [tableName]);
142+ Result[1 ] := Format(' DROP TABLE %0:s ' , [tableName]);
143143end ;
144144
145145function TAnsiSQLGenerator.DoGenerateCreateTable (const tableName: string;
@@ -151,7 +151,7 @@ function TAnsiSQLGenerator.DoGenerateCreateTable(const tableName: string;
151151begin
152152 sqlBuilder := TStringBuilder.Create;
153153 try
154- sqlBuilder.AppendFormat(' CREATE TABLE %0:S ' , [tableName])
154+ sqlBuilder.AppendFormat(' CREATE TABLE %0:s ' , [tableName])
155155 .Append(' (' )
156156 .AppendLine;
157157 for i := 0 to columns.Count - 1 do
@@ -161,7 +161,7 @@ function TAnsiSQLGenerator.DoGenerateCreateTable(const tableName: string;
161161 sqlBuilder.Append(' , ' ).AppendLine;
162162
163163 // 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 ' , [
165165 GetEscapedFieldName(field),
166166 GetSQLDataTypeName(field),
167167 IfThen(cpNotNull in field.Properties, ' NOT NULL' , ' NULL' ),
@@ -182,12 +182,12 @@ function TAnsiSQLGenerator.DoGenerateRestoreTable(const tableName: string;
182182begin
183183 SetLength(Result, 2 );
184184
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,
186186 [tableName, GetTempTableName, GetCreateFieldsAsString(createColumns),
187187 GetCopyFieldsAsString(createColumns, dbColumns)]);
188188
189189 // drop temporary table
190- Result[1 ] := Format(' DROP TABLE %0:S ' , [GetTempTableName]);
190+ Result[1 ] := Format(' DROP TABLE %0:s ' , [GetTempTableName]);
191191end ;
192192
193193function TAnsiSQLGenerator.GenerateCreateForeignKey (
@@ -202,13 +202,13 @@ function TAnsiSQLGenerator.GenerateCreateForeignKey(
202202 for field in command.ForeignKeys do
203203 begin
204204 sqlBuilder.Clear;
205- sqlBuilder.AppendFormat(' ALTER TABLE %0:S ' , [command.Table.Name ])
205+ sqlBuilder.AppendFormat(' ALTER TABLE %0:s ' , [command.Table.Name ])
206206 .AppendLine
207- .AppendFormat(' ADD CONSTRAINT %0:S ' , [field.ForeignKeyName])
207+ .AppendFormat(' ADD CONSTRAINT %0:s ' , [field.ForeignKeyName])
208208 .AppendLine
209- .AppendFormat(' FOREIGN KEY(%0:S )' , [GetEscapedFieldName(field)])
209+ .AppendFormat(' FOREIGN KEY(%0:s )' , [GetEscapedFieldName(field)])
210210 .AppendLine
211- .AppendFormat(' REFERENCES %0:S (%1:S )' , [field.ReferencedTableName,
211+ .AppendFormat(' REFERENCES %0:s (%1:s )' , [field.ReferencedTableName,
212212 AnsiQuotedStr(field.ReferencedColumnName, GetEscapeChar)])
213213 .AppendLine
214214 .Append(field.ConstraintsAsString);
@@ -252,7 +252,7 @@ function TAnsiSQLGenerator.GenerateDelete(const command: TDeleteCommand): string
252252
253253 sqlBuilder := TStringBuilder.Create;
254254 try
255- sqlBuilder.AppendFormat(' DELETE FROM %0:S ' , [command.Table.Name ]);
255+ sqlBuilder.AppendFormat(' DELETE FROM %0:s ' , [command.Table.Name ]);
256256
257257 for i := 0 to command.WhereFields.Count - 1 do
258258 begin
@@ -264,7 +264,7 @@ function TAnsiSQLGenerator.GenerateDelete(const command: TDeleteCommand): string
264264
265265 { TODO -oLinas -cGeneral : implement where operators}
266266
267- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
267+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
268268 [GetEscapedFieldName(field), field.ParamName]);
269269 end ;
270270
@@ -349,9 +349,9 @@ function TAnsiSQLGenerator.GeneratePagedQuery(const sql: string;
349349begin
350350 sqlStatement := sql;
351351 if EndsStr(' ;' , sqlStatement) then
352- SetLength(sqlStatement, Length(sqlStatement)- 1 );
352+ SetLength(sqlStatement, Length(sqlStatement) - 1 );
353353
354- Result := sqlStatement + Format(' LIMIT %1:D ,%0:D %2:S ' ,
354+ Result := sqlStatement + Format(' LIMIT %1:d ,%0:d %2:s ' ,
355355 [limit, offset, GetSplitStatementSymbol]);
356356end ;
357357
@@ -403,7 +403,7 @@ function TAnsiSQLGenerator.GenerateUpdate(const command: TUpdateCommand): string
403403 if i > 0 then
404404 sqlBuilder.Append(' , ' );
405405
406- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
406+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
407407 [GetEscapedFieldName(updateField), updateField.ParamName]);
408408 end ;
409409
@@ -415,7 +415,7 @@ function TAnsiSQLGenerator.GenerateUpdate(const command: TUpdateCommand): string
415415 else
416416 sqlBuilder.Append(' AND ' );
417417
418- sqlBuilder.AppendFormat(' %0:S = %1:S ' ,
418+ sqlBuilder.AppendFormat(' %0:s = %1:s ' ,
419419 [GetEscapedFieldName(whereField), whereField.ParamName]);
420420 end ;
421421
@@ -617,17 +617,21 @@ function TAnsiSQLGenerator.GetQueryLanguage: TQueryLanguage;
617617 Result := qlAnsiSQL;
618618end ;
619619
620- procedure TAnsiSQLGenerator.ParseFullTablename (const fullTableName: string; out tableName, schemaName: string);
620+ procedure TAnsiSQLGenerator.ParseFullTableName (const fullTableName: string;
621+ out tableName, schemaName: string);
621622var
622623 i: Integer;
623624begin
624625 i := Pos(' .' , fullTableName);
625- tableName := fullTableName;
626- schemaName := ' ' ;
627626 if i > 1 then
628627 begin
629628 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 := ' ' ;
631635 end ;
632636end ;
633637
@@ -666,7 +670,7 @@ function TAnsiSQLGenerator.GetSQLDataTypeName(const field: TSQLCreateField): str
666670 tkUnknown: ;
667671 tkInteger, tkInt64, tkEnumeration, tkSet:
668672 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])
670674 else
671675 if typeInfo = System.TypeInfo(Boolean) then
672676 Result := ' BIT'
@@ -682,7 +686,7 @@ function TAnsiSQLGenerator.GetSQLDataTypeName(const field: TSQLCreateField): str
682686 Result := ' TIME'
683687 else
684688 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])
686690 else
687691 Result := ' FLOAT' ;
688692 tkString, tkLString: Result := Format(' VARCHAR(%D)' , [field.Length]);
@@ -715,7 +719,7 @@ function TAnsiSQLGenerator.GetSQLSequenceCount(const sequenceName: string): stri
715719
716720function TAnsiSQLGenerator.GetSQLTableCount (const tableName: string): string;
717721begin
718- Result := Format(' SELECT COUNT(*) FROM %0:S %1:S ' , [tableName, GetSplitStatementSymbol]);
722+ Result := Format(' SELECT COUNT(*) FROM %0:s %1:s ' , [tableName, GetSplitStatementSymbol]);
719723end ;
720724
721725function TAnsiSQLGenerator.GetSQLTableExists (const tableName: string): string;
@@ -725,7 +729,7 @@ function TAnsiSQLGenerator.GetSQLTableExists(const tableName: string): string;
725729
726730function TAnsiSQLGenerator.GetTableColumns (const tableName: string): string;
727731begin
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]);
729733end ;
730734
731735function TAnsiSQLGenerator.GetTableNameWithAlias (const table: TSQLTable): string;
@@ -742,7 +746,7 @@ function TAnsiSQLGenerator.GetUpdateVersionFieldQuery(
742746 const command: TUpdateCommand; const versionColumn: VersionAttribute;
743747 const version, primaryKey: Variant): Variant;
744748begin
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 )' ,
746750 [command.Table.Name , versionColumn.ColumnName,
747751 command.PrimaryKeyColumn.ColumnName, VarToStr(primaryKey), VarToStr(version)]);
748752end ;
0 commit comments