Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert VFP Memo field to SQL Server Image Field
Message
From
11/07/2006 14:36:51
 
 
To
11/07/2006 12:32:29
Stephen Hunt
Admit Computer Services Inc.
Farmingdale, New York, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01135374
Message ID:
01135471
Views:
10
>Ok I put this code in but now on the SQLEXEC insert I get an error message as follows "Arithmetic overflow error converting numeric to data type varchar"
>
>Thanks Again !

Stephen -

Here is what I use to store pictures in SQL server (adapted from code I got from Rod Paddock)

SQLFileImageWrite()
LPARA tcFileName

LOCAL lcTempFile,lnHandle,lnResult

lcTempFile = thisapp.oDataHandler.MakeTempFileName() + ".dbf"
THIS.EraseFile(lcTempFile)

* create temporary buffer table
SELECT 0
CREATE TABLE (lcTempFile) FREE (PICTURE M)

* Place binary data from file into memo
APPEND BLANK
APPEND MEMO PICTURE FROM (tcFileName) OVERWRITE
USE

* change memo field type to general to match to image type on SQL Server
lnHandle = FOPEN(lcTempFile,12)
FSEEK(lnHandle,43)
FWRITE(lnHandle,'G')
FCLOSE(lnHandle)

lcEditUser = thisapp.oSecurityHandler.GetUserName()
ltEditTime = DATETIME()

* write data to SQL Server
USE (lcTempFile) ALIAS csrFile

* Check if a record already exists for this file
*lcSql = [SELECT cMemberID FROM MemberPhotos WHERE cMemberID = ?tcMemberID AND cSiteID = ?tcSiteID]
lnResult = SQLEXEC(this.snHandle,this.scSqlFind,"csrFileExists")
IF lnResult <> SQL_ERROR 
	IF RECCOUNT("csrFileExists") = 0
                lcSql = [insert into MemberPhotos VALUES ] +;
			[(?tcMemberID,?tcSiteID,?csrFile.Picture,?lcEditUser,?ltEditTime,?lcEditUser,?ltEditTime)]
	ELSE
                lcSql =[UPDATE MemberPhotos SET Picture = ?csrFile.Picture, ]+;
			[cUpdateUser = ?lcEditUser,tUpdateDate = ?ltEditTime ] +;
			[WHERE cMemberID = ?tcMemberID AND cSiteID = ?tcSiteID]
	ENDIF
	lnResult = SQLExec(this.snHandle,m.lcSQL)
	ASSERT lnResult <> SQL_ERROR

	USE IN csrFileExists
ENDIF

USE IN csrFile

RETURN lnResult <> SQL_ERROR
SQLFileImageRead()
LOCAL lcTempFile
LOCAL lnHandle,lnResult
LOCAL lcFileName

lcTempFile = thisapp.oDataHandler.MakeTempFileName() + ".dbf"
THIS.EraseFile(lcTempFile)

lcFileName = thisapp.oDataHandler.scViewPath + ALLTRIM(thisapp.GetNetWorkName()) + this.scFileExt && ".jpg"
IF FILE(lcFileName)
	ERASE (lcFileName)
ENDIF


* take data from SQL server
lcSQL = [SELECT picture as FileImage FROM MemberPhotos WHERE cMemberID = ?tcMemberID AND cSiteID = ?tcSiteID]
lnResult = SQLExec(this.snHandle,lcSql,"csrFileImage")

IF lnResult <> SQL_ERROR
	* We have a general field in 'csrPhoto' cursor because image type on SQL Server
	* mapped to general field in VFP.

	* save data to temporary table
	SELECT csrFileImage
	COPY TO (lcTempFile)
	USE

	* change general field type to memo
	lnHandle = FOPEN(lcTempFile,12)
	FSEEK(lnHandle,43)
	FWRITE(lnHandle,'M')
	FCLOSE(lnHandle)

	* save data from memo field into file
	USE (lcTempFile) ALIAS tempFileImage
	STRTOFILE(tempFileImage.FileImage,lcFileName)

	USE IN tempFileImage
	THIS.EraseFile(lcTempFile)
ENDIF

RETURN lcFileName
HTH!
Carsten M. Thode
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform