From: Vladimir T. <pr...@us...> - 2004-02-08 15:35:36
|
Update of /cvsroot/firebird/OdbcJdbc/IscDbc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5067 Modified Files: Tag: v1-2-beta IscConnection.cpp IscConnection.h Log Message: - the control of parameters for a call {call} is added branch v1-2-beta Index: IscConnection.cpp =================================================================== RCS file: /cvsroot/firebird/OdbcJdbc/IscDbc/IscConnection.cpp,v retrieving revision 1.6.2.16 retrieving revision 1.6.2.17 diff -b -U3 -r1.6.2.16 -r1.6.2.17 --- IscConnection.cpp 6 Feb 2004 12:11:08 -0000 1.6.2.16 +++ IscConnection.cpp 8 Feb 2004 15:32:33 -0000 1.6.2.17 @@ -48,6 +48,7 @@ #include <string.h> #include "IscDbc.h" #include "IscConnection.h" +#include "IscProceduresResultSet.h" #include "SQLError.h" #include "IscOdbcStatement.h" #include "IscCallableStatement.h" @@ -286,6 +287,152 @@ } ***/ +int IscConnection::buildParamProcedure ( char *& string, int numInputParam ) +{ + char * ptSrc = string; + + if ( !numInputParam ) + { + while( *ptSrc && *ptSrc != '}' ) + ptSrc++; + + if ( *ptSrc == '}' ) + memmove(string, ptSrc, strlen(ptSrc) + 1 ); + + return 0; + } + + while( *ptSrc && *ptSrc != '(' ) + ptSrc++; + + if ( *ptSrc != '(' ) + return -1; + + ptSrc++; // '(' + + int i = 0; + bool nextParam = false; + char * ptCh; + + while( *ptSrc && i < numInputParam ) + { + SKIP_WHITE ( ptSrc ); + + if ( *ptSrc == ')' ) + return -1; + + if ( *ptSrc == ',' ) + { + if ( nextParam == true ) + { + nextParam = false; + ptSrc++; + } + else + { + i++; + memmove(ptSrc + 1, ptSrc, strlen(ptSrc) + 1 ); + *ptSrc = '?'; + ptSrc += 2; + } + continue; + } + + char delimiter; + + ptCh = ptSrc; + + if ( *ptCh == '\'' ) + { + delimiter = *ptCh; + ++ptCh; // '\'' + ptSrc = ptCh; + while ( *ptCh && *ptCh != ',' && *ptCh != ')' ) + { + if ( *ptCh == delimiter ) + { + if ( *(ptCh+1) == delimiter ) + { + ptCh += 2; + continue; + } + break; + } + ++ptCh; + } + + if ( *ptCh && *ptCh != delimiter && *ptCh != ',' ) + { + ptSrc = ptCh; + i++; + break; + } + + if ( *ptCh == delimiter ) + { + nextParam = true; + ptCh++; + } + } + else + { + delimiter = ','; + ptSrc = ptCh; + while ( *ptCh && *ptCh != delimiter && *ptCh != ')' ) + ++ptCh; + + if ( *ptCh && *ptCh != delimiter ) + { + ptSrc = ptCh; + i++; + break; + } + + nextParam = false; + } + + if( ptCh == ptSrc ) + ptSrc++; + else + { + ptSrc = ptCh + 1; + i++; + } + } + + SKIP_WHITE(ptSrc); + + if ( *ptSrc == ')' ) + { + if ( i < numInputParam ) + { + int offset = (numInputParam - i) * 2; + memmove(ptSrc + offset, ptSrc, strlen(ptSrc) + 1 ); + + while( i++ < numInputParam ) + { + *ptSrc++ = ','; + *ptSrc++ = '?'; + } + } + return 0; + } + else if ( !*ptSrc ) + return -1; + + ptCh = --ptSrc; + +// ASSERT ( *ptCh == ',' ); + + while ( *ptCh && *ptCh != ')' ) + ptCh++; + + memmove(ptSrc, ptCh, strlen(ptCh) + 1 ); + string = ptSrc + 1; + + return 0; +} + bool IscConnection::getNativeSql (const char * inStatementText, long textLength1, char * outStatementText, long bufferLength, long * textLength2Ptr) @@ -421,6 +568,26 @@ ptIn += offset; ptOut += LENSTR_EXECUTE_PROCEDURE; + char procedureName[256]; + char * end = procedureName; + + SKIP_WHITE ( ptIn ); + + end = procedureName; + + while ( !(IS_END_TOKEN(*ptIn)) ) + *end++ = *ptIn++; + + *end = '\0'; + + int count = getCountInputParamFromProcedure ( procedureName ); + int ret = buildParamProcedure ( ptIn, count ); + + if ( ret == -1 ) + return false; + + ptOut = ptIn; + do { while( *ptIn && *ptIn != '}' ) @@ -501,6 +668,24 @@ return bModify; } +int IscConnection::getCountInputParamFromProcedure ( const char* procedureName ) +{ + int num = 0; + IscProceduresResultSet * resultSet = + (IscProceduresResultSet*)getMetaData()->getProcedures ( NULL, NULL, procedureName ); + + if ( resultSet ) + { + if ( resultSet->next() ) + num = resultSet->sqlda->getShort(4); // NUM_INPUT_PARAM + else + num = -1; // not found + resultSet->release(); + } + + return num; +} + DatabaseMetaData* IscConnection::getMetaData() { if (metaData) Index: IscConnection.h =================================================================== RCS file: /cvsroot/firebird/OdbcJdbc/IscDbc/IscConnection.h,v retrieving revision 1.2.2.8 retrieving revision 1.2.2.9 diff -b -U3 -r1.2.2.8 -r1.2.2.9 --- IscConnection.h 27 Dec 2003 19:17:25 -0000 1.2.2.8 +++ IscConnection.h 8 Feb 2004 15:32:33 -0000 1.2.2.9 @@ -95,7 +95,9 @@ //virtual void freeHTML (const char *html); virtual Blob* genHTML (Properties *context, long genHeaders); virtual bool isConnected(); - InternalStatement* IscConnection::createInternalStatement(); + InternalStatement* createInternalStatement(); + int getCountInputParamFromProcedure ( const char* procedureName ); + int buildParamProcedure ( char *& string, int numInputParam ); virtual void prepareTransaction(); virtual bool getTransactionPending(); void *getHandleDb(); |