#1 2014-05-08 06:32:08

DigDiver
Member
Registered: 2013-04-29
Posts: 137

TSQLRestServerDB.Backup and missing fStatementCache.Init(DB.DB);

After performing TSQLRestServerDB.Backup, the server could not execute any SQL anymore.

Error:

ESQLite3Exception ("TSQLRequest.Reset called with no previous Request") at 00328938 SynSQLite3.TSQLRequest.Reset (4127)  stack trace API 0029F900 SynCommons.SynRtlUnwind (37997) 00009790 System.@HandleOnException (18403) 

To solve this problem, we need to add fStatementCache.Init(DB.DB); after opening DB.


function TSQLRestServerDB.Backup(Dest: TStream): boolean;
{$ifdef CPU64} // currently not working on Win64 - never mind
begin
  result := false;
end;
{$else}
var Source: TFileStream;
    Closed: boolean;
    user_version: cardinal;
begin
  result := false;
  if (Self=nil) or (DB=nil) then
    exit;
  fStatementCache.ReleaseAllDBStatements;
  user_version := DB.user_version;
  DB.LockAndFlushCache;
  try
  try
    // perform a VACCUM to recreate the database content
    EngineExecute('VACUUM');
    Closed := false;
    try
      Closed := DB.DBClose=SQLITE_OK;
      // compress the database content file
      Source := TFileStream.Create(DB.FileName,fmOpenRead or fmShareDenyNone);
      try
        Dest.CopyFrom(Source,0);  // Count=0 for whole stream copy
        result := true;
      finally
        Source.Free;
      end;
    finally
      if Closed then begin
        DB.DBOpen; // reopen the database if was previously closed
        fStatementCache.Init(DB.DB);                                                 // <-- NEED TO ADD THIS
        FreeAndNil(fRegisteredVirtualTableModules); // force register modules
        InitializeEngine;                   // register functions and modules
        CreateMissingTables(user_version);  // register virtual tables
      end;
    end;
  finally
    DB.UnLock;
  end;
  except
    on E: Exception do
      result := false;
  end;
end;
{$endif}

Offline

#2 2014-05-15 06:24:39

DigDiver
Member
Registered: 2013-04-29
Posts: 137

Re: TSQLRestServerDB.Backup and missing fStatementCache.Init(DB.DB);

Should I create a ticket?

Offline

#3 2014-05-15 15:45:09

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: TSQLRestServerDB.Backup and missing fStatementCache.Init(DB.DB);

Yes, this is a known issue.

Feel free to create a ticket for this one.
lol

Offline

Board footer

Powered by FluxBB