Sign in to follow this  
Followers 0
craigey1

Binary to Jpg

7 posts in this topic

Hi,

I'm trying to export BLOB data from my oracle database & export it to a jpg file.

So far I can connect to the DB & Display (some of) the blob in a msgbox. How can I export that variable value to a jpg file?

I've got the Auto3Lib installed & thought I could use the GDIP_ImageSaveToFileEx function in A3LGDIPlus.au3, but haven't had any luck.

Any help would be apreciated.

Thanks

Share this post


Link to post
Share on other sites



Post related code snippet ...

I've posted the whole lot. Please note there are a lot of comments etc, where I have been trying to get this to work. I've so far been successfull in outputting normal records (ie names etc) to txt files or within a jpg file when view with wordpad. This just doesn't seem to read the BLOB's.

#include <GUIConstants.au3>

Dim $oMyError

; Initializes COM handler
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

$ado = ObjCreate( "ADODB.Connection" )   ; Create a COM ADODB Object  with the Beta version

With $ado
   ; 'Set data source - for OLEDB this is a tns alias, for ODBC it can be 'either a tns alias or a DSN.
   ; If "provider" is used this means that the ODBC connections is used via DSN. 
   ; if Driver is used = "Driver={Microsoft ODBC for Oracle};Server=TNSnames_ora;Uid=demo;Pwd=demo;" then this is a DSN Less connector
   ; More Info for Oracle MS KB Q193332
   .ConnectionString =("Provider='OraOLEDB.Oracle';Data Source='XXXXXX';User Id='xxxxxx';Password='xxxxxx';") 

.Open
EndWith

$adors = ObjCreate( "ADODB.RecordSet" )   ; Create a Record Set to handles SQL Records

#Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=Yes, Mandatory
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("SQL Query","Please Enter The SQL Query to use.","Select content From images"," M","-1","-1","-1","-1") 
Select
    Case @Error = 0;OK - The string returned is valid

    Case @Error = 1;The Cancel button was pushed
Exit
    Case @Error = 3;The InputBox failed to open
Exit
EndSelect
#EndRegion --- CodeWizard generated code End ---


With $adors
        .ActiveConnection = $ado
       ;.CursorLocation = "adUseClient"
       ;.LockType = "adLockReadOnly"; Set ODBC connection read only
;       .Source = "select camerastatusdata from camerastatus"
        .Source =  $sInputBoxAnswer
        .Open 
EndWith
$j=0
While not $adors.EOF
    For $i = 0 To $adors.Fields.Count - 1

;       ConsoleWrite( $adors.Fields( $i ).Value & @TAB )   ; Columns in the AutoIt console use Column Name or Index
        msgbox(1,"test",$adors.Fields($i).Value)
;       msgbox(1,"test",Hex($adors.Fields($i).Value))
;       msgbox(1,"test",BinaryString($adors.Fields($i).Value))
        
;msgbox(0,"",$i)
;msgbox(0,"",$j)
;msgbox(0,"",$adors.Fields($i).Value)

;$file = FileOpen(@ScriptDir & "\test"&$j&".jpg", 1)
;$filename = @ScriptDir & "\test"&$j&".jpg"
$file = FileOpen("C:\test"&$j&".jpg", 1)
$filename = "C:\test"&$j&".jpg"

msgbox(0,"",$filename)
FileWrite($filename, $adors.Fields($i).Value)
;FileWrite($file, @CRLF)
;FileWrite($filename, $filename)
FileClose($filename)

;RunWait("rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen" &$filename)
RunWait("C:\windows\system32\mspaint.exe "&$filename)
$j=$j+1
Next
;       ConsoleWrite(@CR)
    $adors.MoveNext                                            ; Go to the next record
WEnd


; This COM error Handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  $iMsgBoxAnswer = Msgbox(1,"AutoItCOM Test","We intercepted a COM Error !"    & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
  Select
    Case $iMsgBoxAnswer = 1;OK

    Case $iMsgBoxAnswer = 2;Cancel
Exit
EndSelect
Endfunc

Share this post


Link to post
Share on other sites

Try

$file = FileOpen("C:\test"&$j&".jpg", 2+16)
FileWrite($file, $adors.Fields($i).Value)
FileClose($file)

or

$file = FileOpen("C:\test"&$j&".jpg", 2+16)
FileWrite($file, Binary($adors.Fields($i).Value))
FileClose($file)

Share this post


Link to post
Share on other sites

If I use the 2+16 the files are not even created.

Binary isn't valid, but binarystring is. This returns null. It just appears that once binary is encountered in the Recordset the value is set to null. All the jpgs appear as 0KB files.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

I have used almost the same code for read data froma Oracle BLOB field, but I'm not receiving anything... I tryed to store it to a variable (I tested all type later and always got false), to display in a Message Box, sent to console, file, etc... I always got an empty value from the recordset!

Edited by EdwardTFN

Share this post


Link to post
Share on other sites

I have the same problem, does somebody already have a solution?

CODE
$objconn =ObjCreate("ADODB.Connection")

$objconn.Provider="MSDASQL"

$dsn = "DSN=Reiko"

$objconn.Open ($dsn)

$test = "30799"

$SQLexecute = ObjCreate( "ADODB.RecordSet" )

$SQLstatement = "SELECT bild FROM docbilder WHERE reisepktnr = '"&$test&"'"

$SQLexecute.Open($SQLstatement , $objconn )

$file = FileOpen(@ScriptDir & "\Test2.png", 17)

FileWrite ($file,Binary ($SQLexecute.Fields("bild").value))

FileClose($file)

I will read from a BLOB field try a lot of diverent things, but i always get 0 Byte!

But wen i try:

CODE
$objconn =ObjCreate("ADODB.Connection")

$objconn.Provider="MSDASQL"

$dsn = "DSN=Reiko"

$objconn.Open ($dsn)

$test = "30799"

$SQLexecute = ObjCreate( "ADODB.RecordSet" )

$SQLstatement = "SELECT bild FROM docbilder WHERE reisepktnr = '"&$test&"'"

$SQLexecute.Open($SQLstatement , $objconn )

$SQLexecute.Save(@ScriptDir & "\GDIPlus_Image4.png")

I get a the File, but there are beside the data one more mixes of other information in the file. :-(

I despair.. :-(

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0