Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
General field
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Divers
Thread ID:
00427023
Message ID:
00427217
Vues:
19
Hi!

>Yes, I would be interested. I have no choice but to try to get the data out of SQL Server. I need to be able to at least pull the pictures up via modify general then copy the file to the clipboard. From there I should be able to do a strtofile(). If I can get to the data without the errormessages I'm currently getting, I'll be in good shape.
>
>Post your code, I'll use what I can.

Its exactly what I made!
Following is test code. The main idea is following.
Use memo fields to store data. However, you cannot use text type on SQL server because it corrups binary data (there are special 16-bit binary codes that sql server or ODBC extracts from text field type). So we have only one way - to use image type. To use it, we should use general field in VFP, otherwise we cannot map it (will get errors). So we have a problem now - we can store it, but need to map Memo type in VFP to image type on SQL server. This might be very complex when you will not use very interesting thing - the way VFP stores memo fields and general fields is the same - both use pointer into fpt file. What I did is just used low-level file functions to change field type from memo to general and vise versa just by replacing one byte in dbf file. The code below shows example of how to write binary data from file to SQL server image type field, and than how to read these data and put them back into the file. This code is the most reliable I found.
NOTE: assure you use temporary table in samples with 1 field (or memo field with binary data is FIRST field in table).
<b>* WRITE part</b>
lcFileName = "F:\TWAIN20.ZIP" && this file got corrupted when use text field on SQL server
* create temporary buffer table
if file("F:\ttt.dbf")
  erase ("F:\ttt.dbf")
endif
if file("F:\ttt.fpt")
  erase ("F:\ttt.fpt")
endif
select 0
create table "F:\ttt" FREE (mData M)
* take binary data from file into memo
select ttt
append blank
append memo mData from (lcFileName) overwrite
use
* change memo field type to general to match to image type on SQL Server
ll = fopen("F:\ttt.dbf",12)
fseek(ll,43)
fwrite(ll,'G')
fclose(ll)
* write data to SQL Server
use F:\ttt alias __DATA
lcSQL = 'insert into test values (?__DATA.mData)'
if !(oApp.oServer.RunQuery(m.lcSQL))
  messagebox(oApp.oServer.cError)
endif
use in __DATA


<b>* READ part</b>
* take data from SQL server
lcSQL = 'select mData from test'
if !oApp.oServer.RunQuery(m.lcSQL,"TT")
  messagebox(oApp.oServer.cError)
endif
*** here we have general field in 'TT' cursor because image type on SQL Server.
* save data to temporary table
select TT
if file("F:\ttt.dbf")
  erase ("F:\ttt.dbf")
endif
if file("F:\ttt.fpt")
  erase ("F:\ttt.fpt")
endif
copy to "F:\ttt"
use

* change general field type to memo
ll = fopen("F:\ttt.dbf",12)
fseek(ll,43)
fwrite(ll,'M')
fclose(ll)

* save dtaa from memo field into file
use "F:\ttt" alias TT
lcFileName = "F:\qwerty.zip" && test file name with result from SQL Server
if file(lcFileName)
  erase (lcFileName)
endif
local lH
lH = FCREATE(lcFileName)
FWRITE(lH,TT.mData)
FCLOSE(lH)
use in TT
* here you can compare "F:\qwerty.zip" and "F:\TWAIN20.ZIP" - they should match
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform