Page 1 of 1

SQLite Blob Fields Problem

Posted: Tue 25 Nov 2014 13:53
by Raphael Vital
Hi,

I'm trying to use evaluation version of UniDac5512 but in my first test I see the problem with blobs text fields:

I have two fields blob text in my table, fieldA, fieldB and other fields, string, booleans and so on. When I make a update in any other field in this table, the contents of blob text fields vanish. Yes! The text inside both of them just disappear. The other fields, including string fields (varchar 40) remains with the correct contents.

Additional info: I'm using TuniQuery, TClientDataset, TDataSetProvider, TDataSource.
Delphi Version 7 Update Pack2, Windows XP. In problem table, the
TDataSetprovider is set updates to "WhereChanged" and the KeyField set properly in both
(TUniQuery, TClientDataSet).

I'm try this component for access SQLite by indication and I planned to buy, if everything is fine on my system. I tried to understand what happens with the blob text contents and why JUST text on the blobs dissapears. :shock:

Thanks for any kind of help.

R.Vital Mello
Brasil.

P.S: Sorry, my english bites sometimes! :oops:

Re: SQLite Blob Fields Problem

Posted: Wed 26 Nov 2014 07:31
by AlexP
Hello,

We couldn't reproduce the error on the latest LiteDAC version 2.4.12. The code below works correctly, please modify this code so that the problem can be reproduced and send it to us.

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils, LiteAccess, DB, DBClient, Provider;

var
  LiteConnection: TLiteConnection;
  LiteQuery: TLiteQuery;
  DataSetProvider: TDataSetProvider;
  ClientDataSet: TClientDataSet;

begin
  LiteConnection := TLiteConnection.Create(nil);
  try
    LiteConnection.ConnectString := 'Data Source=:memory:;LoginPrompt=False';
    LiteConnection.Connect;
    LiteConnection.ExecSQL('CREATE TABLE TEST(ID INTEGER, TXT VARCHAR2(40), fieldA TEXT, fieldB TEXT, CONSTRAINT PK_TEST PRIMARY KEY(ID))');
    LiteConnection.ExecSQL('INSERT INTO TEST VALUES(1, ''test'', ''fieldA'', ''fieldB'')');
    LiteQuery := TLiteQuery.Create(nil);
    try
      LiteQuery.Connection := LiteConnection;
      LiteQuery.SQL.Text := 'SELECT * FROM TEST';
      LiteQuery.KeyFields := 'ID';
      DataSetProvider := TDataSetProvider.Create(nil);
      try
        DataSetProvider.DataSet := LiteQuery;
        DataSetProvider.UpdateMode := upWhereChanged;
        ClientDataSet := TClientDataSet.Create(nil);
        try
          ClientDataSet.SetProvider(DataSetProvider);
          ClientDataSet.Open;
          Writeln('Blob Values Before Edit:');
          Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString]));
          ClientDataSet.Edit;
          ClientDataSet.FieldByName('TXT').AsString := 'New text';
          ClientDataSet.Post;
          ClientDataSet.ApplyUpdates(-1);
          Writeln('Blob Values After Edit:');
          Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString]));
        finally
          ClientDataSet.Free;
        end;
      finally
        DataSetProvider.Free;
      end;
    finally
      LiteQuery.Free;
    end;
  finally
    LiteConnection.Free;
    Readln;
  end;
end.

Re: SQLite Blob Fields Problem

Posted: Fri 28 Nov 2014 12:10
by Raphael Vital
Alexp,

Maybe I have posted in wrong place. Not is LiteDAC version 2.4.12. I have installed UNIDAC 5.5.12. The code you posted return an error in LiteAcess.dcu (file not found).

Have any difference between LiteDac and UniDac or I'm do anything wrong? Sorry if I made a mistake. My environment variables (paths) are set correctly for UniDac 5512.

Thanks for your attention.

R.Vital Mello
Brasil.

P.S: Sorry, my english bites a lot sometimes! :oops:

Re: SQLite Blob Fields Problem

Posted: Mon 01 Dec 2014 09:01
by AlexP
Please replace the LiteAccess module with the Uni and SQLiteUniProvider ones in the Uses section, as well declarations and creation of the TLiteConnection and TLiteQuery classes with TUniConnection and TUniQuery respectively, and test the code once more (UniDAC 6.0.1).

Re: SQLite Blob Fields Problem

Posted: Wed 03 Dec 2014 12:34
by Raphael Vital
Hi Alex,

The Result is:

Blob Values Before Edit:
Value of FieldA: fieldA
Value of Fieldb: fieldB
Blob Values After Edit:
Value of FieldA: fieldA
Value of Fieldb: fieldB
ClientDataSet.FieldByName('TXT').AsString := 'New text';
In FieldA the text inserted 'NEW TEXT' does not appear.

I'm running the code right or I'm doing a little mess?

Because missing Provider and DataSetProvider declarations, I change the code to:


{$APPTYPE CONSOLE}

uses
SysUtils,
Uni,
SQLiteUniProvider,
DB,
DBClient,
Provider;

var
UniConnection: TUniConnection;
UniQuery: TUniQuery;
DataSetProvider: TDataSetProvider;
ClientDataSet: TClientDataSet;

begin
UniConnection := TUniConnection.Create(nil);
try
UniConnection.ProviderName := 'SQLite';
UniConnection.ConnectString := 'Provider Name=SQLite;Data Source=:memory:;LoginPrompt=False';
UniConnection.Connect;
UniConnection.ExecSQL('CREATE TABLE TEST(ID INTEGER, TXT VARCHAR2(40), fieldA TEXT, fieldB TEXT, CONSTRAINT PK_TEST PRIMARY KEY(ID))');
UniConnection.ExecSQL('INSERT INTO TEST VALUES(1, ''test'', ''fieldA'', ''fieldB'')');


UniQuery := TUniQuery.Create(nil);
try
UniQuery.Connection := UniConnection;
UniQuery.SQL.Text := 'SELECT * FROM TEST';
UniQuery.KeyFields := 'ID';
DataSetProvider := TDataSetProvider.Create(nil);
try
DataSetProvider.DataSet := UniQuery;
DataSetProvider.UpdateMode := upWhereChanged;
ClientDataSet := TClientDataSet.Create(nil);
try
ClientDataSet.ProviderName := 'DataSetProvider';
ClientDataSet.SetProvider(DataSetProvider);
ClientDataSet.Open;
Writeln('Blob Values Before Edit:');
Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString]));
ClientDataSet.Edit;
ClientDataSet.FieldByName('TXT').AsString := 'New text';
ClientDataSet.Post;
ClientDataSet.ApplyUpdates(-1);
Writeln('Blob Values After Edit:');
Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString]));
finally
ClientDataSet.Free;
end;
finally
DataSetProvider.Free;
end;
finally
UniQuery.Free;
end;
finally
UniConnection.Free;
Readln;
end;
end.


Thanks for your support
Raphael Vital

Re: SQLite Blob Fields Problem

Posted: Wed 03 Dec 2014 13:17
by AlexP
When executing this code, data in a varchar field are saved correctly.

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Uni,
  SQLiteUniProvider,
  DB,
  DBClient,
  Provider;

var
  UniConnection: TUniConnection;
  UniQuery: TUniQuery;
  DataSetProvider: TDataSetProvider;
  ClientDataSet: TClientDataSet;

begin
  UniConnection := TUniConnection.Create(nil);
  try
    UniConnection.ProviderName := 'SQLite';
    UniConnection.ConnectString := 'Provider Name=SQLite;Data Source=:memory:;LoginPrompt=False';
    UniConnection.Connect;
    UniConnection.ExecSQL('CREATE TABLE TEST(ID INTEGER, TXT VARCHAR2(40), fieldA TEXT, fieldB TEXT, CONSTRAINT PK_TEST PRIMARY KEY(ID))');
    UniConnection.ExecSQL('INSERT INTO TEST VALUES(1, ''test'', ''fieldA'', ''fieldB'')');


    UniQuery := TUniQuery.Create(nil);
    try
      UniQuery.Connection := UniConnection;
      UniQuery.SQL.Text := 'SELECT * FROM TEST';
      UniQuery.KeyFields := 'ID';
      DataSetProvider := TDataSetProvider.Create(nil);
      try
        DataSetProvider.DataSet := UniQuery;
        DataSetProvider.UpdateMode := upWhereChanged;
        ClientDataSet := TClientDataSet.Create(nil);
        try
          ClientDataSet.ProviderName := 'DataSetProvider';
          ClientDataSet.SetProvider(DataSetProvider);
          ClientDataSet.Open;
          Writeln('Blob Values Before Edit:');
          Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s%sValue of TXT: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString, #13#10, ClientDataSet.FieldByName('TXT').AsString]));
          ClientDataSet.Edit;
          ClientDataSet.FieldByName('TXT').AsString := 'New text';
          ClientDataSet.Post;
          ClientDataSet.ApplyUpdates(-1);
          Writeln('Blob Values After Edit:');
          Writeln(Format('Value of FieldA: %s%sValue of Fieldb: %s%sValue of TXT: %s', [ClientDataSet.FieldByName('fieldA').AsString, #13#10, ClientDataSet.FieldByName('fieldB').AsString, #13#10, ClientDataSet.FieldByName('TXT').AsString]));
        finally
          ClientDataSet.Free;
        end;
      finally
        DataSetProvider.Free;
      end;
    finally
      UniQuery.Free;
    end;
  finally
  UniConnection.Free;
  Readln;
  end;
end.

Re: SQLite Blob Fields Problem

Posted: Wed 03 Dec 2014 13:57
by Raphael Vital
Hi,

The question is: varchar data are saved in my system too but the contents of both blob fields are erased. This code perhaps not do this. I reviewed all my code and there's nothing i can see wrong to do that. And if are a bug, why ONLY this two blob fields? All the other data remains there.
I don't know why and I have no clue where I can search where the bug is. I've tried to remove all components and reset again and nothing happens.

There's a new data: in other form i have, with blob fields, the problem is the same, so, is not the set of components for "one" particulary table, is general.

In this other table, the componentes are setted in another way and using the same trio "clientdataset->dataseprovider->, uniquery".

It's funny, don't you think? Seems a little bug hidden in a small corner of code, but now I have one nervous breakdown. =)))


Thanks for all your support.

Raphael Vital

Re: SQLite Blob Fields Problem

Posted: Thu 04 Dec 2014 05:44
by AlexP
Please send me your project (including the database file) to alexp*devart*com - and we will check this issue on your sample.