sqlite3ds: change ApplyUpdates to raise an exception if an error occurs

git-svn-id: trunk@37079 -
This commit is contained in:
blikblum 2017-08-27 19:44:06 +00:00
parent 46de720c63
commit 9ead4329c6

View File

@ -219,7 +219,7 @@ type
procedure SetFieldData(Field: TField; Buffer: Pointer); override;
procedure SetFieldData(Field: TField; Buffer: Pointer; NativeFormat: Boolean); override;
// Additional procedures
function ApplyUpdates: Boolean;
procedure ApplyUpdates;
procedure ClearUpdates(RecordStates: TRecordStateSet = [rsAdded, rsDeleted, rsUpdated]);
function CreateTable: Boolean;
function CreateTable(const ATableName: String): Boolean;
@ -1634,28 +1634,21 @@ begin
ExecSQL(FSQL);
end;
function TCustomSqliteDataset.ApplyUpdates: Boolean;
procedure TCustomSqliteDataset.ApplyUpdates;
var
iFields, iItems, StatementsCounter: Integer;
SQLTemp, WhereKeyNameEqual, SQLLine, TemplateStr: String;
SQLTemp, WhereKeyNameEqual, SQLLine, TemplateStr, ErrorMessage: String;
TempItem: PDataRecord;
begin
Result := False;
CheckBrowseMode;
if not UpdatesPending then
begin
Result := True;
Exit;
end;
//A PrimaryKey is only necessary to update or delete records
if FPrimaryKeyNo <> -1 then
begin
WhereKeyNameEqual := ' WHERE ' + FieldDefs[FPrimaryKeyNo].Name + ' = ';
Result := True;
end else if (FUpdatedItems.Count + FDeletedItems.Count) = 0 then
Result := True;
if not Result then
Exit;
end else if (FUpdatedItems.Count + FDeletedItems.Count) > 0 then
DatabaseError('No PrimaryKey field specified', Self);
FReturnCode := SQLITE_OK;
StatementsCounter := 0;
@ -1687,8 +1680,9 @@ begin
SQLTemp := 'BEGIN;';
if FReturnCode <> SQLITE_OK then
begin
ErrorMessage := ReturnString;
SqliteExec('ROLLBACK;', nil, nil);
Break;
DatabaseError(ErrorMessage, Self);
end;
end;
end;
@ -1721,8 +1715,9 @@ begin
SQLTemp := 'BEGIN;';
if FReturnCode <> SQLITE_OK then
begin
ErrorMessage := ReturnString;
SqliteExec('ROLLBACK;', nil, nil);
Break;
DatabaseError(ErrorMessage, Self);
end;
end;
end;
@ -1753,8 +1748,9 @@ begin
SQLTemp := 'BEGIN;';
if FReturnCode <> SQLITE_OK then
begin
ErrorMessage := ReturnString;
SqliteExec('ROLLBACK;', nil, nil);
Break;
DatabaseError(ErrorMessage, Self);
end;
end;
end;
@ -1767,12 +1763,12 @@ begin
SQLTemp := SQLTemp + 'COMMIT;';
FReturnCode := SqliteExec(PAnsiChar(SQLTemp), nil, nil);
if FReturnCode <> SQLITE_OK then
begin
ErrorMessage := ReturnString;
SqliteExec('ROLLBACK;', nil, nil);
DatabaseError(ErrorMessage, Self);
end;
end;
Result := FReturnCode = SQLITE_OK;
{$ifdef DEBUG_SQLITEDS}
WriteLn(' Result: ', Result);
{$endif}
end;
procedure TCustomSqliteDataset.ClearUpdates(RecordStates: TRecordStateSet);