WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Binary OLE example


 Winbatch - accessing binary data with MSXML
;//  error on line - oElement.nodeTypedValue = oField.Value
;//  1628 - arrdimension - invalid array dimensionIntControl(request# , 0, 0, 0, 0 )
;//
;// stan littlefield - December 30, 2003
;////////////////////////////////////////////////////////////////


;// added work around code for signature field
;// declare the MSXML field as bin.hex then use BinaryPeekHex()
;//////////////////////////////////////////////////////////////////
#DefineSubRoutine FixXML(Field)
var = Field.Value
var = StrReplace(var, "&", "&")
var = StrReplace(var, "<", "<")
var = StrReplace(var, ">", ">")
var = StrReplace(var, '"', """)
var = StrReplace(var, "'", "'")
Return(var)
#EndSubRoutine

;// uncomment and error changes to type mismatch
IntControl(83,1,0,0,0)

cXML = StrCat( dirget(),"bank.xml")
If FileExist( cXML ) Then FileDelete( cXML )
DB = ObjectOpen("ADODB.Connection")
cConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\test\bank2000.mdb"
DB.Open(cConn)

RS= DB.Execute( "SELECT * FROM accounts WHERE AcctNumber=1234;" )

If RS.eof
   message("Cannot Continue","Query Returned No Results")
   goto end
Endif
; otherwise get the current row

oXML = ObjectOpen("MSXML2.DOMDocument.4.0")
oXML.loadXML('')
oRoot = oXML.createElement("ACCOUNT")
oXML.documentElement = oRoot
oElement = oXML.createElement("ACCTNUMBER")
oRoot.appendChild(oElement)
oElement.dataType = "i2"
oElement.nodeTypedValue = FixXML(RS.Fields("AcctNumber"))
oElement = oXML.createElement("ACCTTYPE")
oRoot.appendChild(oElement)
oElement.dataType = "string"
oElement.nodeTypedValue = FixXML(RS.Fields("AcctType"))
oElement = oXML.createElement("OPENDATE")
oRoot.appendChild(oElement)
oElement.dataType = "string"
oElement.nodeTypedValue = FixXML(RS.Fields("OpenDate"))
oElement = oXML.createElement("BALANCE")
oRoot.appendChild(oElement)
oElement.dataType = "string"
oElement.nodeTypedValue = FixXML(RS.Fields("Balance"))
oMainElement = oXML.createElement("ACCOUNTHOLDER")
oRoot.appendChild(oMainElement)
oElement = oXML.createElement("LASTNAME")
oMainElement.appendChild(oElement)
oElement.dataType = "string"
oElement.nodeTypedValue = FixXML(RS.Fields("LastName"))
oElement = oXML.createElement("FIRSTNAME")
oMainElement.appendChild(oElement)
oElement.dataType = "string"
oElement.nodeTypedValue = FixXML(RS.Fields("FirstName"))
oElement = oXML.createElement("SIGNATURE")
oRoot.appendChild(oElement)

; work around
oElement.dataType = "bin.hex"
oField = RS.Fields("Signature")
v = oField.Value
n = BinaryEodGet(v)
oElement.nodeTypedValue = BinaryPeekHex(v,0,n)
ObjectClose(oField)
; end of work around

oP     = oXML.CreateProcessingInstruction( "xml", 'version="1.0"' )
oIns   = oXML.ChildNodes(0)
oXML.InsertBefore( oP, oIns )

;// XML is saved to file
oXML.Save( cXML )
;// what you would want is to pass oXML to a UDF that would parse
;// the data as an HTML response, this would transforming the signature field
;// back to a binary file to be displayed something like
;// 


:close
ObjectClose(oMainElement)
ObjectClose(oElement)
ObjectClose(oXML)
:end
DB.Close()
ObjectClose(DB)
Exit

Article ID:   W16160
File Created: 2004:03:30:15:43:00
Last Updated: 2004:03:30:15:43:00