Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Storing An Image In A SQL Table
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01234808
Message ID:
01245918
Views:
35
I'm back on this again. I have no idea why this isn't working any more.

The SQL column 'ImageFile' is of type Image. I created a VFP DB, then a remote view
to the SQL table, and I set the ImageFile datatype to Blob in the VFP DB.

I then use this code to load the images:
CLOSE DATABASES ALL
MODIFY DATABASE ImageLoad.DBC NOWAIT

IF USED("v_GenImages")
	USE IN v_GenImages
ENDIF

SELECT 0
USE v_GenImages
DELETE FROM v_GenImages

nTotImages = ADIR(aImages, "Images\*.png")

FOR nImage = 1 TO nTotImages

  cImageName = LOWER(SYS(5) + SYS(2003) + "\Images\" + aImages[nImage, 1])

  INSERT INTO v_GenImages;
    (imagesize, imagecode);
    VALUES;
    (16, LOWER(JUSTSTEM(cImageName)))

  REPLACE ImageFile WITH FILETOSTR(cImageName)
	
ENDFOR
That part worked fine. This next part errors on the STRTOFILE() with "Function argument value, type, or count is invalid."
nHandle = SQLSTRINGCONNECT(cConnString)

IF nHandle > -1

  nResult = SQLEXEC(nHandle, "select * from genimages", "Images")
	
  IF nResult > -1

    SELECT Images
    SCAN
	
      cFileName = cDestDir + ALLTRIM(Images.ImageCode) + ".png"

      =STRTOFILE(ImageFile , JUSTFNAME(cFileName))
		
    ENDSCAN
		
  ELSE
    ? "Error"
  ENDIF
	
  SQLDISCONNECT(nHandle)

ELSE
  ? "Not connected"
ENDIF
This was all working the last time I posted on this. Now I can't get the images back outta
the SQL table.











>You should map SQL Image column to VFP blob data type in the remote view.
>Check also CURSORSETPROP("MapBinary") in the help.
>
>>It is an Image file in SQL. It appears to be working with this. Should I make the SQL column a 'blob'?
>>
>>
>>
>>CLOSE DATABASES ALL
>>MODIFY DATABASE ImageLoad.DBC NOWAIT
>>
>>cImageFile = "graphics\test_image.bmp"
>>
>>IF USED("v_ImageTest")
>>	USE IN v_ImageTest
>>ENDIF
>>
>>SELECT 0
>>USE v_ImageTest
>>
>>FOR nRecord = 1 TO 1000
>>
>>	WAIT WINDOW "Adding record " + TRANSFORM(nRecord) + " of 1000" NOWAIT
>>
>>	cImageName = SYS(2015)
>>
>>	INSERT INTO v_ImageTest;
>>		(ImageName);
>>		VALUES;
>>		(cImageName)
>>
>>	APPEND MEMO ImageFile FROM &cImageFile OVERWRITE
>>
>>ENDFOR
>>
>>RETURN
>>
>>
>>
>>Now I want to pull the images out, and I'm trying:
>>
>>
>>nHandle = SQLSTRINGCONNECT(cConnString)
>>
>>IF nHandle > -1
>>SET STEP ON
>>	nResult = SQLEXEC(nHandle, "select * from ImageTest", "Images")
>>	
>>	IF nResult > -1
>>	
>>		cImageFile = STRTOFILE(Images.ImageFile, cDestDir + Images.ImageName + ".bmp")
>>		
>>	ELSE
>>		? "Error"
>>	ENDIF
>>	
>>	SQLDISCONNECT(nHandle)
>>
>>ELSE
>>	? "Not connected"
>>ENDIF
>>
>>
>>When I get the resulting cursor back, the Gen field appears empty. When I attempt to open the Gen field,
>>I get "OLE object is invalid or corrupted."
>>
>>What in the world am I doing wrong here?
>>
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform