Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
INSERT Text into SQL Server Varbinary col using SPT
Message
De
20/03/2018 20:34:14
 
 
À
20/03/2018 19:44:33
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01658804
Message ID:
01658889
Vues:
51
>>I have a large character variable (400,000 bytes), the result of a FILETOSTR() operation. I want to INSERT this value into a SQL Server varbinary(MAX) column.
>>
>>This doesn't work:
>>lcFile = FILETOSTR( {some file} )
>>
>>lcSQL = "INSERT INTO dbo.SomeTable ( VarBinCol ) VALUES ( ?m.lcFile )"
>>
>>=SQLEXEC( MyHandle, m.lcSQL )
>>
>>* ODBC error:
>>* Error Message: [Connectivity error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Operand type clash: text is incompatible with varbinary(max)]
>>
>>I can do this with a remote view but I've already coded the routine using SPT. If there's some magic trick to make this work using SPT I'd prefer to use that.
>
>You have to cast the data on the VFP side before passing the parameter to the ODBC driver.
>
>
>m.FileContents = CAST(FILETOSTR(GETFILE()) AS Blob)
>
>? SQLEXEC(m.MyHandle, "INSERT INTO dbo.SomeTable (VarBinCol) VALUES (?m.FileContents)")
>
>
>Update: Basically, this is what Naomi said this in her post (sorry, Naomi). An additional note: to fetch back the data properly, "MapBinary" cursor property should be set to .T.

Thanks - I haven't tested your code, it may work. In the interim I found CREATEBINARY() does the job:
lcFile = CREATEBINARY( FILETOSTR( {some file} ) )
* then the rest of my original code works as expected
Your point about MapBinary is well taken. It is not necessary when INSERTing the data as above using CREATEBINARY( ). The app that reads these embedded files does have MapBinary set .T. and it reads these embedded files as expected.
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform