Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
hi,
I just want to store a picture into the db using v3 component. I think it is supposed to work if I update the component with the new ASGSQlite3.pas Version Beta 1.0.B file, available on the download page... Isn' it? Anyway, it doesn't work on my computer. I create a db, with a table created with SQL statement as follows :
I found on the web some sample code to store image in a BLOB field. Here it is:
procedure TForm1.Button5Click(Sender: TObject); var FileStream: TFileStream; BlobStream: TStream; begin ASQLite3Table1.Edit; try
On the line BlobStream := ASQLite3Table1.CreateBlobStream(TBlobField(ASQLite3Table1.FieldByName('image')),bmWrite);, I get the 'Invalid class typecast' error message.
On ww.sqlite.org it says any type of field is supposed to be able to be typecasted as a blob...
Do you have sample code to save picture in a db using blobs?
Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
This is not Delphi 6 compatible code... Do you have Delphi code to insert BLOBs in a db?
I tried to translate in delphi, I can execute the SQL statement without error, but when I close the DB, I get an Access Violation in rtl60.bpl. I tried twice with 2 new db.
This it the code I translated:
procedure TForm1.Button7Click(Sender: TObject); var BlobStream: TMemoryStream; begin BlobStream := TMemoryStream.Create; BlobStream.LoadFromFile('c:image1.jpg');
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
I Couldn't reach our development system due to some network trouble, but I will look for the sample tomorrow. But your translated code looks allright to me although I don't know why the null value should be used. I would try insert image into employee8 values (:img) The sample of the c++ database used a integer primary key. Inserting NULL causes an autoincrement of the key. Do you have the same? But again, I don't have access to our development system right now so I'll check it out tomorrow. (the clear after execsql is not necessary if you're not reusing the query. Just close it).
Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
As the definition of my table has two columns, id and image, i have to give two values to my insert statement. If the statement is "insert image into employee8 values (:img)", one value is missing. I tried specifying "insert image into employee8 values (1, :img)" and "insert image into employee8 values (NULL, :img)" (for auto-increment field ID) and it doesn't change anything. Also, I removed the Clear and Closed the Query and it didn't changed anything.
I will wait for your Delphi example code tomorrow.
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
The following code works well here. (Be sure the sqlite3.dll can be found and use the latest release. The av was generated in sqlite3.dll)
procedure TForm1.BitBtn1Click(Sender: TObject); var var_Stream : TMemoryStream; begin Image1.Picture.LoadFromFile('c:test.bmp');//OpenDialog1.FileName);
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
I noticed that sometimes an error can occur, useually on loading the application in Delphi, somehow it is not able to load or find the sqlite3.dll. This only occurs if the database is open when you load the source (active property of the database set to true). Although this is generally a bad idea, best is to open the database by yourself in the application, the application compiles fine and runs fine, but you cannot open the database in the designer any more. The message keeps comming up. Restarting Delphi useually solves the error. I have noticed such behaviour on mysql and oracle packages too. So it's probabely something in the creation order of Delphi, but I'm not sure. It doesn't always happen and in production situations I haven't noticed this kind of error.
Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
Can you tell me how have you created the table PHOTO you use in the example SQL statement?
This is how I created my table, but it still doesn't work: ASQLite3Query1.SQL.Add('create table employee1 (image);'); ASQLite3Query1.ExecSQL;
As you said, I activate the database connection and the table's Active property to true by a button click at runtime. I copy-pasted your code in another onButtonClick event, and it executes without problems.
The problem is when I close the application, and open it back again, when I set the Active property of the table (after having connected the db) to true, I get an Access violation error. Also, the db size doesn't reflect the fact that I added an image in it.
Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
Yes, I have the latest dll from your website. Is it possible the version on your website is not your latest version? Because the last modified date on the sqlite3.dll file from your website is july 7th, 2004.