[prev in list] [next in list] [prev in thread] [next in thread]
List: xalan-cvs
Subject: cvs commit: xml-xalan/java/src/org/apache/xalan/lib/sql SQLDocument.java
From: johng () apache ! org
Date: 2004-09-16 4:17:06
Message-ID: 20040916041706.62851.qmail () minotaur ! apache ! org
[Download RAW message or body]
johng 2004/09/15 21:17:06
Modified: java/src/org/apache/xalan/lib/sql SQLDocument.java
Log:
Fixed bug where JDBC execute was being called instead ofg executeQuery.
executeQuery will always retrurn a result set even if the query does not return any rows
where execute won't. This was causing a compatibility issue.
Added in Record skip code to help with pagination.
PR: http://nagoya.apache.org/jira/browse/XALANJ-1908
Obtained from:
Submitted by: John Gentilin
Reviewed by:
Revision Changes Path
1.26 +53 -8 xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java
Index: SQLDocument.java
===================================================================
RCS file: /home/cvs/xml-xalan/java/src/org/apache/xalan/lib/sql/SQLDocument.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- SQLDocument.java 11 Feb 2004 17:56:36 -0000 1.25
+++ SQLDocument.java 16 Sep 2004 04:17:06 -0000 1.26
@@ -386,7 +386,11 @@
// fetched on demand.
// We need to do this here so at least on row is set up
// to measure when we are actually reading rows.
- addRowToDTMFromResultSet();
+
+ // We won't grab the first record in case the skip function
+ // is applied prior to looking at the first record.
+ // JCG Changed 9/15/04
+ // addRowToDTMFromResultSet();
}
catch(SQLException e)
{
@@ -404,11 +408,11 @@
if (! m_QueryParser.hasParameters() )
{
m_Statement = conn.createStatement();
- if (! m_Statement.execute(m_QueryParser.getSQLQuery()))
- {
- throw new SQLException("Error in Query");
- }
+ m_ResultSet = m_Statement.executeQuery(m_QueryParser.getSQLQuery());
+
+
}
+
else if (m_QueryParser.isCallable())
{
CallableStatement cstmt =
@@ -417,6 +421,8 @@
m_QueryParser.populateStatement(cstmt, m_ExpressionContext);
m_Statement = cstmt;
if (! cstmt.execute()) throw new SQLException("Error in Callable Statement");
+
+ m_ResultSet = m_Statement.getResultSet();
}
else
{
@@ -424,13 +430,45 @@
conn.prepareStatement(m_QueryParser.getSQLQuery());
m_QueryParser.populateStatement(stmt, m_ExpressionContext);
m_Statement = stmt;
- if (! stmt.execute()) throw new SQLException("Error in Prepared Statement");
+ m_ResultSet = stmt.executeQuery();
}
- m_ResultSet = m_Statement.getResultSet();
}
/**
+ * Push the record set forward value rows. Used to help in
+ * SQL pagination.
+ *
+ * @param value
+ */
+ public void skip( int value )
+ {
+ try
+ {
+ if (m_ResultSet != null) m_ResultSet.relative(value);
+ }
+ catch(Exception origEx)
+ {
+ // For now let's assume that the relative method is not supported.
+ // So let's do it manually.
+ try
+ {
+ for (int x=0; x<value; x++)
+ {
+ if (! m_ResultSet.next()) break;
+ }
+ }
+ catch(Exception e)
+ {
+ // If we still fail, add in both exceptions
+ m_XConnection.setError(origEx, this, checkWarnings());
+ m_XConnection.setError(e, this, checkWarnings());
+ }
+ }
+ }
+
+
+ /**
* Extract the Meta Data and build the Column Attribute List.
* @param meta
* @return
@@ -1004,6 +1042,13 @@
if ( m_ResultSet != null )
{
int id = _exptype(identity);
+
+ // We need to prime the pump since we don't do it in execute any more.
+ if (m_FirstRowIdx == DTM.NULL)
+ {
+ addRowToDTMFromResultSet();
+ }
+
if (
( id == m_Row_TypeID) &&
(identity >= m_LastRowIdx) )
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic