Forums


Aducom Software :: Forums :: Delphi SQLite Version 3.0.x Components :: Questions
 
<< Voorgaande discussie | Volgende discussie >>
CreateBlobStream
Ga naar pagina  [1] 2
Moderators: aducom, aducomadmin2
Auteur Bericht
cyrn
wo nov 17 2004, 01:34
Geregistreerde deelnemer #134
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

FileStream := TFileStream.Create('c:image.jpg',fmOpenRead or fmShareDenyNone);
BlobStream.CopyFrom(FileStream,FileStream.Size);
FileStream.Free;
BlobStream.Free;
ASQLite3Table1.Post;
except
ASQLite3Table1.Cancel;
end;

end;


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?

Thanks,

Nic
Terug omhoog
aducom
wo nov 17 2004, 02:02

Geregistreerde deelnemer #1
Geregistreerd: wo jan 25 2006, 04:34
Woonplaats: groningen (NL)
berichten: 1561
I tested it with:

link

albert

albert
Terug omhoog
cyrn
wo nov 17 2004, 02:31
Geregistreerde deelnemer #134
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');

ASQLite3Query1.SQL.Clear;
ASQLite3Query1.SQL.Add('INSERT INTO employee8 VALUES(NULL, :Image);');
ASQLite3Query1.Params.Add;
ASQLite3Query1.Params.Items.LoadFromStream(BlobStream, ftBlob);
ASQLite3Query1.ExecSQL;
ASQLite3Query1.SQL.Clear;
end;
Terug omhoog
aducom
wo nov 17 2004, 02:44

Geregistreerde deelnemer #1
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).

albert

albert
Terug omhoog
cyrn
wo nov 17 2004, 03:02
Geregistreerde deelnemer #134
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.

Thanks,

Nic
Terug omhoog
aducom
do nov 18 2004, 01:51

Geregistreerde deelnemer #1
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);

var_Stream := TMemoryStream.Create;
var_Stream.LoadFromFile('c:test.bmp');

SQLQuery.Close();
SQLQuery.SQL.Clear();
SQLQuery.SQL.Add('INSERT INTO PHOTO VALUES(:v)');

SQLQuery.Params.Items[0].LoadFromStream(var_Stream, ftBlob);

SQLQuery.ExecSQL();
SQLQuery.Close();

Var_Stream.Free;
end;


albert

albert
Terug omhoog
aducom
do nov 18 2004, 02:07

Geregistreerde deelnemer #1
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.

Albert

albert
Terug omhoog
cyrn
do nov 18 2004, 08:48
Geregistreerde deelnemer #134
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.

Any ideas?

Nic
Terug omhoog
aducom
do nov 18 2004, 09:13

Geregistreerde deelnemer #1
Geregistreerd: wo jan 25 2006, 04:34
Woonplaats: groningen (NL)
berichten: 1561
I created the table as:

Create table photo(thephoto blob);

Do yo have the latest sqlite3.dll? I had similar problems, but they are solved now...

albert

albert
Terug omhoog
cyrn
do nov 18 2004, 09:40
Geregistreerde deelnemer #134
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.

thank you,
Nic
Terug omhoog
Ga naar pagina  [1] 2  

Ga naar:     Terug omhoog

Publiceer deze discussie: RSS 0.92 Publiceer deze discussie: RSS 2.0 Publiceer deze discussie: RDF
Powered by e107 Forum System