Sie sind auf Seite 1von 9

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

Smart questions Smart answers Smart people

Join Directory Search Tell A Friend Whitepapers Jobs Home > Forums > Programmers > DBMS Pac ages > Microso!t" #isual Fo$Pro Forum

Insert VFP LowLevelFile to SQL Image


thread%&'(%)*+,-&
Share This

stanlyn .Programmer/

%+ Feb %-"0&

Hi1 Ho2 can 3 insert an image45pg !ile into a S6l -,,&r- image !ield7 8sing #FP9sp- as the local client 2here the actual dis based image !ile is1 3 need to read the image !ile and sa:e it into a :ariable !or inclusion in a insert script that 3 create using te$tmerge4 This script 2ill be e$ecuted against a remote S6l ser:er using the s6le$ec command4 3t needs to be done purely in s6l on the ser:er side as there is only s6l ser:er running remotely4 3s there a 2ay to pass the :ariable that contains the image !ile through a con:erter .77-he$1 77-binary1 77-str1 or some other con:erter so that it can be passed into the te$tmerge script1 2hich actually supports te$t or similar7 3;m trying to a:oid using some other transport mechanism !or deli:ery o! the image !ile to the s6l ser:er1 and the processing it on the ser:er side1 by including it directly in the s6l insert statement4 3;m also using a S<= Ser:er nati:e client connection string4 Belo2 is 2hat 3;m doing444 T>?T to m4lcS6lStr te$tmerge nosho2 3nsert 3nto @8serA . @countyBidA1 @8S>CB3DA1 @8S>CBDAM>A1 @photoA1 @isBdeletedA / #A=8>S . ;EEpcFounty3d>>;1 ;EEui>>;1 ;EEun>>;1 ;EEdataB!romBimageB!ile>>;1 EEln3sDeleted>> / >ndTe$t lnS6lCesults G S<=>$ec.FonnectionHandle1 m4lcS6lStr/ Than s1 Stanley

OlafDosch e .Programmer/

%+ Feb

& of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

%0",, Hi Stanley1 First" 3mage !ields are not to be used1 they 2ill deprecate1 use a blob !ield or !ilestream4 The di!!iculty o! ho2 to use such !ields !rom :!p remains1 but stay a2ay !rom image4 Hb:iously you don;t use te$tmerge !unctionality to put in binary data e:en using Blob on the #FP side/"
!OD"

1 use parameteriIation .and this also should 2or !or 3mage !or no21

lwImage = Cast(filetostr(getpic()) as Blob) * just to show the pic works: _screen.addobject("image1","image") _screen.image1.pictureval = lwImage _screen.image1.visible = .t. TEXT to m.lcSqlStr Noshow Insert Into [User] ( [county_id], [USER_ID], [USER_NAME], [photo], [is_deleted] ) VALUES ( ?pcCountyId, ?ui, ?un, ?lwBlob, ?lnIsDeleted ) EndText lnSqlResults = SQLExec(ConnectionHandle, m.lcSqlStr) 7:ariable in an s6l string sends this :ariable seperate !rom the s6l command to s6lser:er1 2hich allo2s to JembedJ .in this sense/ binary data4 Besides that you can ha:e a static s6l command this 2ay4 3 assume ui1 un1 pcFountr3D ln3sDeleted are :ars or !ields1 you can pass them the same 2ay1 and it;s recommended1 not 5ust to ha:e a static command1 but also because o! s6l in5ection1 eg in the simplest case through single 6uotes in some o! your :ariables1 2hich 2ould brea the correctness o! the s6lK Bye1 Hla!4

stanlyn .Programmer/

%+ Feb %0"-*

>> First" 3mage !ields are not to be used1 they 2ill deprecate1 use a blob !ield or !ilestream4 Are you tal ing about S<= !ield types here7 3! so1 3 2as thing o! :arimage.ma$/ 2hich is the ne2 image !ield type that is replacing the image type4 3 ha:e read some stu!! stating that this ne2 -,,& s6l type is problematic 2ith :!p9444 3s this true7 3! you 2ere spea ing o! #FP !ield types1 then it probably 2on;t matter here as 3;m not 2riting it into a #FP table here1 only grabbing it !rom a physical harddis image45pg !ile4

>> The di!!iculty o! ho2 to use such !ields !rom :!p remains1 but stay a2ay !rom image4

+ of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

Hnce again1 #FP or S<= image type7

>> 7l2Blob1 And this 2ill pass the binary :alue to the ser:er 2here it 2ill get merged into the insert statement77 3! so1 then 2onder!ul444 Than s1 Stanley

OlafDosch e .Programmer/

%+ Feb %+"'&

3 2as only tal ing about S<= Ser:er 3mage Field type1 there is no Fo$pro 3mage Field type you could stay a2ay !rom4 Fo$pro has Leneral !or ages1 2hich is also to a:oid and since :ersion & or 9 2e ha:e !o$pro Blob !ields1 2hich S<= Ser:er also has4 3n S<= Ser:er the !ields dedicated to binary large ob5ects are blob .2ell1 that means binary large ob5ect/ or !ilestream1 the latter does store the !iles seperate on the ser:er side4 Blob is !ine1 as both s6l ser:er and !o$pro o!!er it4 Bye1 Hla!4

OlafDosch e .Programmer/

%+ Feb %)"%,

The only thing to add is1 that the blob !ield type is called :arbinary.ma$/ on the s6l ser:er side4 And yes1 it 2or s :ia 7:ariable4 Bye1 Hla!4

#r$$l%r .Programmer/

%+ Feb %9"''

While Hla!;s method is the best to use !or 2hat you ha:e stated you 2ant to do1 you should 6uestion i! that is the best 2ay to handle the !ile in!ormation4 A much better 2ay to handle large !ile types .li e image !iles1 etc4/ is to store them in a Windo2s directory some2here4 Then store the Path M Filename in the data table and not the !ile contents4 With that in!ormation stored1 an application can still access the !ile itsel! in 2hate:er manner it needs4 Lood =uc 1 JCB(Bldr

stanlyn .Programmer/

%+ Feb %-

. of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

%'"'0 Hi 5rbbldr1 >> A much better 2ay to handle large !ile types .li e image !iles1 etc4/ is to store them in a Windo2s directory some2here4 >>Then store the Path M Filename in the data table and not the !ile contents4 3;:e been doing it your 2ay .storing only the !ilename path/ in my :!p tables !or the last %- years4 Do2 that S<= is being used to replace #FP1 the arguments to eep only the pathing in!o is deminished4 Here are some o! my arguments !or changing to a Jinclude the image in the tableJ layout444 %4 3n #FP1 the -gb limit !or the 4!pt seriously limited ho2 many images could be sa:ed4 -4 =i:e bac ups are not a:ailable in #FP4 04 Security o! the image !iles1 as it is too easy !or a competitor 2ith the agreeance o! the customer to li!t the dri:e and circum:ent nt!s perms structures and ha:e all your images4 And i! you made it real easy !or them by naming them in a 2ay that ma es sense to humans1 then you can really be le!t in the cold444 Ha:ing them as part o! the database greatly adds to the security model4 3 could do things li e adding an additional header to the image that 2ould brea the image unless remo:ed prior to using it to populate an image ob5ect444 '4 Static Bac ups 2ould be e$tremely !aster in S<= as the system 3NH in #FP is really ta$ed by the millions o! !ile openNreadNclose operations 2hen bac ing up indi:idual image !iles as 2e currently do in #FP4 Furrently1 to bac up -4) million ), b images on an 3* raid + system1 it ta es more that -' hours to do4 3t also re6uires human inter:ention at times1 so the process has to be Jhand heldJ1 due to system prompts i! done :ia 2indo2s e$plorer444 3t ta es bet2een %(- hours to do it :ia Acronis 2here sector reading is occuring and the massi:e iNo o! indi:idual !iles are a:oided4 3 understand .and not tested yet/ that S<= static bac up speed 2ould be similar to Acronis;s speed4 +4 3;m changing !rom a local model to a remote model !or 2eb access1 and someho2 3 belie:e it to be less trouble i! the image is contained 2ithin the database 4 )4 S<= is supposedly stable enough444

3! you see any thing here that is 6uestionable1 or 3 should loo at !urther1 then please ad:ise4 3 ha:e not made the !inal decisions yet1 but ha:e been 2eighing the pros and cons as best as 3 can 2hen comparing to the e$periences o! the last %- years o! doing this4 Fan you thing o! other pros and cons7 Please ad:ise444 Than s1 Stanley

#r$$l%r .Programmer/

%+ Feb %%+"'-

Stanley ( Oou suggested in P% abo:e sa:ing the image !ile data in the Memo .!pt/ !ield7 &'SOL()"L* +O) , Sa:e the Path M Filename in a Fharacter !ield and then 2hen needed ha:e your application go get the !ile !rom the appropriate Windo2s directory and use it4 Despite no longer ha:ing the -LB data table limitation 2ithin S<= Ser:er data tables1 you still 2ill most li ely e$perience table B=HAT 2ith the entire contents o! the image !ile 2ithin the table itsel!4 And that B=HAT can diminish S<= Ser:er response times in returning data1 S<= Ser:er bac up times1 etc4 And1 since the contents o! an image !iles themsel:es are not li ely to be :ery dynamic the bac up issue seems moot4 That !unctionality should not be handled 2ithin #FP any2ay1 but 2ith a more !le$ible ;real; bac up utility running concurrently such as Acronis1 etc4 2here ;=i:e; bac ups o! the !iles themsel:es can be con!igured and scheduled4 Hne o! my clients is doing ;=i:e !ile bac ups; o! each o! their ) ser:ers e:ery %+ minutes ( e:en to an o!!(site location4 Admittedly security could be a concern1 but it can be addressed by the Det2or Administrator limiting user rights to the image !ile storage

/ of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

directory4 So1 2hile the issues you list are :alid1 3;d still recommend staying 2ith your pre:ious model1 but addressing those :arious issues in another .in my opinion ( better/ manner4 Maybe other gurus 2ill ha:e their o2n :ie2points to share4 Lood =uc 1 JCB(Bldr

stanlyn .Programmer/

%+ Feb %%)"0&

Hi Hla!1 2hen 3 tried using the suggestions in these 0 2ays1 3 get 0 di!!erent errors444 Any ideas7

>CCHC run%444 3n the te$tmerge script 3 ha:e ;EEA==TC3M.8P=HAD4Fhr99Str,+/>>;1 ;EE7lm3mageData>>;1 EEln3sDeleted>> 2hich produces this 2hen e:aluated444 @3MAL>%A G ;;1 2hen e:aluated444 QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ >CCHC run-444 3n the te$tmerge script 3 ha:e ;EEA==TC3M.8P=HAD4Fhr99Str,+/>>;1 EE7lm3mageData>>1 EEln3sDeleted>> 2hich produces this 2hen e:aluated444 @S>FB3DA G ;;1 @3MAL>%A G 1 @isBdeletedA G , QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ >CCHC run0444 3n the te$tmerge script 3 ha:e ;EEA==TC3M.8P=HAD4Fhr99Str,+/>>;1 7lm3mageData1 EEln3sDeleted>> 2hich produces this 2hen e:aluated444 @S>FB3DA G ;;1 @3MAL>%A G 7lm3mageData1 @isBdeletedA G ,

OlafDosch e .Programmer/

%+

) of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

Feb %%&"%* Third is correct1 the result is 7:ariable1 there is no te$tmerge nor print o! the image data1 this reamins in the :ariable1 S<=>?>F./ then sends BHTH the s6l command string ADD the data 2ithin the :ariables4 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %,"'9

The third item as 2ell as the other - items produces a E , result !rom the s6le$ec command 2hich is some sort o! an error444 lnS6lCesults G S<=>$ec.FonnectionHandle1 m4lcS6lStr/ 3! lnS6lCesults E , So1 2onder 2hat is ma ing this !ail7 3! 3 remo:e the line @3MAL>%A G 7lm3mageData1 it does not !ail444 Also note that my :ariable Jlm3mageDataJ contains the data !rom the image by using the !ile lo2 le:el routines in 2hich 3 am also sa:ing into a #FP blob !ield4 That part is 2or ing HR no2 and !or the past %- years4 Would the image !ormat be o! any concern1 o! 2ould this routine 5ust stu!! the binary :ariable contents into the s6l !ield 2ithout regard to the image !ile !ormat .45pg1 4bmp1 4eps1 4$yI as in non(standard image !ormats/7 Ho2 does one traceNtroubleshoot this1 as it is !ailing on the s6l side7

OlafDosch e .Programmer/

%) Feb %-"'9

8se A>CCHC a!ter S<=>$ec returns E, to get more error in!ormation4 3s the :ariable still in scope 2hen you e$ecute the s6l7 >g setting a local :ariable1 then calling a method calling s6le$ec./ 2ould error on that1 o! course4 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %%-"'0

Oes the :ariable is in scope and contains image data4 3;m getting an error message" JFonnecti:ity error4 @Microso!t HDBF S<= Ser:er Dri:erA@S<= Ser:erAHperand type clash" te$t is incompatible 2ith :arbinary.ma$/J 3;m going to s2itch the s6l !ield type to the depreciated type o! JimageJ and see i! that 2or s4

stanlyn .Programmer/

%) Feb %%-"'9

' of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

HR1 same error e$cept instead o! incompatibility 2ith :arbinary.ma$/ its image444 Any other ideas7

OlafDosch e .Programmer/

%) Feb %%0"'&

What :ersion o! s6l ser:er are you using and 2hy did you s2itch !rom image to te$t and bac to image1 2hen you should s2itch to blob a a :arbinary.ma$/7 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %%'",0

-,,&r>> 2hy did you s2itch !rom image to te$t and bac to image 3 did not444 3 initially tried type J:arbinary.ma$/J and a!ter the error claims incompatibility1 3 s2itched to type JimageJ 2hich also !ailed 2ith incompatibility4 3 ha:e ne:er tried te$t or :ariation o! te$t4 Stanley

OlafDosch e .Programmer/

%) Feb %%'"--

Passing 7l2Blob 2or ed !or me 2ith s6l-,,&r- using the JS<= Ser:erJ Dri:er :ersion -,,,4&+4%%0-4,, !rom %'4,'4-,,&4 Oou may try to update your HDBF dri:er or s2itch to another one1 eg JS<= Ser:er Dati:e Flient %,4,J instead o! JS<= Ser:erJ4 Bye1 Hla!4

OlafDosch e .Programmer/

%) Feb %%'"-*

3 thin you use an older dri:er and that dri:er transports the !o$pro blob :ariable as image or te$t1 2hich is causing the trouble ser:er side4 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %%'"')

3;m using the e$act odbc dri:er as you444

OlafDosch e .Programmer/

%)

( of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

Feb %%+",) 3s your database running in some compatibility mode1 perhaps7 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %%+"-,

3;m getting around the pre: error by !irst issuing l23mage G Fast.lm3mageData as Blob/ 3 do not no2 i! this is producing a :alid image on the s6l side4 Hn the #FP side issuing Ceplace 8P=HAD4Memo,0 With lm3mageData creates and stores a per!ect image in the :!p table4 Memo0 is :!p type M.'/ 2hich appears to be memo te$t444 3! M.'/ is memo te$t1 2hat does the type./ !unction return !or memo binary7 3! you don;t no21 3 can create a test !or it1 as 3 did not see it listed in the types and :artypes help sections4 So1 i! 3 cast this as a blob1 2ould 3 consider this the actual !iles bytes 2ritten to the table as a nati:e image !ile7 And 2ould there need any con:ersions needed 2hen binding to an image control7

OlafDosch e .Programmer/

%) Feb %%+"'&

Quote3;m getting around the pre: error by !irst issuing l23mage G Fast.lm3mageData as Blob/

That;s 2hat my sample code included1 see !irst ans2er" l23mage G Fast.!iletostr.getpic.// as Blob/ Memo.binary/ is the same as M nocptran4 The type./ !unction has no di!!erent letter !or that4 A Blob !ield on #FP side is1 2ell JblobJ or W1 that;s 2hy 3 named the :ariable lw3mage4 >:en in a codepage %-+- db! memo !ields don;t necessarily translate binary data you put in there4 Maybe because they are stored in the seperate !pt !ile1 3 don;t no21 but don;t trust them to store the binary data unchganged1 use M nocptran or W !ields on the !o$pro side4 Bye1 Hla!4

OlafDosch e .Programmer/

%) Feb %%)"-+

Actually it;s 6uite simple" db!s ha:e a codepage1 and that typically is the same as the current codepage1 so memo !ields normally act the same 2ay as memo.binary/ or nocptran .no codepage translation/ !ields1 as there is no code page di!!erence to o:ercome4

, of -

./.&/+*&/ .:/& PM

Microsoft: Visual FoxPro - Insert VFP LowLevelFile to SQ...

http://www.te -tips.co!/viewthrea".cf!#$i"%&'()*+,

Still in regard to the outside 2orld1 eg spt1 it ma es a huge di!!erence1 i! you trans!er a :ariable interpreted as large te$t or a :ariable casted as blob4 Bye1 Hla!4

stanlyn .Programmer/

%) Feb %%&"0,

Than s Hla! !or all you;:e done4 3 ha:e it 2or ing no24 3 also con!irmed that the actual image !ile siIe is e6ual to the casted :ariable as blob !or s6l1 2hich is also e6ual to :!p;s lo2 le:el read to a te$t memo !ield444 All 0 siIes are identical444 Than s again1 Stanley

0exus )
1oo1le.co!/nexus The new phone fro! 2oo1le3 !a"e for the !o!ents that !atter. 4u5 now.

Join S 3ndeed Jobs S Ad:ertise S About 8s S Fontact 8s S Site Policies


Fopyright T %99&(-,%' Tecumseh Lroup1 3nc4 All rights reser:ed4 8nauthoriIed reproduction or lin ing !orbidden 2ithout e$press 2ritten permission4

- of -

./.&/+*&/ .:/& PM

Das könnte Ihnen auch gefallen