I successfully add a binary picture of 34554 bytes into the database with the code below :
Code: Select all
;/ PureBasic 4.51
;- Store binary data
;/ Create DatabaseUsePostgreSQLDatabase()
If OpenDatabase(0, "host=127.0.0.1 port=5432", "postgres", "root")
Debug "Open : Succès"
Else
Debug "Open : Fail"
End
EndIf
If DatabaseUpdate(0,"CREATE TABLE Pictures ( Blob1_data BYTEA) ; ")=0
Debug DatabaseError()
EndIf
;/ Read the picture and put in a buffer (34554 bytes)
Picture.s="d:\Picture1.bmp"
PictureSize=FileSize(Picture)
Debug PictureSize
*buffer=AllocateMemory(PictureSize)
ReadFile(0,Picture)
ReadData(0,*buffer,PictureSize)
CloseFile(0)
;/ Add binary data to database
SetDatabaseBlob(0,0,*buffer,PictureSize)
If DatabaseUpdate(0, "INSERT INTO Pictures VALUES ($1);")=0
Debug DatabaseError()
EndIf
FreeMemory(*buffer)
;/ Read Binary data to buffer
DatabaseQuery(0,"SELECT * FROM Pictures ;")
NextDatabaseRow(0)
PictureSize=DatabaseColumnSize(0,0) ;/ Get size of the blob
Debug PictureSize
*buffer=AllocateMemory(PictureSize)
GetDatabaseBlob(0,0,*buffer,PictureSize)
;/ Write buffer to file
Picture2.s="d:\Picture2.bmp"
CreateFile(0,Picture2)
WriteData(0,*buffer,PictureSize)
CloseFile(0)
FreeMemory(*buffer)
FinishDatabaseQuery(0)
CloseDatabase(0)
Thanks