0

How can I rollback my SQLite database after doing a few queries on my iOS/Android device within a Delphi 10 firemonkey multi device project?

I create my database queries using TFDQuery.

Remi
  • 1,289
  • 1
  • 18
  • 52
  • Are you using transactions? – CL. Mar 16 '16 at 08:52
  • @CL. No, I am not at the moment – Remi Mar 16 '16 at 08:52
  • 1
    Well, the [do](http://www.sqlite.org/lang_transaction.html). – CL. Mar 16 '16 at 08:56
  • @CL. So start with "Begin Transaction" then do queries then rollback? And if i do want to commit then commit at the end instead of rollback? – Remi Mar 16 '16 at 11:09
  • @CL. Because when I try this I get the message cannot start a transaction within a transaction – Remi Mar 16 '16 at 11:14
  • @CL. I've tried to execute the query using DB Browser for Sqlite. I'll try to do it with code. Maybe then it will work fine. – Remi Mar 16 '16 at 11:17
  • @CL. It does work when I do it in code! It only has to be all in 1 query that I execute though. If you post your answer ill accept it! – Remi Mar 16 '16 at 11:30
  • I don't know what code you used before, and what you changed. You have to write the answer yourself. – CL. Mar 16 '16 at 11:34

1 Answers1

0
procedure TData.RollbackTest;
var
  FD: TFDQuery;
begin
  FD := TFDQuery.Create(nil);
  FD.Connection := fConnection;
  FD.SQL.Add := 'BEGIN;'
  FD.SQL.Add := 'CREATE TABLE test (id INTEGER PRIMARY KEY);'
  FD.SQL.Add := 'ROLLBACK;'
  FD.Prepare;
  FD.ExecSQL;
  FD.Free;
end;
Remi
  • 1,289
  • 1
  • 18
  • 52