简体   繁体   English

如何从QTP中的VBScript中的db2数据库检索xml列

[英]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. 我正在尝试从DB2数据库中的表中检索XML列。 Using the code below, I can retrieve any column that does not have xml as the data-type: 使用下面的代码,我可以检索没有xml作为数据类型的任何列:

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". 当数据是xml数据类型时,“ data = rs.Fields(0)”行将引发“未指定的错误”。 I thought since the recordset returns an XML object, I need to assign it to a DOM object like this: 我以为,由于记录集返回XML对象,因此需要将其分配给这样的DOM对象:

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. 但这仍然行不通,执行保存行时QTP抛出“未指定的错误”。

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. 根据DB2-.NET 数据类型 ,DB2Xml映射到Byte()/ Blob。 So perhaps you can deal with your XML field as Mr. Gates deals with pictures , eg: 因此,就像盖茨先生处理图片一样也许您可以处理XML字段,例如:

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; PS:您的rs.Save xDOM, adPersistXML是完全错误的。 .Save saves the whole recordset to a file specified as first parameter. .Save将整个记录集保存到指定为第一个参数的文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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