简体   繁体   中英

How to retrieve an xml column from a db2 database in VBScript in QTP

I'm trying to retrieve an XML column from a table in a DB2 database. Using the code below, I can retrieve any column that does not have xml as the data-type:

query = "some query"  
strConn = "my connection string"  
set dbConn = CreateObject("ADODB.Connection")  
set rs = CreateObject("ADODB.RecordSet")  
dbConn.Open strConn  
rs.Open query, dbConn  

rs.MoveFirst  
While Not rs.EOF  
 data = rs.Fields(0)  
 rs.MoveNext  
Wend  
dbConn.Close  

When the data is an xml data-type, the line "data = rs.Fields(0)" throws an "unspecified error". I thought since the recordset returns an XML object, I need to assign it to a DOM object like this:

Set xDOM = CreateObject("Microsoft.XMLDOM")  
rs.Save xDOM, adPersistXML  

but this still doesn't work, QTP throws an "unspecified error" when executing the save line.

I googled for an answer but couldn't find anything that would help. Is there anyone out there who has successfully done this?

Thanks for reading my question.

According to DB2 - .NET datatypes , DB2Xml maps to Byte()/Blob. So perhaps you can deal with your XML field as Mr. Gates deals with pictures , eg:

Set cn = New ADODB.Connection   ---> CreateObject("ADODB.Connection")
cn.Open "DB2 Connection String"

Set rs = New ADODB.Recordset    ---> CreateObject("ADODB.Recordset")
rs.Open "Your SQL", cn, adOpenKeyset, adLockOptimistic ---> Const defines needed

Set mstream = New ADODB.Stream ---> CreateObject("ADODB.Stream")
mstream.Type = adTypeBinary ---> Const define needed
mstream.Open
mstream.Write rs.Fields("Your XML field").Value
mstream.SaveToFile "fullfilespec.xml", adSaveCreateOverWrite ---> Const define needed

rs.Close
cn.Close

(obviously untested aircode)

PS Your rs.Save xDOM, adPersistXML is completely wrong; .Save saves the whole recordset to a file specified as first parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM