Return-Path: Delivered-To: apmail-xml-cocoon-dev-archive@xml.apache.org Received: (qmail 32481 invoked by uid 500); 30 Jan 2002 10:10:58 -0000 Mailing-List: contact cocoon-dev-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: Reply-To: cocoon-dev@xml.apache.org Delivered-To: mailing list cocoon-dev@xml.apache.org Received: (qmail 32458 invoked from network); 30 Jan 2002 10:10:58 -0000 Date: Wed, 30 Jan 2002 11:10:15 +0100 From: Christian Haul To: "Durrant, Peter" , Kosh.Podder@ubsw.com, "NUGENT ROBERT (APP3RJN)" Cc: cocoon-dev@xml.apache.org Subject: esql stored procedure support Message-ID: <20020130111014.A1849@bremen.dvs1.informatik.tu-darmstadt.de> Reply-To: haul@dvs1.informatik.tu-darmstadt.de Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="XMCwj5IQnwKtuyBG" Content-Disposition: inline User-Agent: Mutt/1.3.22.1i Organization: Databases and Distributed Systems Group, Darmstadt University of Technology X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --XMCwj5IQnwKtuyBG Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Peter, Kosh, I've got a new iteration of the stored procedure support for esql. (Kosh, I will mail you the necessary files separately because you indicated that you have problems with CVS). Bob, I've CC'ed you since you might be interested to try the feature. Since the next release is due in a couple of days I don't want to commit these changes right now unless I hear success stories from you. The DBMS I use on a regulary basis does not support most of what's in this patch so I rely on you to send bug reports (and fixes!). Diff is against today's CVS HEAD as usual. The attributes to have been renamed to be a bit more XMLish (needsQuery -> needs-query, resultsetFromObject -> resultset-from-object) * use instead of , for stored procedures, use either DBMS specific syntax or JDBC escape syntax "{? = foo(?)}" * if driver requires to use the "executeQuery()" method instead of the "execute()" method (like e.g. INFORMIX does), set 'needs-query="true"' attribute to * if a result set is returned through the (only) return parameter of a stored procedure, one can use e.g. 'resultset-from-object="1"' as attribute to to automatically use this result set. For a more general alternative see further below. * (child of ) may contain code that will always be executed whether the call returned a resultset or not. * all tags accept new attribute 'from-call="yes"' to indicate that the value is retrieved from the CallableStatement rather than the current ResultSet. * Retrieve a ResultSet from any column and use it like the result of a nested query by e.g. . Of course the column needs to return a result that is castable to ResultSet. Example: {? = foo(1)} Disclaimer: I have only tested a fraction of these modifications as the DBMS I use does not support the other variants. I have, however, tried to ensure that the resulting code compiles well. Please try this code and report failures (preferably with fixes :-) and successes to me and cocoon-dev Chris. -- C h r i s t i a n H a u l haul@informatik.tu-darmstadt.de fingerprint: 99B0 1D9D 7919 644A 4837 7D73 FEF9 6856 335A 9E08 --XMCwj5IQnwKtuyBG Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="esql.patch" ? esql.patch Index: EsqlQuery.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/EsqlQuery.java,v retrieving revision 1.2 diff -r1.2 EsqlQuery.java 12a13 > import java.sql.CallableStatement; 32a34 > private boolean resultSetValid = false; 47a50,57 > public EsqlQuery( ResultSet aResultSet ) { > this.connection = null; > this.statement = null; > this.query = null; > this.resultSetValid = true; > this.hasResultSet = (this.resultSet != null); > } > 120a131,143 > > public CallableStatement prepareCall() throws SQLException { > switch(limitMethod) { > case EsqlConnection.LIMIT_METHOD_JDBC: > preparedStatement = connection.prepareCall( getQueryString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); > break; > default: > preparedStatement = connection.prepareCall( getQueryString() ); > }; > statement = preparedStatement; > return((CallableStatement)preparedStatement); > } > 124a148,151 > public CallableStatement getCallableStatement() { > return((CallableStatement) preparedStatement); > } > 174,180c201,239 < if (preparedStatement != null) { < hasResultSet = preparedStatement.execute(); < } < else { < hasResultSet = statement.execute( getQueryString() ); < } < return(hasResultSet); --- > return this.execute(false); > } > > /** > * some brain dead DBMSs (Oracle) return their result sets for > * callable statements through the some (i.e. the first) returned > * object. > */ > public boolean execute( int resultSetFromObject ) throws SQLException { > hasResultSet = this.execute(false); > resultSet = (ResultSet) ((CallableStatement) preparedStatement).getObject(1); > resultSetValid = true; > return hasResultSet; > } > > /** > * some other brain dead DBMSs (Informix) don't like their callable > * statements to be 'execute'd but require 'executeQuery' instead. > */ > public boolean execute( boolean needsQuery ) throws SQLException { > if ( needsQuery ) { > if (preparedStatement != null) { > resultSet = preparedStatement.executeQuery(); > } > else { > resultSet = statement.executeQuery( getQueryString() ); > } > hasResultSet = (resultSet != null); > resultSetValid = true; > } else { > if (preparedStatement != null) { > hasResultSet = preparedStatement.execute(); > } > else { > hasResultSet = statement.execute( getQueryString() ); > } > resultSetValid = false; > } > return(hasResultSet); 212,213c271,275 < resultSet = statement.getResultSet(); < resultSetMetaData = resultSet.getMetaData(); --- > if ( resultSetValid ) { > resultSetMetaData = resultSet.getMetaData(); > } else { > resultSet = statement.getResultSet(); > } Index: java/esql.xsl =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/markup/xsp/java/esql.xsl,v retrieving revision 1.4 diff -r1.4 esql.xsl 207a208 > java.sql.CallableStatement 440c441,443 < --- > > > 462a466,505 > > try { > _esql_query.prepareCall(); > } catch (SQLException _esql_exception_) { > throw new RuntimeException("Error preparing statement: " + _esql_query.getQueryString() + ": "+_esql_exception_.getMessage()); > } > > try { > > _esql_query.getCallableStatement(). > registerOutParameter(, Types., ); > > > _esql_query.getCallableStatement(). > > > > set(,); > > > > setString(,String.valueOf()); > > > > > } catch (SQLException _esql_exception_) { > throw new RuntimeException("Error setting parameter on statement: " + _esql_query.getQueryString() + ": "+_esql_exception_); > } > > try { > > _esql_query.execute(true); > _esql_query.execute(); > _esql_query.execute(); > > } catch (SQLException _esql_exception_) { > throw new RuntimeException("Error executing prepared statement: " + _esql_query.getQueryString() + ": "+_esql_exception_); > } > 509a553,558 > > // call results > > > > 561a611 > "?" 572a623,631 > > > // call results2 > > > > > > 784c843 < --- > 794c853 < --- > 806c865 < --- > 818c877 < --- > 830c889 < --- > 835c894 < --- > 847c906 < --- > 864c923 < --- > 869c928 < --- > 874c933 < --- > 879c938 < --- > 884c943 < --- > 889c948 < --- > 894c953 < --- > 902c961 < --- > 975c1034 < --- > 980c1039 < --- > 985c1044 < --- > 990c1049 < --- > 995c1054 < --- > 1003a1063,1096 > > > > // nested result set > if (_esql_query != null) { > _esql_queries.push(_esql_query); > } > _esql_query = new EsqlQuery((ResultSet) .getObject()); > { > if (_esql_query.hasResultSet()) { > do { > _esql_query.getResultRows(); > > if (_esql_query.nextRow()) { > > } > else { > > } > _esql_query.getResultSet().close(); > > } while(_esql_query.getMoreResults()); > } else { > > } > } > if (_esql_queries.empty()) { > _esql_query = null; > } else { > _esql_query = (EsqlQuery)_esql_queries.pop(); > } > > > 1020c1113 < .getResultSet() --- > .getCallableStatement().getResultSet() 1089a1183,1203 > > > > > > TINYINT > SMALLINT > INTEGER > BIGINT > REAL > DECIMAL > BIT > VARCHAR > BINARY > LONGVARCHAR > LONGVARCHAR > VARBINARY > > > > --XMCwj5IQnwKtuyBG Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org For additional commands, email: cocoon-dev-help@xml.apache.org --XMCwj5IQnwKtuyBG--