Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write a jpg to a blob... 1

Status
Not open for further replies.

thatguy

Programmer
Aug 1, 2001
283
US
Hey there folks--

So I was able to accomplish part 1 of what I need to do via this thread., but now I would like to write an image back into a Blob field in the backend table. From what little I've learned about ADO and OLEDB in the past couple hours, I have the following code so far..

Code:
LOCAL loc as ADODB.Connection, loRS as ADODB.RecordSet

loc = CREATEOBJECT('adodb.connection')
loRS = CREATEOBJECT('adodb.recordset')
loc.ConnectionString = "Provider=Advantage OLE DB Provider; Data Source=c:\localalta; ServerType=ADS_LOCAL_SERVER"
loc.Open()

loRS.Open("SELECT * FROM data23 WHERE [patient] = 'TEST000001'",loc,1,3,1)
IF loRS.Fields("patient").Value == 'TEST000001'
    loRS.Fields("picture").Value = FILETOSTR("temp.jpg")
    loRS.Update()
ELSE
    =MESSAGEBOX('not found')
ENDIF

lors.Close
loc.Close

RELEASE lors, loc

on the "Value = FILETOSTR(...)" line, I get a "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if availble. No work was done..." error.

i'm not ashamed to say that I have no idea what that means.. is this the way to write an image into a blob field? or is there some other technique i haven't found yet?

any help is appreciated.

thanks
--frank~
 
Use an ADODB.Stream to accomplish this...


...code is VB, but you should be able to make out the translation easy enough.

boyd.gif

 
Kudos to Craig! Thank you.. that was perfect.

-- frank~
 
ARGH!!!

ok, so in testing this worked just fine, however, in testing i was only dealing with one record in the recordset. it seems that when i use a SELECT statement that pulls more than one record, the recordset is not updatable.

i've used every combination of cursortype and locktype that has to do with making a read/write recordset, with no luck.

this is what i'm working with:
Code:
TRY 
   STORE '"C:\Program Files\Advanced Batch Converter\abc" "c:\temp.jpg" /dpi=(12,12) /jpeg=(25,0,0,1,0,2) /convert="c:\temp2.jpg"' TO lcexec
   oWsh = CREATEOBJECT("wscript.shell")
   loc = CREATEOBJECT('adodb.connection')
   lors = CREATEOBJECT('adodb.recordset')
   lostr = CREATEOBJECT('adodb.stream')

   loc.ConnectionString = "Provider=Advantage OLE DB Provider; Data Source=c:\localalta; ServerType=ADS_LOCAL_SERVER"
   loc.Open

   loRS.Open("SELECT * FROM data23 WHERE (not [picture] is null)",loc,2,4)
   ?lors.Supports(0x200) && movefirst, returns .t.
   ?lors.Supports(0x1008000) && update, returns .f. if there's more than 1 record in the recordset
   lostr.Type = 1
   lostr.Open 

   lors.MoveFirst
   DO WHILE !lors.EOF
      WAIT WINDOW 'rec: '+ALLTRIM(STR(lnnum))+'...' NOWAIT 
      lostr.Write(lors.Fields("picture").Value)
      lostr.SaveToFile("c:\temp.jpg",2)
		
      oWsh.Run(lcexec, 3, .T.)
		
      IF FILE("c:\temp2.jpg")
         lostr.LoadFromFile("c:\temp2.jpg")
         lors.Fields("picture").value = lostr.Read
         lors.Update()
      ELSE
         =MESSAGEBOX('temp2 not created.')
         lnnum = 25
      ENDIF

      lors.MoveNext
   ENDDO
CATCH TO oExc
   ?'lnnum: ' + ALLTRIM(STR(lnnum))
   ?ALLTRIM(STR(oExc.ErrorNo))
   ?oExc.Message
   ?oExc.LineContents
FINALLY 
   WAIT CLEAR 

   lostr.Close
   lors.Close
   loc.Close
   RELEASE lostr, lors, loc, oWsh
ENDTRY

what am i missing? do i have to use a select statement to pull each record one at a time? this is driving me nuts! any thoughts?

thanks
-- frank~
 
sorry.. in reading thru the cryptic OLE driver help doc, i found that a recordset based on a select statement which includes a memo or blob field in the where clause is not updateable. *sigh*

rtfm.. i know..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top