OracleXmlQueryPropertiesオブジェクトは、XmlCommandTypeプロパティがQueryである場合に、OracleCommandクラスにより使用されるXMLプロパティを表します。
クラスの継承
System.Object
System.OracleXmlQueryProperties
宣言
public sealed class OracleXmlQueryProperties : ICloneable
スレッド安全性
パブリック静的メソッドはスレッドセーフですが、インスタンス・メソッドではスレッド安全性は保証されません。
備考
OracleXmlQueryPropertiesは、OracleCommandクラスのXmlQueryPropertiesプロパティを使用してアクセスおよび変更できます。各OracleCommandオブジェクトには、XmlQueryPropertiesプロパティに、OracleXmlQueryPropertiesクラスの独自のインスタンスが含まれます。
OracleXmlQueryPropertiesの新規インスタンスを取得するには、デフォルトのコンストラクタを使用します。OracleXmlQueryProperties.Clone()メソッドを使用して、OracleXmlQueryPropertiesインスタンスのコピーを取得します。
例
この例では、リレーショナル・データがXMLで取得されます。
// C#
using System;
using System.IO;
using System.Data;
using System.Xml;
using System.Text;
using Oracle.DataAccess.Client;
class OracleXmlQueryPropertiesSample
{
static void Main()
{
int rows = 0;
StreamReader sr = null;
// Define the XSL document for doing the transform.
string xslstr = "<?xml version='1.0'?>\n" +
"<xsl:stylesheet version=\"1.0\"" +
" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n" +
" <xsl:output encoding=\"utf-8\"/>\n" +
" <xsl:template match=\"/\">\n" +
" <EMPLOYEES>\n" +
" <xsl:apply-templates select=\"ROWSET\"/>\n" +
" </EMPLOYEES>\n" +
" </xsl:template>\n" +
" <xsl:template match=\"ROWSET\">\n" +
" <xsl:apply-templates select=\"ROW\"/>\n" +
" </xsl:template>\n" +
" <xsl:template match=\"ROW\">\n" +
" <EMPLOYEE>\n" +
" <EMPLOYEE_ID>\n" +
" <xsl:apply-templates select=\"EMPNO\"/>\n" +
" </EMPLOYEE_ID>\n" +
" <EMPLOYEE_NAME>\n" +
" <xsl:apply-templates select=\"ENAME\"/>\n" +
" </EMPLOYEE_NAME>\n" +
" <HIRE_DATE>\n" +
" <xsl:apply-templates select=\"HIREDATE\"/>\n" +
" </HIRE_DATE>\n" +
" <JOB_TITLE>\n" +
" <xsl:apply-templates select=\"JOB\"/>\n" +
" </JOB_TITLE>\n" +
" </EMPLOYEE>\n" +
" </xsl:template>\n" +
"</xsl:stylesheet>\n";
// Create the connection.
string constr = "User Id=scott;Password=tiger;Data Source=oracle";
OracleConnection con = new OracleConnection(constr);
con.Open();
// Set the date, and timestamp formats for Oracle 9i Release 2, or later.
// This is just needed for queries.
if (!con.ServerVersion.StartsWith("9.0") &&
!con.ServerVersion.StartsWith("8.1"))
{
OracleGlobalization sessionParams = con.GetSessionInfo();
sessionParams.DateFormat = "YYYY-MM-DD\"T\"HH24:MI:SS";
sessionParams.TimeStampFormat = "YYYY-MM-DD\"T\"HH24:MI:SS.FF3";
sessionParams.TimeStampTZFormat = "YYYY-MM-DD\"T\"HH24:MI:SS.FF3";
con.SetSessionInfo(sessionParams);
}
// Create the command.
OracleCommand cmd = new OracleCommand("", con);
// Set the XML command type to query.
cmd.XmlCommandType = OracleXmlCommandType.Query;
// Set the SQL query.
cmd.CommandText = "select * from emp e where e.empno = :empno";
// Set command properties that affect XML query behaviour.
cmd.BindByName = true;
// Bind values to the parameters in the SQL query.
Int32 empNum = 7369;
cmd.Parameters.Add("empno", OracleDbType.Int32, empNum,
ParameterDirection.Input);
// Set the XML query properties.
cmd.XmlQueryProperties.MaxRows = 1;
cmd.XmlQueryProperties.RootTag = "ROWSET";
cmd.XmlQueryProperties.RowTag = "ROW";
cmd.XmlQueryProperties.Xslt = xslstr;
// Test query execution without returning a result.
Console.WriteLine("SQL query: select * from emp e where e.empno = 7369");
Console.WriteLine("Maximum rows: all rows (-1)");
Console.WriteLine("Return Value from OracleCommand.ExecuteNonQuery():");
rows = cmd.ExecuteNonQuery();
Console.WriteLine(rows);
Console.WriteLine("\n");
// Get the XML document as an XmlReader.
Console.WriteLine("SQL query: select * from emp e where e.empno = 7369");
Console.WriteLine("Maximum rows: all rows (-1)");
Console.WriteLine("XML Document from OracleCommand.ExecuteXmlReader():");
XmlReader xmlReader = cmd.ExecuteXmlReader();
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.PreserveWhitespace = true;
xmlDocument.Load(xmlReader);
Console.WriteLine(xmlDocument.OuterXml);
Console.WriteLine("\n");
// Change the SQL query, and set the maximum number of rows to 2.
cmd.CommandText = "select * from emp e";
cmd.Parameters.Clear();
cmd.XmlQueryProperties.MaxRows = 2;
// Get the XML document as a Stream.
Console.WriteLine("SQL query: select * from emp e");
Console.WriteLine("Maximum rows: 2");
Console.WriteLine("XML Document from OracleCommand.ExecuteStream():");
Stream stream = cmd.ExecuteStream();
sr = new StreamReader(stream, Encoding.Unicode);
Console.WriteLine(sr.ReadToEnd());
Console.WriteLine("\n");
// Get all the rows.
cmd.XmlQueryProperties.MaxRows = -1;
// Append the XML document to an existing Stream.
Console.WriteLine("SQL query: select * from emp e");
Console.WriteLine("Maximum rows: all rows (-1)");
Console.WriteLine("XML Document from OracleCommand.ExecuteToStream():");
MemoryStream mstream = new MemoryStream(32);
cmd.ExecuteToStream(mstream);
mstream.Seek(0, SeekOrigin.Begin);
sr = new StreamReader(mstream, Encoding.Unicode);
Console.WriteLine(sr.ReadToEnd());
Console.WriteLine("\n");
// Clean up.
cmd.Dispose();
con.Close();
con.Dispose();
}
}
要件
ネームスペース: Oracle.DataAccess.Client
アセンブリ: Oracle.DataAccess.dll
Microsoft .NET Frameworkバージョン: 1.xまたは2.0
OracleXmlQueryPropertiesメンバーを次の表にリストします。
OracleXmlQueryPropertiesコンストラクタ
OracleXmlQueryPropertiesコンストラクタのリストを、表6-2に示します。
OracleXmlQueryPropertiesプロパティ
OracleXmlQueryPropertiesプロパティのリストを、表6-3に示します。
表6-3 OracleXmlQueryPropertiesプロパティ
| 名前 | 説明 |
|---|---|
|
結果として得られるXML文書内に表示できる、問合せの結果セットからの最大行数を指定します |
|
|
結果として得られるXML文書のルート要素を指定します |
|
|
XML文書の結果セットからのデータの行を識別するXML要素の値を指定します |
|
|
XSLTを使用したXML変換に使用されるXSL文書を指定します |
|
|
XSL文書のパラメータを指定します |
OracleXmlQueryPropertiesパブリック・メソッド
OracleXmlQueryPropertiesパブリック・メソッドのリストを、表6-4に示します。
OracleXmlQueryPropertiesコンストラクタは、OracleXmlQueryPropertiesクラスの新規インスタンスをインスタンス化します。
宣言
// C# public OracleXmlQueryProperties();
OracleXmlQueryPropertiesプロパティのリストを、表6-5に示します。
表6-5 OracleXmlQueryPropertiesプロパティ
| 名前 | 説明 |
|---|---|
|
結果として得られるXML文書内に表示できる、問合せの結果セットからの最大行数を指定します |
|
|
結果として得られるXML文書のルート要素を指定します |
|
|
XML文書の結果セットからのデータの行を識別するXML要素の値を指定します |
|
|
XSLTを使用したXML変換に使用されるXSL文書を指定します |
|
|
XSL文書のパラメータを指定します |
このプロパティは、結果として得られるXML文書内に表すことができる、問合せの結果セットからの最大行数を指定します。
宣言
// C#
public int MaxRows {get; set;}
プロパティ値
最大行数
例外
ArgumentException - MaxRowsの新規の値が有効ではありません。
備考
デフォルトの値は-1です。
可能な値は、次のとおりです。
-1 (全行)
0以上の数値
このプロパティは、結果として得られたXML文書のルート要素を指定します。
宣言
// C#
public string RootTag {get; set;}
プロパティ値
結果として得られたXML文書のルート要素
備考
デフォルトのルート・タグは、ROWSETです。
結果として得られたXML文書内でルート・タグが使用されないことを示すには、このプロパティをnull、""またはString.Emptyに設定します。
RootTagとRowTagが両方ともnullに設定されると、XML文書は結果セットが1行および1列を戻す場合にのみ戻されます。
このプロパティは、XML文書の結果セットからのデータの行を識別するXML要素の値を指定します。
宣言
// C#
public string RowTag {get; set;}
プロパティ値
XML要素の値
備考
デフォルトはROWです。
結果として得られたXML文書内で行タグが使用されないことを示すには、このプロパティをnull、""またはString.Emptyに設定します。
RootTagとRowTagが両方ともnullに設定されると、XML文書は結果セットが1行および1列を戻す場合にのみ戻されます。
このプロパティは、XSLTを使用してXML変換を行う際に使用するXSL文書を指定します。
宣言
// C#
public string Xslt {get; set;}
プロパティ値
XML変換に使用するXSL文書
備考
デフォルトの値はnullです。
XSL文書は、問合せの結果セットから生成されたXML文書のXML変換に使用されます。
このプロパティは、XSL文書のパラメータを指定します。
宣言
// C#
public string XsltParams {get; set;}
プロパティ値
XSL文書のパラメータ
備考
デフォルトの値はnullです。
パラメータを指定する際は、文字列「name=value」ペアを「param1=value1; param2=value2;...」のようにセミコロンで区切って指定します。
OracleXmlQueryPropertiesパブリック・メソッドのリストを、表6-6に示します。
このメソッドは、OracleXmlQueryPropertiesオブジェクトのコピーを作成します。
宣言
// C# public object Clone();
戻り値
OracleXmlQueryPropertiesオブジェクト
実装
ICloneable