Need help with inserting blob data to SQLite 3 database.

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

krzysiek_grucha
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 21.12.2010, 20:40

Need help with inserting blob data to SQLite 3 database.

Postby krzysiek_grucha » 02.01.2011, 14:47

Hello !

For 3 days I'm fighting with inserting files into SQLite 3 database. I'm using CodeGear C++ Builder 2009 with ZeosLib 7.0.0 aplha installed.

As for now I'm doing something like this to save files into database:

Code: Select all

   if((LabeledEdit1->Text.Length() > 0) && (LabeledEdit2->Text.Length() > 0)){
      TFileStream * file = new TFileStream(LabeledEdit2->Text, fmOpenRead);

      ZQuery1->Active = false;
      ZQuery1->SQL->Clear();
      ZQuery1->SQL->Add("insert into data(\"nazwa\", \"binary\") values(" + LabeledEdit1->Text + ", :binary)");
      ZQuery1->ParamByName("binary")->LoadFromStream(file, ftBlob);
      ZQuery1->ExecSQL();
      delete file;
   }


After execution of this code I get an error: SQL error: library routine called out of sequence.

I have a database with only one table, just for testing purposes, with create statement like shown below:

Code: Select all

CREATE TABLE "data" ("id" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "nazwa" TEXT NOT NULL , "binary" BLOB NOT NULL )


My "load file from database" function looks like this:

Code: Select all

   if(LabeledEdit3->Text.Length() > 0){
      TStream * blob;
      TFileStream * filestr;

      ZQuery1->Active = false;
      ZQuery1->SQL->Clear();
      ZQuery1->SQL->Add("select * from data where id = " + LabeledEdit3->Text);
      ZQuery1->Active = true;

      blob = ZQuery1->CreateBlobStream(DataSource1->DataSet->FieldByName("binary"), bmRead);

      if(SaveDialog1->Execute()){
         filestr = new TFileStream(SaveDialog1->FileName, fmCreate);
         filestr->CopyFrom(blob, blob->Size);
         delete blob;
         delete filestr;
      }

      ZQuery1->Active = false;
   }


If someone can help my with this problem I would appreciate. If You also see some bugs with this code, please show me them, because it will be a good lesson for me.

Best wishes,
Chris.

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 02.01.2011, 19:56

Chris,

If you're just using the one year old 7.0.0-alpha, please upgrade to a recent snapshot. http://zeosdownloads.firmos.at/downloads/snapshots . There's a preview available for a 7.0.1-alpha version. Please check it and report if this does or does not solve your problem.

Mark
Image

krzysiek_grucha
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 21.12.2010, 20:40

Postby krzysiek_grucha » 02.01.2011, 22:36

Thank You Mark for Your answer.

I'll upgrade my version and post back the changes.

Chris.

Today I installed the newest version of ZeosLib from the link You gave me Mark, but the problem still exists in my project, when I'm trying to add a file to a database - SQL Error: Library routine called out of sequence. I haven't got any clue where to find the reason of this error.

The second thing is that ZeosLib 7.0.1 needs a file ZPlainMySQL41.pas when trying to install it. The problem is that the file is not included in the Zeos package, so if I'm trying to install the whole package I must find that file in the internet (what causes more problems) or delete the file from package, and install ZeosLib without ZPlainMySQL41.pas (works just fine for me :) ).

Chris.

Another edit :) .

I was constantly thinking about my project, and figured out, that i have to remove the old ZConnection component placed in the project, with the new one from the updated installation, and gues what ? Everything is working just fine :D .

I found another thing - after adding TZConnectionGroup component to the project I get some errors:

Code: Select all

[BCC32 Error] xlocale(908): E2040 Declaration terminated incorrectly


And the file xocale is opened in IDE on the 908 line:

Code: Select all

struct _CRTIMP2 ctype_base
   : public locale::facet
   {   // base for ctype
   enum
      {   // constants for character classifications
      alnum = _DI|_LO|_UP|_XA, alpha = _LO|_UP|_XA,
      cntrl = _BB, digit = _DI, graph = _DI|_LO|_PU|_UP|_XA,
      lower = _LO, print = _DI|_LO|_PU|_SP|_UP|_XA|_XD,
      punct = _PU, space = _CN|_SP|_XS, upper = _UP,
      xdigit = _XD};
   [b]typedef short mask;   // to match <ctype.h>[/b]

   ctype_base(size_t _Refs = 0)
      : locale::facet(_Refs)
      {   // default constructor
      }

   ~ctype_base()
      {   // destroy the object
      }
   };


Maybe it is just an error in my IDE, caused by the removal of ZPlainMySQL41.pas, I'm not sure.

I'm not using TZConnectionGroup, but found this issue, so trying to help.

Chris.


Return to “SQLite”

Who is online

Users browsing this forum: No registered users and 1 guest