#1 2016-11-25 16:26:58

xalo
Member
Registered: 2016-09-22
Posts: 32

CreateAndFillPrepare doesn't work in TSQLRestServerFullMemory...

Hi,
With the following code, it doesn't work in a TSQLRestStorageInMemory REST storage, but in TSQLRestServerDB works like a charm:

 TSQLiniDB = class(TSQLRecordVirtualTableAutoID)
 private
    fSeccio : RawUTF8;
    fCamp : RawUTF8;
    fValor : RawUTF8;
 published
    property Seccio : RawUTF8 read fSeccio write fSeccio;
    property Camp : RawUTF8 read fCamp write fCamp;
    property Valor : RawUTF8 read fValor write fValor;
 end;
...
...
var
 ModelSettings : TSQLModel;
 SettingsDB : TSQLRestServer;
...
...
procedure ORMInit;
begin
  ModelSettings := TSQLModel.Create([TSQLiniDB]);
  ModelSettings.VirtualTableRegister(TSQLiniDB,TSQLVirtualTableJSON);
  SettingsDB := TSQLRestServerFullMemory.create(ModelSettings,'settings.json',false,false);
end;
...
...
var ORMiniDB : TSQLiniDB
      Seccio,Camp,Valor:string;
begin
      Seccio := 'General';
      Camp := 'Path';
      Valor := 'c:\';
      ORMiniDB := TSQLiniDB.CreateAndFillPrepare(SettingsDB,'Seccio=? AND Camp=?',[StringToutf8(Seccio),StringToUTF8(Camp)]);;
      try
          ORMiniDB.FillOne;
          ORMiniDB.Seccio := StringToUTF8(Seccio);
          ORMiniDB.Camp := StringToUTF8(Camp);
          ORMiniDB.Valor := StringToUTF8(Valor);
          SettingsDB.AddOrUpdate(ORMiniDB);
      finally
        ORMiniDB.Free
      end;
end;

Even the pair fields 'Seccio' 'Camp' exists, AddOrUpdate adds a new register instead of update. In a sqlite database storage it works well.
Is there something wrong?

Many thanks

Last edited by xalo (2016-11-25 17:38:46)

Offline

#2 2016-11-26 07:48:03

edwinsn
Member
Registered: 2010-07-02
Posts: 1,215

Re: CreateAndFillPrepare doesn't work in TSQLRestServerFullMemory...

Except from the doc:

If your purpose is not to have a full SQLite3 engine available, you may create your server from a
TSQLRestServerFullMemory class instead of TSQLRestServerDB : this will implement a fast
in-memory engine (using TSQLRestStorageInMemory instances), with basic CRUD features (for ORM),
and persistence on disk as JSON or optimized binary files - this kind of server is enough to handle
authentication, and host services in a stand-alone way.

You might instead want to use TSQLRestServerDB  with ':memory:' (without the quotes) as the filename? reference is here: https://www.sqlite.org/inmemorydb.html

Last edited by edwinsn (2016-11-26 07:48:25)


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#3 2016-11-26 15:00:30

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

Re: CreateAndFillPrepare doesn't work in TSQLRestServerFullMemory...

The AND operator is not handled by TSQLRestServerFullMemory....
Change your where clause or Switch to Sqlite3 in-memory database engine.

Offline

#4 2016-11-26 16:35:13

xalo
Member
Registered: 2016-09-22
Posts: 32

Re: CreateAndFillPrepare doesn't work in TSQLRestServerFullMemory...

ok!...but is so so so fast!!! :-(
Maybe it would be possible apply only one condition for prepare, and the second one through a fillone iterating.

Really really good framework!
Awesome!

Many thanks

Offline

#5 2016-11-26 16:52:31

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

Re: CreateAndFillPrepare doesn't work in TSQLRestServerFullMemory...

Or you could also directly access the TList containing the TSQLRecord, so you can do whatever request you expect, directly on the records.
Ensure you protect your direct use with StorageLock/StorageUnlock method calls.

Offline

Board footer

Powered by FluxBB