Hello,

A while back (2001-11-26) Walter Szewelanczyk suggested a patch that will 
enable a direct sql call using the "SQL CALL " keyword.

I wonder if this can be fixed in CVS version as I found this really usefull.

Thanks,


(here the patch again attached)


-- 
Victor Hadianto
Index: OQLQueryImpl.java
===================================================================
RCS file: /cvs/castor/castor/src/main/org/exolab/castor/jdo/engine/OQLQueryImpl.java,v
retrieving revision 1.67
diff -u -u -r1.67 OQLQueryImpl.java
--- OQLQueryImpl.java	11 Dec 2001 09:38:49 -0000	1.67
+++ OQLQueryImpl.java	19 Dec 2001 01:19:59 -0000
@@ -309,6 +309,26 @@
 
     }
 
+    // ADDED METHOD createSQLCall  WALTER SZEWELANCZYK 2001-11-26
+    protected int createSQLCall(String sql) throws QueryException
+    {
+        _paramInfo = new Hashtable();
+        _spCall = sql;
+        int paramCount = 0;
+        char[] chars= sql.toCharArray();
+        for(int i = 0 ; i < chars.length ; ++i)
+        {
+            if(chars[i] == '?')
+            {
+                ++paramCount;
+                ParamInfo info = new ParamInfo( "", "java.lang.Object", null);
+                info.mapToSQLParam( paramCount );
+                _paramInfo.put( new Integer(paramCount) , info );
+            }
+        }
+        return paramCount;
+    }
+
     public void createCall( String oql ) throws QueryException {
         StringBuffer sql;
         int as;
@@ -327,55 +347,61 @@
         if ( as < 0 ) {
             throw new QueryException( "Stored procedure call must end with \"AS <class-name>\"" );
         }
-        leftParen = oql.indexOf( "(" );
-        rightParen = oql.indexOf( ")" );
-        sql = new StringBuffer();
-        paramCnt = 0;
-        _paramInfo = new Hashtable();
-        if ( leftParen < 0 && rightParen < 0 ) {
-            sql.append( oql.substring( 5, as ) );
-        } else {
-            if ( ( leftParen < 0 && rightParen >= 0 )
-                    || ( leftParen > rightParen ) ) {
-                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
-                    sb = new StringBuffer();
-                    for ( int j = i + 1; j < rightParen; j++ ) {
-                        char c;
 
-                        c = oql.charAt( j );
-                        if ( c < '0' || c > '9' ) {
-                            break;
+        if(oql.startsWith("CALL SQL ")){ 
+            paramCnt = createSQLCall(oql.substring(5, as)); // WALTER SZEWELANCZYK 2001-11-26
+        }                                                   
+        else {                                                         
+            leftParen = oql.indexOf( "(" );
+            rightParen = oql.indexOf( ")" );
+            sql = new StringBuffer();
+            paramCnt = 0;
+            _paramInfo = new Hashtable();
+            if ( leftParen < 0 && rightParen < 0 ) {
+                sql.append( oql.substring( 5, as ) );
+            } else {
+                if ( ( leftParen < 0 && rightParen >= 0 )
+                     || ( leftParen > rightParen ) ) {
+                    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
+                        sb = new StringBuffer();
+                        for ( int j = i + 1; j < rightParen; j++ ) {
+                            char c;
+
+                            c = oql.charAt( j );
+                            if ( c < '0' || c > '9' ) {
+                                break;
+                            }
+                            sb.append( c );
                         }
-                        sb.append( c );
-                    }
-                    if ( sb.length() > 0 ) {
-                        paramNo = Integer.valueOf( sb.toString() );
-                    } else {
-                        paramNo = new Integer( paramCnt + 1 );
-                    }
-                    info = (ParamInfo) _paramInfo.get( paramNo );
-                    if ( info == null ) {
-                        info = new ParamInfo( "", "java.lang.Object", null);
+                        if ( sb.length() > 0 ) {
+                            paramNo = Integer.valueOf( sb.toString() );
+                        } else {
+                            paramNo = new Integer( paramCnt + 1 );
+                        }
+                        info = (ParamInfo) _paramInfo.get( paramNo );
+                        if ( info == null ) {
+                            info = new ParamInfo( "", "java.lang.Object", null);
+                        }
+                        info.mapToSQLParam( paramCnt + 1 );
+                        _paramInfo.put( paramNo , info );
+                        paramCnt++;
                     }
-                    info.mapToSQLParam( paramCnt + 1 );
-                    _paramInfo.put( paramNo , info );
-                    paramCnt++;
                 }
+                for ( int i = 0; i < paramCnt; i++ ) {
+                    sql.append( '?' );
+                    if ( i < paramCnt - 1 )
+                        sql.append( ',' );
+                }
+                sql.append( ')' );
             }
-            for ( int i = 0; i < paramCnt; i++ ) {
-                sql.append( '?' );
-                if ( i < paramCnt - 1 )
-                    sql.append( ',' );
-            }
-            sql.append( ')' );
+            _spCall = sql.toString();
         }
-        _spCall = sql.toString();
         _projectionType = ParseTreeWalker.PARENT_OBJECT;
         _bindTypes = new Class[ paramCnt ];
         for ( int i = 0; i < paramCnt; i++ )

Reply via email to