Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Inserting/selecting BLOB records with Firebird database
Versions des environnements
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
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement