如何使用XML创建OCI-Lob对象? [英] How to use XML to create OCI-Lob Object?
问题描述
我有一个Oracle查询,它返回以下输出:-
I have a Oracle Query, which returns the below output:-
stdClass Object
(
[START_TIME] => 2015/01/04 06:03:07
[END_TIME] => 2015/01/04 06:27:27
[STATUS] => Error
[NODE] => DEVSERVER1
[CTRL_GROUP] => DEV_ORA
[SERVER_NUMBER] => 1001
[JOB_NAME] => Oracle Process
[STEP_INFORMATION] => OCI-Lob Object
(
[descriptor] => Resource id #165
)
)
在此,步骤信息来自于Oracle Query内部的getClobVal()函数。我通过运行以下代码获取步骤信息,提取了XML内容-
In this, the step information is coming from a getClobVal() function which present inside the Oracle Query. I have extracted the XML contents by running the below code for the step information -
$stmt = oci_parse($this->oraConn, $query);
oci_execute($stmt, OCI_DEFAULT);
$r = oci_fetch_array($stmt, OCI_RETURN_NULLS+OCI_RETURN_LOBS);
echo "<pre>";
echo htmlentities($r["STEP_INFORMATION"]);
echo "</pre>";
exit;
我低于XML-
<orastep number="9">
<ora_name>oracle_load_script</ora_name>
<ora_selection>10089</ora_selection>
<ora_selection_ind>3</ora_selection_ind>
</orastep>
我正在进行PHP单元测试,在该测试中,我需要传递与Oracle相同的输入输出,但不使用Oracle查询或连接到任何数据库。我试过使用JSON以及在PHP中创建对象来模拟输入,但是我无法表示OCI-Lob对象。
I am working on a PHP Unit test in which I need to pass the input as same as the Oracle output, but without using the Oracle query or connecting to any database. I have tried using JSON as well as creating object in PHP to mock the input but I couldn't represent the OCI-Lob object.
我想知道如何使用上面的XML如下创建OCI-Lob对象,以便我可以在输入中模拟它并在单元测试中将其传递。
I want to know how can I use the above XML to create the OCI-Lob object as below, So that I can mock that in input and pass it in unit test.
[STEP_INFORMATION] => OCI-Lob Object
(
[descriptor] => Resource id #165
)
我已经在PHP中寻找了几乎所有与OCI-Lob相关的线程,但是没有得到我想要的信息。
I have looked for almost all the threads related to OCI-Lob in PHP but didn't get the information which I am looking for.
希望你理解我的问题。任何建议,将不胜感激。
Hope you understand my question. Any suggestions on this would be appreciated.
谢谢。
推荐答案
在对此进行了大量调查之后,终于我明白了这一点。我们不能直接将XML直接转换为OCI-Lob对象。因为
After doing plenty of investigation on this, finally I have come to a point of understanding this. We can not directly convert a XML to OCI-Lob Object directly. Because
让我们想知道XMLAGG函数,在我们存储为 Val的查询中带有getClobVal(),它返回如下所示的OCI-Lob对象
Let it be like If we have any XMLAGG function with getClobVal() in side the query which we are storing as "Val" which returns OCI-Lob Object as below
$Val = OCI-Lob Object
(
[descriptor] => Resource id #130
)
下面的函数将为我们提供OCI-Lob对象[CLOB数据类型]的XML内容,我在问题中已经提到过。
the below function will give us the XML Contents of OCI-Lob Object [CLOB DataType], Which I have mentioned in the Questions.
$this->$conn = oci_connect('user', 'password', 'connectionString');
$query = "Some SELECT Query";
$stmt = oci_parse($this->oraConn, $query);
oci_execute($stmt);
while($row = oci_fetch_assoc($stmt)){
if($row['Val'] != false){
printVar($row['Val']->load());
break;
}
}
现在如果我从printVar($ row ['Val']-> load())并执行printVar($ row ['Val']),它将再次返回OCI-Lob对象。
Now If I remove load() from printVar($row['Val']->load()) and do printVar($row['Val']) it will again return me the OCI-Lob Object.
要获取OCI-Lob对象,我们确实需要Oracle Select查询,此外,我们还可以使用getClobVal()或任何函数传递XMLAttributes / Elements。但是我们无法解析XML并将其转换为OCI-Lob对象,因为它始终与Oracle数据库/服务器交互。
因此要运行PHP进行单元测试的工作是,我将XML转换为OCIMockObject,它将具有所有XML值并将其解析为函数。
So to run the PHP Unit test what I did was, I took the XML and Converted that to an OCIMockObject, Which Will have all the XML Values and parse it to the function.
成功了!
此链接对于了解有关 Oracle呼叫接口(OCI)
谢谢。
这篇关于如何使用XML创建OCI-Lob对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!