Hi,
I
had to make the attached changes to make the direct SQL work within the Castor
JDO. The main problem with the current CVS implementation
is
that
it can only handle 1 parameter as the input and also truncates queries after
the 1st parameter. Attached is the "diff".
Thanks !
Sudhir
Index: OQLQueryImpl.java
===================================================================
RCS file: /cvs/castor/castor/src/main/org/exolab/castor/jdo/engine/OQLQueryImpl.java,v
retrieving revision 1.66
diff -c -r1.66 OQLQueryImpl.java
*** OQLQueryImpl.java 22 Jun 2001 23:57:24 -0000 1.66
--- OQLQueryImpl.java 22 Oct 2001 21:07:46 -0000
***************
*** 308,313 ****
--- 308,314 ----
}
+
public void createCall( String oql ) throws QueryException {
StringBuffer sql;
int as;
***************
*** 339,345 ****
throw new QueryException( "Syntax error: parenthesis" );
}
sql.append( oql.substring( 5, leftParen ) );
! sql.append( '(' );
for ( int i = leftParen + 1; i < rightParen; i++ ) {
if ( oql.charAt( i ) == '$' ) {
// get parameter number if given
--- 340,349 ----
throw new QueryException( "Syntax error: parenthesis" );
}
sql.append( oql.substring( 5, leftParen ) );
! //Sudhir added the while loop
! while(leftParen > 0)
! {
! sql.append( '(' );
for ( int i = leftParen + 1; i < rightParen; i++ ) {
if ( oql.charAt( i ) == '$' ) {
// get parameter number if given
***************
*** 366,379 ****
_paramInfo.put( paramNo , info );
paramCnt++;
}
! }
! for ( int i = 0; i < paramCnt; i++ ) {
sql.append( '?' );
if ( i < paramCnt - 1 )
sql.append( ',' );
! }
sql.append( ')' );
! }
_spCall = sql.toString();
_projectionType = ParseTreeWalker.PARENT_OBJECT;
_bindTypes = new Class[ paramCnt ];
--- 370,397 ----
_paramInfo.put( paramNo , info );
paramCnt++;
}
! sql.append( '?' );
! if(i < (rightParen-1))
! sql.append( ',' );
! }//end of for
! sql.append( ')' );
! leftParen = oql.indexOf( "(", rightParen);
! if(leftParen > 0)
! sql.append(oql.substring(rightParen+1, leftParen));
! else{
! if(rightParen < (as-1))
! sql.append(oql.substring(rightParen+1, as-1));
! }//end of else
! rightParen = oql.indexOf( ")", leftParen);
! }//end of while
! /*for ( int i = 0; i < paramCnt; i++ ) {
sql.append( '?' );
if ( i < paramCnt - 1 )
sql.append( ',' );
! }//end of for
sql.append( ')' );
! */
! }//end of else
_spCall = sql.toString();
_projectionType = ParseTreeWalker.PARENT_OBJECT;
_bindTypes = new Class[ paramCnt ];
***************
*** 396,402 ****
if ( _dbEngine == null || _dbEngine.getPersistence( _objClass ) == null )
throw new QueryException( "Could not find an engine supporting class " +
objType );
}
-
public QueryResults execute()
throws QueryException, PersistenceException,
TransactionNotInProgressException
--- 414,419 ----
Index: SQLEngine.java
===================================================================
RCS file: /cvs/castor/castor/src/main/org/exolab/castor/jdo/engine/SQLEngine.java,v
retrieving revision 1.107
diff -c -r1.107 SQLEngine.java
*** SQLEngine.java 7 Sep 2001 02:03:54 -0000 1.107
--- SQLEngine.java 22 Oct 2001 21:07:46 -0000
***************
*** 431,437 ****
System.arraycopy( jdoFields0, 0, jdoFields, 0, count );
System.arraycopy( sqlTypes0, 0, sqlTypes, 0, count );
// changes for the SQL Direct interface begins here
! if(spCall.startsWith("SQL")){
sql =spCall.substring(4);
return new SQLQuery( this, sql, types );
} else{
--- 431,437 ----
System.arraycopy( jdoFields0, 0, jdoFields, 0, count );
System.arraycopy( sqlTypes0, 0, sqlTypes, 0, count );
// changes for the SQL Direct interface begins here
! if(spCall.startsWith(" SQL")){
sql =spCall.substring(4);
return new SQLQuery( this, sql, types );
} else{