This section describes the ResultSetXml class that supports the ResultSet DTD.
The ResultSetXml class is similar to the OrderXml class. It is a subclass of the JXml class, which validates a document with the XML ResultSet DTD, and also provides methods for accessing and updating the elements of the contained XML ResultSet document.
Constructor: ResultSetXml(String)
Validates that the argument contains a valid XML ResultSet document and constructs a ResultSetXml object containing that document. For example, if doc is a Java String variable containing an XML ResultSet document, read from a file:
jcs.xml.resultset.ResultSetXml rsx = new jcs.xml.resultset.ResultSetXml(doc);
Constructor: ResultSetXml(query, cdataColumns, colNames, dtdOption, server)
The parameters are all String.
The query parameter is any SQL query that returns a result set.
The server parameter identifies the IQ server on which to execute the query.
If you invoke the method in a client environment, specify the server name.
If you invoke the method on an IQ server (in a SQL statement or dbisql), specify either an empty string or the string “jdbc:default:connection,” indicating that the query should be executed on the current Sybase IQ.
The method connects to the server, executes the query, retrieves the SQL result set, and constructs a ResultSetXml object with that result set.
The cdataColumns parameter indicates which columns should be XML CDATA sections. The colNames parameter indicates whether the resulting XML should specify “name” attributes in the “Column” elements. The dtdOption indicates whether the resulting XML should include the XML DTD for the ResultSet document type in-line, or reference it externally.
For example:
jcs.xml.resultset.ResultSetXml rsx = new jcs.xml.resultset.ResultSetXml (“select 1 as ‘a’, 2 as ‘b’, 3 ”, “none”, “yes”, “external”, “antibes:4000?user=DBA&password=SQL”);
This constructor call connects to the server specified in the last argument, evaluates the SQL query given in the first argument, and returns an XML ResultSet containing the data from the result set of the query. This simple SQL query does not reference a table. If the constructor is called in the Sybase IQ, then the server parameter should be an empty string or jdbc:default:connection, to indicate a connection to the current server.
String toSqlScript(resultTableName, columnPrefix, writeOption, goOption)
The parameters are all String.
The method returns a SQL script with a create statement and a list of insert statements that re-create the result set data.
The resultTableName parameter is the table name for the create and insert statements. (SQL result sets do not specify a table name because they could be derived from joins or unions.) The columnPrefix parameter is the prefix to use in generated column names, which are needed for unnamed columns in the result set. The writeOption parameter indicates whether the script is to include the create statement, the insert statements, or both. The goOption parameter indicates whether the script is to include the go commands, which are required in dbisql and not supported in JDBC.
For example, if rsx is a Java variable of type ResultSetXml:
rsx>>toSqlScript('systypes_copy', 'column_', 'both', 'yes')
String getColumn(int rowNumber, int columnNumber)
rowNumber is the index of a row in the result set; columnNumber is the index of a column of the result set. The method returns the text of the specified column.
For example, if rsx is a Java variable of type ResultSetXml:
select rsx>>getColumn(3, 4)
String getColumn(int rowNumber, String columnName)
rowNumber is the index of a row in the result set; columnName is the name of a column of the result set. The method returns the text of the specified column.
For example, if rsx is a Java variable of type ResultSetXml:
select rsx>>getColumn(3, 'name')
void setColumn(int rowNumber, int columnNumber, newValue)
rowNumber and columnNumber are as described for getColumn( ). The method sets the text of the specified column to newValue.
For example, if rsx is a Java variable of type ResultSetXml:
set rsx = rsx>>setColumn(3, 4, 'new value')
void setColumn(int rowNumber, String columnName, newValue)
rowNumber and columnName are as described for getColumn( ). The method sets the text of the specified column to newValue.
For example, if rsx is a Java variable of type ResultSetXml:
set rsx = rsx>>setColumn(3, 'name', 'new value')
Boolean allString(int columnNumber, String compOp, String comparand)
columnNumber is the index of a column of the result set. compOp is a SQL comparison operator (<, >, =, !=, <=, >=). comparand is a comparison value. The method returns a value indicating whether the specified comparison is true for all rows of the result set.
For example, if rsx is a Java variable of type ResultSetXml:
if rsx>>allString(3, '<', 'compare value')…
This condition is true if, in the result set represented by rsx, the value of column 3 is less than “compare value” for all rows. This is a String comparison. Similar methods can be used for other data types.
Boolean someString(int columnNumber, String compOp, String comparand)
columnNumber is the index of a column of the result set. compOp is a SQL comparison operator (<, >, =, !=, <=, >=). comparand is a comparison value. The method returns a value indicating whether the specified comparison is true for some row of the result set.
For example, if rsx is a Java variable of type ResultSetXml:
if rsx>>someString(3, '<', 'compare value') …
This condition is true if, in the result set represented by rsx, the value of column 3 is less than “compare value” for some row.