KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Send and receive a picture with 4D ODBC
PRODUCT: 4D | VERSION: 6.8.4 | PLATFORM: Mac & Win
Published On: October 30, 2003

Versions: 6.8.x and 2003.x

The following is a simple approach on how to send and receive a picture through an ODBC datasource.

Example: Sending a picture

C_TEXT($sql)
C_LONGINT($currsorID;$res)
C_BLOB(vBlob)
PICTURE TO BLOB(vPicture;vBlob;"JPEG")
$currsorID:=OC Create cursor (<>connectID)
If ($currsorID#-1)
$sql:="insert into PictureTable values (?)"
$res:=OC Set SQL in Cursor ($currsorID;$sql)
If ($res=1)
$res:=OC Bind parameter ($currsorID;1;"vBlob";1)  ` SQL_BINARY/BLOB
$res:=OC Execute cursor ($currsorID)
End if
OC DROP CURSOR ($currsorID)
End if

In this example, the command OC Bind parameter is used to bind a picture variable to a Blob column (SQL_BINARY) in the ODBC datasource.

Example: Receiving a picture through ODBC datasource

C_TEXT($sql)
C_LONGINT($currsorID;$res)
C_PICTURE(vPicture)
C_BLOB(vBlob)
$currsorID:=OC Create cursor (<>connectID)
If ($currsorID#-1)
$sql:="select picture from PictureTable where pictureid=123"
$res:=OC Set SQL in Cursor ($currsorID;$sql)
If ($res=1)
$res:=OC Bind ($currsorID;1;"vBlob")  ` SQL_BINARY
$res:=OC Execute cursor ($currsorID)
$res:=OC Load row ($currsorID)
BLOB TO PICTURE(vBlob;vPicture)
End if
OC DROP CURSOR ($currsorID)
End if

In this example, a variable vBlob is bound to a blob column named picture with the command OD Bind. Once the result is returned to the variable vBlob, the command BLOB TO PICTURE will inserts a picture stored in a BLOB into the 4D picture variable (vPicture)