Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Inserting/selecting BLOB records with Firebird database
Message
From
17/05/2005 15:02:50
 
 
To
17/05/2005 13:14:19
Héctor Lizarraga
Gobierno Del Edo de Querétaro
Querétaro, Mexico
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP
Miscellaneous
Thread ID:
01014996
Message ID:
01015041
Views:
18
>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?


Hector:

Instead of reading the image (JPG) file char-by-char with low level functions, you can just load it into a BLOB in VFP9.0 with:
cBLOB=FileToStr('c:\esc.jpg')
cBLOB is now a memvar that you can send to a BOB field in the back-end database (or insert into a BLOB in a DBF now too!)

I do not know FireBird but I assume your TEST_TABLE.TEST_FIELD is of type BLOB.
Try it first in a DBF and see how it works. When you extract it back you can STRTOFILE() from cBLOB and you get the original image in a new file.


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Reply
Map
View

Click here to load this message in the networking platform