Eric,
In the PowerBasic Windows forum I started a thread concerning how to store and retrieve a PDF into a VARBINARY sql 2005 db, retrieve it as a variable, save it to a file and redisplay it as a pdf.
Here is my last posted code sample.
Carlo helped me with the saving part. Can't tell if it worked because I can't get the retrieving part to report an data read for that column though the other columns come back without error.
In the PowerBasic Windows forum I started a thread concerning how to store and retrieve a PDF into a VARBINARY sql 2005 db, retrieve it as a variable, save it to a file and redisplay it as a pdf.
Here is my last posted code sample.
Code:
'Basic structure to insert your PDF file into a binary field local SQL AS STRING, PDF_File as STRING 'local lResult as long SHELL ENVIRON$("COMSPEC") + " /C C:\PDFS\CULAND2.PDF",0 OPEN "C:\PDFS\CULAND2.PDF" FOR BINARY AS 1 GET$ 1,LOF(1),PDF_File CLOSE 1 SQL = "insert STMTPDFS ([ACCOUNT],[DATESTR],[QUALIFIER],[PDFDOC]) VALUES('1101500','2009-07-17','UNAUDITED',?)" lresult& = SQL_Statement(1, 1, %SQL_STMT_PREPARE,SQL) ' IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 1", MSGBOX_OK END IF IF lresult& = %Success THEN 'Bind parameters lresult& = SQL_BindParameter(1, 1, 1, %SQL_PARAM_INPUT, 99, %SQL_LONGVARBINARY, LEN(PDF_File), 0, 1, LEN(PDF_File), %SQL_LONG_DATA) 'lIndicator& IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 2", MSGBOX_OK END IF IF lresult& = %Success then 'Execute the SQL statement lresult& = SQL_Statement(1, 1, %SQL_STMT_EXECUTE, "") IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 3", MSGBOX_OK END IF if lresult& = %Success then 'Tell the driver that we are about to "fill" a parameter lresult& = SQL_NextParameter(1, 1) IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 4", MSGBOX_OK END IF IF lresult& = %Success then lresult& = SQL_LongParameter(1, 1, PDF_File, LEN(PDF_File)) IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 5", MSGBOX_OK END IF if lresult& = %Success then lresult& = SQL_NextParameter(1, 1) IF SQL_Errorpending THEN SQL_MsgBox SQL_ErrorQuickOne + " 6", MSGBOX_OK END IF end if end if end if end if end if if lresult& <> %Success then msgbox "Problem somewhere" end if ' ' Now retrieve the PDF ' 'Starting retrieval msgbox("Starting retrieval") DIM sData AS LOCAL ASCIIZ * 32000 DIM sBlock AS LOCAL STRING SQL = "SELECT ACCOUNT,DATESTR,QUALIFIER,PDFDOC FROM STMTPDFS WHERE ACCOUNT = '1101500'" lresult& = SQL_Statement(1, 1, %SQL_STMT_PREPARE,SQL) lresult& = SQL_Statement(1, 1, %SQL_STMT_EXECUTE,SQL) SQL_Fetch %NEXT_ROW sAccount$ = SQL_ResultColumnStr(1,1,1) sDatastr$ = SQL_ResultColumnStr(1,1,2) sQualifier$ = SQL_ResultColumnStr(1,1,3) SQL_DirectBindColumn(1,1,4,%SQL_LONGVARBINARY,VARPTR(sData),32000) MSGBOX(sAccount$ + $CRLF + _ sDatastr$ + $CRLF + _ sQualifier$) 'Check for unexpected errors IF SQL_ErrorPending THEN SQL_MsgBox SQL_ErrorQuickAll, %MSGBOX_OK END IF SQL_MsgBox FORMAT$(LEN(TRIM$(sData)))+" characters read.", %MSGBOX_OK
Comment