#1 2019-03-14 08:01:39

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

UpdateBlobFields or UpdateBlob is not recorded in TSynLog

Using latest revision, here is sample console program.

program UpdateBlobTest;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  SynCommons,
  mORMot,
  mORMotSQLite3,
  SynSQLite3Static,
  SynLog;

type
  TSQLTestRecord = class(TSQLRecord)
  private
    FName: RawUTF8;
    FBlob: TSQLRawBlob;
  published
    property Name: RawUTF8 read FName write FName stored False { AS_UNIQUE };
    property Blob: TSQLRawBlob read FBlob write FBlob;
  end;

var
  Model: TSQLModel;
  RestServer: TSQLRestServerDB;
  lSQLTestRecord: TSQLTestRecord;
  LRand: Integer;
  LID: Int64;
  LBlob: TSQLRawBlob;

begin
  try
    with TSynLog.Family do
    begin
      Level := LOG_VERBOSE;
      DestinationPath := ExeVersion.ProgramFilePath;
    end;

    Model := TSQLModel.Create([TSQLTestRecord]);

    RestServer := TSQLRestServerDB.Create(Model, ExeVersion.ProgramFilePath + 'test.db');
    try

      Model.Owner := RestServer;
      RestServer.CreateMissingTables;

      (*
        Create record
      *)
      Randomize;
      LRand := Random(MaxInt);
      lSQLTestRecord := TSQLTestRecord.Create;
      try
        lSQLTestRecord.Name := FormatUTF8('TestName%', [LRand]);
        lSQLTestRecord.Blob := 'TEST';
        RestServer.AddWithBlobs(lSQLTestRecord);
      finally
        FreeAndNil(lSQLTestRecord);
      end;

      (*
        Retrieve record and update blob
      *)
      lSQLTestRecord := TSQLTestRecord.Create;
      try
        RestServer.Retrieve('Name=?', [], [FormatUTF8('TestName%', [LRand])], lSQLTestRecord, '*');
        LID := lSQLTestRecord.IDValue;
        lSQLTestRecord.Blob := '7777777777777777777777777777777777777777';

        (*
          Neither UpdateBlobFields or UpdateBlob will be recorded in TSynLog
        *)
        RestServer.UpdateBlobFields(lSQLTestRecord);
        // RestServer.UpdateBlob(TSQLTestRecord, LID, 'Blob', '----123-----');
      finally
        FreeAndNil(lSQLTestRecord);
      end;

      ReadLn;

    finally
      RestServer.Free;
    end;

  except
    on E: Exception do
      WriteLn(E.ClassName, ': ', E.Message);
  end;

end.

And here is the log generated

20190314 07591661  +    SynSQLite3.TSQLDatabase(02717B30).DBOpen test.db
20190314 07591661 SQL   	SynSQLite3.TSQLDatabase(02717B30) 108us test.db PRAGMA page_size=4096
20190314 07591661 SQL   	SynSQLite3.TSQLDatabase(02717B30) 282us test.db PRAGMA cache_size=10000
20190314 07591661 DB    	SynSQLite3.TSQLDatabase(02717B30) "C:\MormoTTest\UpdateBlobTest\Win64\Debug\test.db" database file (0 B) opened with PageSize=4096 CacheSize=10000 (39 MB)
20190314 07591661  -    00.000.973
20190314 07591661 SQL   SynSQLite3.TSQLDatabase(02717B30) 162us test.db returned 0 rows SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';
20190314 07591661 DB    mORMotSQLite3.TSQLRestServerDB(026CFCB0) CreateMissingTables on {"TSQLDatabase(02717B30)":{"FileName":"C:\\MormoTTest\\UpdateBlobTest\\Win64\\Debug\\test.db","UseCache":true,"CacheSize":10000,"PageSize":4096,"Synchronous":"smFull","OpenV2Flags":6,"SQLite3Library":{"TSQLite3LibraryDynamic(026FEA30)":{"LibraryName":"sqlite3-64.dll","Version":"3.24.0 with internal MM"}}}}
20190314 07591661 DB    mORMotSQLite3.TSQLRestServerDB(026CFCB0) GetTables=[]
20190314 07591661 SQL   SynSQLite3.TSQLDatabase(02717B30) 9us test.db BEGIN TRANSACTION;
20190314 07591661 SQL   SynSQLite3.TSQLDatabase(02717B30) 657us test.db CREATE TABLE TestRecord(ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT COLLATE SYSTEMNOCASE UNIQUE, Blob BLOB);
20190314 07591661 SQL   mORMotSQLite3.TSQLRestServerDB(026CFCB0) 101us  CREATE INDEX IF NOT EXISTS IndexTestRecordName ON TestRecord(Name);
20190314 07591700 SQL   SynSQLite3.TSQLDatabase(02717B30) 27.13ms test.db COMMIT TRANSACTION;
20190314 07591700 DB    mORMotSQLite3.TSQLRestServerDB(026CFCB0) prepared 21us test.db INSERT INTO TestRecord (Name,Blob) VALUES (?,?);
20190314 07591702 SQL   mORMotSQLite3.TSQLRestServerDB(026CFCB0) 29.88ms  lastInsertedID=1 INSERT INTO TestRecord (Name,Blob) VALUES (:('TestName1008988397'):,:('￰VEVTVA=='):);
20190314 07591702 DB    mORMotSQLite3.TSQLRestServerDB(026CFCB0) prepared 71us test.db SELECT ID,Name,Blob FROM TestRecord WHERE Name=?
20190314 07591702 SQL   mORMotSQLite3.TSQLRestServerDB(026CFCB0) 76us returned 1 row as 60 B SELECT ID,Name,Blob FROM TestRecord WHERE Name=:('TestName1008988397'):
20190314 07591702 res   SynSQLite3.TSQLDatabase(02717B30) [{"ID":1,"Name":"TestName1008988397","Blob":"￰VEVTVA=="}] 
20190314 07591702 cache SynSQLite3.TSQLDatabase(02717B30) test.db cache flushed
20190314 07591804  +    mORMotSQLite3.TSQLRestServerDB(026CFCB0).Destroy root
20190314 07591804  +    	mORMotSQLite3.TSQLRestServerDB(026CFCB0).Shutdown() root CurrentRequestCount=0
20190314 07591804  -    	00.005.161
20190314 07591804 info  	mORMotSQLite3.TSQLRestServerDB(026CFCB0) Destroy root
20190314 07591804  +    	SynSQLite3.TSQLDatabase(02717B30).Destroy test.db
20190314 07591804  +    		SynSQLite3.TSQLDatabase(02717B30).DBClose
20190314 07591804 DB    			SynSQLite3.TSQLDatabase(02717B30) closing "C:\MormoTTest\UpdateBlobTest\Win64\Debug\test.db" 20 KB
20190314 07591804  -    		00.000.189
20190314 07591804  -    	00.000.197
20190314 07591804  -    00.005.424

Offline

#2 2019-03-14 11:07:17

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

Re: UpdateBlobFields or UpdateBlob is not recorded in TSynLog

Offline

#3 2019-03-14 12:06:11

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 210

Re: UpdateBlobFields or UpdateBlob is not recorded in TSynLog

wow that was so fast , thank you ab.

now it adds to log:

20190314 11473305 DB    mORMotSQLite3.TSQLRestServerDB(026CFCB0) prepared 21us test.db UPDATE TestRecord SET Blob=? WHERE ROWID=?
20190314 11473307 SQL   mORMotSQLite3.TSQLRestServerDB(026CFCB0) 20.28ms stored 40 B in ID=6 UPDATE TestRecord SET Blob=? WHERE ROWID=?

Is it possible to log the blob value also, just like for the INSERT statement?

Offline

Board footer

Powered by FluxBB