#1 2014-12-07 00:01:10

steadfast
Member
Registered: 2011-09-30
Posts: 2

Error in TSQLDBConnection.NewTableFromRows

While debugging my application I found an error in this function:

3972          for i := 0 to n-1 do
3973            if Fields[i].DBType=ftUnknown then
3974              Types[ i ] := ftInt64  // <=== was Types[ n ] ...
3975            else
3976              Types[ i ] := Fields[i].DBType;  // <=== was Types[ n ] ...
3977          Properties.GetTableNames(Tables);

The error meant that all field types were being left as ftUnknown and not being processed

I still have an error in my application when processing BLOBS...
I am importing a database from file into an in-memory database (opened with ':memory:' filename).
All records and fields are being imported correctly EXCEPT for blobs.
The blobs are saved using the SaveToRawByteString into a field defined as  fCustomPicture: TSQLRawBlob;
I can view the blob using an external SQLite3 db management tool, so I know it is saved correctly.

When the NewTableFromRows function processes that field it thinks the column type is ftUTF8 and I end up with content in that field like "PNG
" which is not recognised as a blob and causes errors when trying to retrieve it.

Should the field type be ftBlob and there is an error in the routine?  Or am I doing something wrong?

My code is copied from sample12:

  if aSourceFileName <> '' then
  begin
    ExcludeTypes := [];
    SourceProp := TSQLDBSQLite3ConnectionProperties.Create(StringToUTF8(aSourceFileName),'','','');
    TargetProp   := TSQLDBSQLite3ConnectionProperties.Create(TSQLRestServerDB(aDestDB).DB);
    try
      TargetConn := TargetProp.MainConnection as TSQLDBSQLite3Connection;
      TargetConn.Connect;
      try
        TargetConn.DB.ExecuteAll('PRAGMA journal_mode=MEMORY;PRAGMA journal_size_limit=16777216;'+'PRAGMA synchronous=OFF;');
        TSQLRestClientURI(SourceProp.MainConnection).ForceBlobTransfert := true;
        TSQLRestClientURI(TargetConn).ForceBlobTransfert := true;
        SourceProp.GetTableNames(Tables);
        TableList  := TStringList.Create;
        try
          TableList.CommaText := UTF8ToString(RawUTF8ArrayToCSV(Tables,#13#10));
          for i := 0 to TableList.Count - 1 do
          begin
            Application.ProcessMessages;
            SQL := format('SELECT * FROM %s',[TableList.Strings[i]]);
            rows := SourceProp.NewThreadSafeStatement;
            try
              rows.Prepare(SQL,true);
              rows.ExecutePrepared;
              result := TargetConn.NewTableFromRows(S2U(TableList.Strings[i]),Rows,true); 

Offline

#2 2014-12-08 14:13:27

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

Re: Error in TSQLDBConnection.NewTableFromRows

Should be fixed by http://synopse.info/fossil/info/6fc957a230
We have also added a new optional parameter, to allow defining a custom set of column types for the resulting table.
Thanks for the report!

BTW if you want to copy one database into another, consider using the background thread backup feature instead.

Offline

Board footer

Powered by FluxBB