General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Inserting/selecting BLOB records with Firebird database
Does anyone knows how can I insert/select BLOB records into a Firebird database?
Here are the steps:
I assure that the result cursor be of vfp BLOB type
=CURSORSETPROP("MapBinary",.T.,0)
First, I connect to the database:
lcDriver = "{Firebird/InterBase(r) driver}"
lcUid = "SYSDBA"
lcPwd = "masterkey"
lcFbd = "127.0.0.1:Prueba"
lcDsnString = [DRIVER=] + lcDriver + [;UID=] + lcUid + [;PWD=] + lcPwd + [;DBNAME=] + lcFbd
nHnd=SQLSTRINGCONNECT(lcDsnString)
*///
Second, I populate a string containing the jpg file I want to upload to the database. This is in a prg called blob.prg
cChar = ''
nFileHnd=FOPEN('c:\esc.jpg') && This file is 8k long
=FSEEK(nFileHnd, 0, 0)
DO WHILE !FEOF(nFileHnd)
cChar = cChar + FREAD(nFileHnd,1)
ENDDO
*///
Then I send the sql string to the server
cQuery = 'insert into TEST_TABLE (TEST_FIELD) VALUES (?cChar)'
SQLPREPARE(nHnd,cQuery,'curResult')
SQLEXEC(nHnd)
*///
The record seems to be OK in the IB Expert admin tool.
cQuery = 'SELECT * FROM TEST_TABLE'
SQLPREPARE(nHnd,cQuery,'curResult')
SQLEXEC(nHnd)
*///
=STRTOFILE(curResult.test_field,'C:\esc2.jpg')
The result file is 4k long and is not recognized as a jpg. There are no ODBC errors.
What is wrong?
Any ideas?
Thanks in advance
Héctor L.
Mexico
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only