159 |
|
property FieldDefs stored FieldDefsStored; |
160 |
|
property Filter; |
161 |
|
property Filtered; |
162 |
+ |
property GeneratorField; |
163 |
|
property IndexDefs: TIndexDefs read FIndexDefs write SetIndexDefs stored IndexDefsStored; |
164 |
|
property IndexFieldNames: string read GetIndexFieldNames write SetIndexFieldNames; |
165 |
|
property IndexName: string read GetIndexName write SetIndexName; |
1302 |
|
procedure TIBTable.GenerateUpdateSQL; |
1303 |
|
var |
1304 |
|
InsertFieldList, InsertParamList, UpdateFieldList: string; |
1305 |
< |
WherePrimaryFieldList, WhereAllFieldList: string; |
1305 |
> |
WherePrimaryFieldList, WhereAllFieldList, |
1306 |
> |
InsertReturningFieldList, UpdateReturningFieldList: string; |
1307 |
|
|
1308 |
|
procedure GenerateFieldLists; |
1309 |
|
var |
1310 |
|
I: Integer; |
1311 |
+ |
AllowReturningClause: boolean; |
1312 |
|
begin |
1313 |
+ |
{Is database Firebird 2.1 or later?} |
1314 |
+ |
AllowReturningClause := (DatabaseInfo.ODSMajorVersion > 11) or |
1315 |
+ |
((DatabaseInfo.ODSMajorVersion = 11) and (DatabaseInfo.ODSMinorVersion >= 1)); |
1316 |
|
for I := 0 to FieldDefs.Count - 1 do begin |
1317 |
< |
with FieldDefs[I] do begin |
1317 |
> |
with TIBFieldDef(FieldDefs[I]) do begin |
1318 |
> |
if AllowReturningClause then |
1319 |
> |
begin |
1320 |
> |
if (faReadOnly in Attributes) or IdentityColumn then |
1321 |
> |
begin |
1322 |
> |
if InsertReturningFieldList <> '' then |
1323 |
> |
InsertReturningFieldList := InsertReturningFieldList + ', ' + |
1324 |
> |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)) |
1325 |
> |
else |
1326 |
> |
InsertReturningFieldList := ' RETURNING ' + |
1327 |
> |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)) |
1328 |
> |
end; |
1329 |
> |
if (faReadOnly in Attributes) then |
1330 |
> |
begin |
1331 |
> |
if UpdateReturningFieldList <> '' then |
1332 |
> |
UpdateReturningFieldList := UpdateReturningFieldList + ', ' + |
1333 |
> |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)) |
1334 |
> |
else |
1335 |
> |
UpdateReturningFieldList := ' RETURNING ' + |
1336 |
> |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)) |
1337 |
> |
end; |
1338 |
> |
end; |
1339 |
|
if not (InternalCalcField or (faReadOnly in Attributes) or |
1340 |
< |
(DataType = ftUnknown)) then |
1340 |
> |
(DataType = ftUnknown)) then |
1341 |
|
begin |
1342 |
< |
if ( InsertFieldList <> '' ) then begin |
1343 |
< |
InsertFieldList := InsertFieldList + ', '; |
1344 |
< |
InsertParamList := InsertParamList + ', '; |
1342 |
> |
if not IdentityColumn then |
1343 |
> |
begin |
1344 |
> |
if ( InsertFieldList <> '' ) then begin |
1345 |
> |
InsertFieldList := InsertFieldList + ', '; |
1346 |
> |
InsertParamList := InsertParamList + ', '; |
1347 |
> |
end; |
1348 |
> |
InsertFieldList := InsertFieldList + |
1349 |
> |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)); |
1350 |
> |
InsertParamList := InsertParamList + ':' + Name; |
1351 |
> |
end; |
1352 |
> |
if (UpdateFieldList <> '') then begin |
1353 |
|
UpdateFieldList := UpdateFieldList + ', '; |
1354 |
|
if (DataType <> ftBlob) and (DataType <>ftMemo) then |
1355 |
|
WhereAllFieldList := WhereAllFieldList + ' AND '; |
1356 |
|
end; |
1322 |
– |
InsertFieldList := InsertFieldList + |
1323 |
– |
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)); |
1324 |
– |
InsertParamList := InsertParamList + ':' + Name; |
1357 |
|
UpdateFieldList := UpdateFieldList + |
1358 |
|
QuoteIdentifier(DataBase.SQLDialect, GetDBAliasName(FieldNo)) + |
1359 |
|
' = :' + Name; |
1403 |
|
InsertSQL.Text := 'insert into ' + {do not localize} |
1404 |
|
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1405 |
|
' (' + InsertFieldList + {do not localize} |
1406 |
< |
') values (' + InsertParamList + ')'; {do not localize} |
1406 |
> |
') values (' + InsertParamList + ')' + InsertReturningFieldList; {do not localize} |
1407 |
|
ModifySQL.Text := 'update ' + |
1408 |
|
QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1409 |
|
' set ' + UpdateFieldList + {do not localize} |
1410 |
< |
' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY'; {do not localize} |
1410 |
> |
' where RDB$DB_KEY = :IBX_INTERNAL_DBKEY' + UpdateReturningFieldList; {do not localize} |
1411 |
|
WhereAllRefreshSQL.Text := 'select ' + {do not localize} |
1412 |
|
QuoteIdentifier(DataBase.SQLDialect, FTableName) + '.*, ' |
1413 |
|
+ 'RDB$DB_KEY as IBX_INTERNAL_DBKEY from ' {do not localize} |
1414 |
|
+ QuoteIdentifier(DataBase.SQLDialect, FTableName) + |
1415 |
< |
' where ' + WhereAllFieldList; {do not localize} |
1415 |
> |
' where ' + WhereAllFieldList ; {do not localize} |
1416 |
|
if FPrimaryIndexFields <> '' then |
1417 |
|
begin |
1418 |
|
GenerateWherePrimaryFieldList; |