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:
01245939
Views:
38
>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.

What is the error?
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
    AERROR(laError)
    ? "Error " +laError[1,2]
  ENDIF
  SQLDISCONNECT(nHandle)

ELSE
   AERROR(laError)
  ? "Not connected "+laError[1,2]
ENDIF
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform