fix for trie index
[csql.git] / src / odbc / odbcStmt.cxx
blob68c951fe3e534bfb44fe13f918c5634cb4d9ad24
2 // Class CSqlOdbcStmt
3 // Description: Statement Handle manager.
5 #include "odbcCommon.h"
7 // Constructor
8 CSqlOdbcStmt::CSqlOdbcStmt( void ) :
9 handleType_( SQL_HANDLE_STMT ),
10 parentDbc_( 0 ),
11 state_( S1 ),
12 err_( SQL_HANDLE_STMT ),
13 rowsAffected_( -1 ),
14 isParamBound_( true ),
15 isPrepared_( false ),
16 apd_(SQL_DESC_APP),
17 ipd_(SQL_DESC_IMP),
18 ard_(SQL_DESC_APP),
19 ird_(SQL_DESC_IMP),
20 fsqlStmt_( NULL )
21 //HACK::
22 //fetchMode_(SQL_FETCH_SINGLE_TUPLE)
24 cursorName_[0] = '\0';
27 SQLRETURN SQLAllocStmt(
28 SQLHDBC ConnectionHandle,
29 SQLHSTMT *StatementHandle)
31 return( CSqlOdbcStmt::SQLAllocHandle( ConnectionHandle, StatementHandle ) );
34 SQLRETURN CSqlOdbcStmt::SQLAllocHandle(
35 SQLHANDLE inputHandle, // IN
36 SQLHANDLE *outputHandle ) // OUT
38 CSqlOdbcDbc *inputDbc = (CSqlOdbcDbc*) inputHandle;
40 // Is Dbc valid ?
41 if( isValidHandle( inputDbc, SQL_HANDLE_DBC ) != SQL_SUCCESS )
42 return( SQL_INVALID_HANDLE );
44 // Is Dbc connected ?
45 if( inputDbc->state_ < C4 )
47 globalError.set( ERROR_CONNOTOPEN );
48 globalError.printStr( SQL_OV_ODBC3 );
49 return( SQL_ERROR );
51 if (NULL == outputHandle)
53 globalError.set(ERROR_INVARGVAL);
54 return (SQL_ERROR);
58 // Allocate Statement object.
59 *outputHandle = (SQLHANDLE*) new CSqlOdbcStmt;
60 if( *outputHandle == NULL )
62 globalError.set( ERROR_MEMALLOC );
63 globalError.printStr( SQL_OV_ODBC3 );
64 return( SQL_ERROR );
67 // Initialize relation b/w Stmt and Dbc
68 inputDbc->stmtList_.append(*outputHandle );
69 inputDbc->stmtHdlList_.append(outputHandle);
70 if( inputDbc->state_ <= C4 )
71 inputDbc->state_ = C5;
72 ((CSqlOdbcStmt*) *outputHandle)->parentDbc_ = inputDbc;
73 //CSqlOdbcError::printDbg("proxy:stmt:setConnection");
74 //((CSqlOdbcStmt*) *outputHandle)->fsqlStmt_->setConnection( inputDbc->fsqlConn_ );
75 ((CSqlOdbcStmt*) *outputHandle)->fInfo = new FieldInfo();
76 return( SQL_SUCCESS );
79 SQLRETURN CSqlOdbcStmt::SQLFreeHandle(
80 SQLHANDLE inputHandle) // IN
82 CSqlOdbcStmt *inputStmt = (CSqlOdbcStmt*) inputHandle;
84 // Is Stmt valid ?
85 if( isValidHandle( inputStmt, SQL_HANDLE_STMT ) != SQL_SUCCESS )
86 return( SQL_INVALID_HANDLE );
88 // Can we proceed ?
89 if( inputStmt->chkStateForSQLFreeHandle() != SQL_SUCCESS )
90 return( SQL_ERROR );
92 // Free resultset
93 inputStmt->resetStmt();
95 // Remove Stmt from Parent Dbc.
96 ListIterator iter = inputStmt->parentDbc_->stmtList_.getIterator();
97 CSqlOdbcStmt *stmtElem = NULL;
98 while (iter.hasElement()) {
99 stmtElem = (CSqlOdbcStmt *) iter.nextElement();
100 if( stmtElem == inputStmt ) {
101 iter.reset();
102 inputStmt->parentDbc_->stmtList_.remove(stmtElem);
103 break;
106 // Set Dbc state_ = no statement.
107 if( inputStmt->parentDbc_->stmtList_.size() == 0 )
108 inputStmt->parentDbc_->state_ = C4;
110 inputStmt->handleType_ = -1; // Make object invalid.
111 SQLHANDLE *elem;
112 ListIterator it = inputStmt->parentDbc_->stmtHdlList_.getIterator();
113 while (it.hasElement()) {
114 elem = (SQLHANDLE *) it.nextElement();
115 if(*elem == inputStmt) *elem = NULL;
117 inputStmt->parentDbc_->stmtHdlList_.remove(elem);
118 delete inputStmt->fInfo;
119 delete inputStmt; // Delete Stmt.
120 return( SQL_SUCCESS );
123 SQLRETURN SQLFreeStmt(
124 SQLHSTMT StatementHandle, // IN
125 SQLUSMALLINT Option) // IN
127 #ifdef DEBUG
128 printError(ErrWarning, "SQLFreeStmt opt:%d", Option);
129 #endif
130 // Is Stmt valid ?
131 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
132 return( SQL_INVALID_HANDLE );
134 // Free Handle
135 if( Option == SQL_DROP )
136 return( CSqlOdbcStmt::SQLFreeHandle( StatementHandle ) );
138 return( ((CSqlOdbcStmt*) StatementHandle)->SQLFreeStmt( Option ) );
141 SQLRETURN CSqlOdbcStmt::SQLFreeStmt(
142 SQLUSMALLINT option)
144 // Start with NO_ERR
145 err_.set( NO_ERR );
147 // Can we proceed
148 if( chkStateForSQLFreeStmt() != SQL_SUCCESS )
149 return( SQL_ERROR );
150 if (!fsqlStmt_) return (SQL_SUCCESS);
151 switch( option )
153 case SQL_CLOSE: // // Free resultset
154 // if( fsqlStmt_->isSelect() == true ) // CSQL
155 // {
156 // //CSqlOdbcError::printDbg("proxy:stmt:getResultSet");
157 // CSqlResultSet *resultSet_ = fsqlStmt_->getResultSet(); // CSQL
158 // if( resultSet_ && resultSet_->isOpen() == true )
159 // {
160 // resultSet_->close();
161 // }
162 // }
164 // cursor states
165 if( isPrepared_ )
167 if( fsqlStmt_->isSelect() == true ) { // CSQL
168 fsqlStmt_->close();
169 state_ = S3; // With Cursor
171 else
172 state_ = S2; // Without Cursor
174 else
176 ard_.freeAllDesc();
177 apd_.freeAllDesc();
178 ipd_.freeAllDesc();
179 ird_.freeAllDesc();
180 fsqlStmt_->free(); // CSQL
181 state_ = S1;
184 break;
186 case SQL_UNBIND: ard_.freeAllDesc();
187 ird_.freeAllDesc();
188 break;
190 case SQL_RESET_PARAMS: apd_.freeAllDesc();
191 ipd_.freeAllDesc();
192 //isParamBound_ = false;
193 break;
195 default: err_.set( ERROR_OPTRANGE );
196 return( SQL_ERROR );
198 return( SQL_SUCCESS );
201 SQLRETURN SQLBindCol(
202 SQLHSTMT StatementHandle,
203 SQLUSMALLINT ColumnNumber,
204 SQLSMALLINT TargetType,
205 SQLPOINTER TargetValue,
206 SQLINTEGER BufferLength,
207 SQLINTEGER *StrLen_or_Ind)
209 #ifdef DEBUG
210 printError(ErrWarning, "SQLBindCol");
211 #endif
212 // Is Stmt valid ?
213 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
214 return( SQL_INVALID_HANDLE );
216 return( ((CSqlOdbcStmt*) StatementHandle)->SQLBindCol( ColumnNumber,
217 TargetType, TargetValue, BufferLength, StrLen_or_Ind ) );
220 SQLRETURN CSqlOdbcStmt::SQLBindCol(
221 SQLUSMALLINT columnNumber,
222 SQLSMALLINT targetType,
223 SQLPOINTER targetValue,
224 SQLINTEGER bufferLength,
225 SQLINTEGER *ind)
227 CSqlOdbcDesc *bindDesc = 0;
228 CSqlOdbcDesc *inputDesc = 0;
229 SQLRETURN found = SQL_ERROR;
231 // Start with NO_ERR
232 err_.set( NO_ERR );
234 // Can we proceed ?
235 if( chkStateForSQLBindCol() != SQL_SUCCESS )
236 return( SQL_ERROR );
238 // Invalid Buffer Length.
239 switch( targetType )
241 // switch is in order to support more types.
242 case SQL_C_CHAR:
243 if( bufferLength < 0 && bufferLength != SQL_NTS )
245 err_.set( ERROR_BUFLEN );
246 return( SQL_ERROR );
248 break;
249 case SQL_C_BINARY:
250 if( bufferLength < 0 && bufferLength != SQL_NTS )
252 err_.set( ERROR_BUFLEN );
253 return( SQL_ERROR );
255 break;
258 // Invalid Column Number
259 if( columnNumber < 1 )
261 err_.set( ERROR_COLNUM );
262 return( SQL_ERROR );
265 // Get the Descriptor if already exists
266 found = ard_.getDescWithColNum( columnNumber , &bindDesc );
268 // UNBIND
269 if( targetValue == 0 )
271 if( found != SQL_SUCCESS )
273 err_.set( ERROR_COLNUM );
274 return( SQL_ERROR );
276 ard_.delDesc( bindDesc ); // UNBIND
278 return( SQL_SUCCESS );
281 // Validate target Type, Value and Column no.
282 if( targetValue == 0 || isValidCType( targetType ) != SQL_SUCCESS )
284 err_.set( ERROR_INVBUFTYPE );
285 return( SQL_ERROR );
288 // Add new descriptor
289 if( found != SQL_SUCCESS )
291 bindDesc = new CSqlOdbcDesc();
292 ard_.descList_.append(bindDesc);
295 // Initialize Descriptor.
296 bindDesc->col_ = columnNumber;
297 bindDesc->cType_ = targetType;
298 bindDesc->dataPtr_ = targetValue;
299 bindDesc->length_ = (SQLUINTEGER) bufferLength;
300 bindDesc->indPtr_ = (SQLPOINTER) ind;
302 found = ird_.getDescWithColNum( columnNumber , &inputDesc );
304 // Add new descriptor
305 if( found != SQL_SUCCESS )
307 inputDesc = new CSqlOdbcDesc();
308 ird_.descList_.append(inputDesc);
310 ResultSetPlan pl = fsqlStmt_->getResultSetPlan();
311 //Get Field Information from CSQL
312 fsqlStmt_->getProjFldInfo(columnNumber, fInfo);
313 // Initialize input Descriptor.
314 //DataType sourceType = getCSqlType( targetType );
315 //char fldName[IDENTIFIER_LENGTH];
316 //Table::getFieldNameAlone((char*)fInfo->fldName,fldName);
317 strcpy((char *)inputDesc->colName_,(char*)fInfo->fldName);
318 inputDesc->col_ = columnNumber;
319 if( pl == GetColumns && columnNumber == 5) {
320 inputDesc->csqlType_ = typeShort;
321 inputDesc->cType_ = typeShort;
323 else {
324 inputDesc->csqlType_ = fInfo->type;
325 inputDesc->cType_ = fInfo->type;
327 getInputBuffer(&inputDesc->dataPtr_ ,fInfo->type,(SQLUINTEGER) bufferLength);
328 inputDesc->length_ = fInfo->length;
329 inputDesc->indPtr_ = (SQLPOINTER) ind;
330 return( SQL_SUCCESS );
333 SQLRETURN SQLSetParam(
334 SQLHSTMT StatementHandle,
335 SQLUSMALLINT ParameterNumber,
336 SQLSMALLINT ValueType,
337 SQLSMALLINT ParameterType,
338 SQLUINTEGER LengthPrecision,
339 SQLSMALLINT ParameterScale,
340 SQLPOINTER ParameterValue,
341 SQLINTEGER *StrLen_or_Ind)
343 #ifdef DEBUG
344 printError(ErrWarning, "SQLSetParam");
345 #endif
347 return( SQLBindParameter( StatementHandle, ParameterNumber,
348 SQL_PARAM_INPUT_OUTPUT, ValueType, ParameterType, LengthPrecision,
349 ParameterScale, ParameterValue, 0, StrLen_or_Ind) );
352 SQLRETURN SQLBindParam(
353 SQLHSTMT StatementHandle,
354 SQLUSMALLINT ParameterNumber,
355 SQLSMALLINT ValueType,
356 SQLSMALLINT ParameterType,
357 SQLUINTEGER LengthPrecision,
358 SQLSMALLINT ParameterScale,
359 SQLPOINTER ParameterValue,
360 SQLINTEGER *StrLen_or_Ind)
362 #ifdef DEBUG
363 printError(ErrWarning, "SQLBindParam");
364 #endif
366 return( SQLBindParameter( StatementHandle, ParameterNumber,
367 SQL_PARAM_INPUT_OUTPUT, ValueType, ParameterType, LengthPrecision,
368 ParameterScale, ParameterValue, 0, StrLen_or_Ind) );
371 SQLRETURN SQLBindParameter(
372 SQLHSTMT StatementHandle,
373 SQLUSMALLINT ParameterNumber,
374 SQLSMALLINT InputOutputType,
375 SQLSMALLINT ValueType,
376 SQLSMALLINT ParameterType,
377 SQLUINTEGER LengthPrecision,
378 SQLSMALLINT ParameterScale,
379 SQLPOINTER ParameterValue,
380 SQLINTEGER BufferLength,
381 SQLINTEGER *StrLen_or_Ind)
383 #ifdef DEBUG
384 printError(ErrWarning, "SQLBindParameter");
385 #endif
386 // Is Stmt valid ?
387 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
388 return( SQL_INVALID_HANDLE );
390 return( ((CSqlOdbcStmt*) StatementHandle)->SQLBindParameter( ParameterNumber,
391 InputOutputType, ValueType,
392 ParameterType, LengthPrecision,
393 ParameterScale, ParameterValue,
394 BufferLength, StrLen_or_Ind ) );
397 SQLRETURN CSqlOdbcStmt::SQLBindParameter(
398 SQLUSMALLINT parameterNumber,
399 SQLSMALLINT inputOutputType,
400 SQLSMALLINT valueType,
401 SQLSMALLINT parameterType,
402 SQLUINTEGER lengthPrecision,
403 SQLSMALLINT parameterScale,
404 SQLPOINTER parameterValue,
405 SQLINTEGER bufferLength,
406 SQLINTEGER *ind)
408 CSqlOdbcDesc *bindDesc = 0;
409 CSqlOdbcDesc *inputDesc =0;
410 SQLRETURN found;
412 // Start with NO_ERR
413 err_.set( NO_ERR );
415 // Can we proceed ?
416 if( chkStateForSQLBindParameter() != SQL_SUCCESS )
417 return( SQL_ERROR );
418 // Invalid Buffer Length.
419 switch( valueType )
421 // switch is in order to support more types.
422 case SQL_C_CHAR:
423 if( bufferLength < 0 && bufferLength != SQL_NTS )
425 err_.set( ERROR_BUFLEN );
426 return( SQL_ERROR );
428 break;
429 case SQL_C_BINARY:
430 if( bufferLength < 0 && bufferLength != SQL_NTS )
432 err_.set( ERROR_BUFLEN );
433 return( SQL_ERROR );
435 break;
438 // Validate parameters
439 switch( inputOutputType )
441 case SQL_PARAM_INPUT:
442 case SQL_PARAM_OUTPUT:
443 case SQL_PARAM_INPUT_OUTPUT: break;
444 default: err_.set( ERROR_INV_PARAMTYPE );
445 return( SQL_ERROR );
447 if( isValidCType( valueType ) != SQL_SUCCESS )
448 // || isValidSQLType( parameterType ) != SQL_SUCCESS )
450 err_.set( ERROR_INVBUFTYPE );
451 return( SQL_ERROR );
453 if( parameterNumber < 1 )
455 err_.set( ERROR_COLNUM );
456 return( SQL_ERROR );
459 // Get the Descriptor if already exists
460 found = apd_.getDescWithColNum( parameterNumber , &bindDesc );
461 if( found != SQL_SUCCESS )
463 bindDesc = new CSqlOdbcDesc();
464 apd_.descList_.append(bindDesc);
465 // Initialize Descriptor.
466 bindDesc->col_ = parameterNumber;
467 bindDesc->paramType_ = inputOutputType;
468 bindDesc->cType_ = valueType;
469 bindDesc->sqlType_ = parameterType;
470 bindDesc->dataPtr_ = parameterValue;
471 bindDesc->length_ = (SQLUINTEGER) bufferLength;
472 bindDesc->precision_ =(short) lengthPrecision;
473 bindDesc->scale_ = parameterScale;
474 bindDesc->indPtr_ = (SQLPOINTER) ind;
476 found = ipd_.getDescWithColNum (parameterNumber, &inputDesc);
477 if( found != SQL_SUCCESS )
479 inputDesc = new CSqlOdbcDesc();
480 ipd_.descList_.append(inputDesc);
481 //Initialize inputDescriptor
482 DataType destType=getCSqlType(valueType);
483 inputDesc->col_ = parameterNumber;
484 inputDesc->paramType_ = inputOutputType;
485 inputDesc->cType_ = valueType;
486 inputDesc->sqlType_ = parameterType;
487 inputDesc->dataPtr_= NULL;
488 //getInputBuffer(&inputDesc->dataPtr_,destType,(SQLUINTEGER)bufferLength);
489 inputDesc->length_ = (SQLUINTEGER) bufferLength;
490 inputDesc->precision_ = (short)lengthPrecision;
491 inputDesc->scale_ = parameterScale;
492 inputDesc->indPtr_ = (SQLPOINTER) ind;
494 //isParamBound_ = false;
495 return( SQL_SUCCESS );
498 SQLRETURN SQLExecDirect(
499 SQLHSTMT StatementHandle, // IN
500 SQLCHAR *StatementText, // IN
501 SQLINTEGER TextLength) // IN
503 #ifdef DEBUG
504 printError(ErrWarning, "SQLExecDirect: %s", StatementText);
505 #endif
507 // Is Stmt valid ?
508 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
509 return( SQL_INVALID_HANDLE );
511 // Prepare
512 return( ((CSqlOdbcStmt*) StatementHandle)->SQLExecDirect( StatementText, TextLength ) );
515 SQLRETURN CSqlOdbcStmt::SQLExecDirect(
516 SQLCHAR *statementText, // IN
517 SQLINTEGER textLength) // IN
519 // Start with NO_ERR
520 err_.set( NO_ERR );
522 // Can we proceed ?
523 if( chkStateForSQLPrepare() != SQL_SUCCESS )
524 return( SQL_ERROR );
526 // Invalid Buffer Length.
527 if( textLength < 0 && textLength != SQL_NTS )
529 err_.set( ERROR_BUFLEN );
530 return( SQL_ERROR );
532 if (NULL == statementText)
534 err_.set(ERROR_INVARGVAL);
535 return (SQL_ERROR);
538 // If Stmt is already prepared.
539 if( state_ >= S2 ) {
540 resetStmt();
543 if (parentDbc_->mode_ ==1)
544 fsqlStmt_ = SqlFactory::createStatement(CSql);
545 else if (parentDbc_->mode_ ==2)
546 fsqlStmt_ = SqlFactory::createStatement(CSqlAdapter);
547 else if (parentDbc_->mode_ ==3)
548 fsqlStmt_ = SqlFactory::createStatement(CSqlGateway);
549 else if (parentDbc_->mode_ ==4)
550 fsqlStmt_ = SqlFactory::createStatement(CSqlNetwork);
551 else if (parentDbc_->mode_ ==5)
552 fsqlStmt_ = SqlFactory::createStatement(CSqlNetworkAdapter);
553 else if (parentDbc_->mode_ ==6)
554 fsqlStmt_ = SqlFactory::createStatement(CSqlNetworkGateway);
555 fsqlStmt_->setConnection( parentDbc_->fsqlConn_ );
556 // Prepare
557 //CSqlOdbcError::printDbg("proxy:stmt:prepare");
558 DbRetVal rv=OK;
559 if( (rv=fsqlStmt_->executeDirect( (char*) statementText ))!= OK) // CSQL
561 state_ = S1;
562 resetStmt();
563 //err_.set(ERROR_GENERAL);
564 switch(rv)
566 case ErrNotExists: err_.set( ERROR_TBLNOTFOUND); break;
567 case ErrNotFound: err_.set( ERROR_NO_COLEXISTS); break;
568 case ErrAlready: err_.set( ERROR_TBLEXISTS); break;
569 case ErrSyntaxError:err_.set(ERROR_SQL_SYNTAX);break;
570 case ErrSyntax:err_.set(ERROR_SQL_SYNTAX);break;
571 /*case csqlSqlErrSchNotFound: err_.set( ERROR_SCHNOTFOUND); break;
572 case csqlSqlErrIndexNotFound: err_.set( ERROR_NO_IDXEXISTS); break;
573 case csqlSqlErrViewNotFound: err_.set( ERROR_TBLNOTFOUND); break;
574 case csqlSqlErrFldExists: err_.set( ERROR_COLEXISTS); break;
575 case csqlSqlErrIndexExists: err_.set( ERROR_IDXEXISTS); break;
576 case csqlSqlErrViewExists: err_.set( ERROR_TBLEXISTS); break;
577 case csqlSqlErrTooManyVals:err_.set(ERROR_MANY_VALS);break;
578 case csqlSqlErrTooFewVals:err_.set(ERROR_FEW_VALS);break;
579 case csqlSqlErrIncompatibleType:err_.set(ERROR_TYPE_INCMP);break;
580 case csqlSqlErrInvalidFormat:err_.set(ERROR_DATA_FORMAT);break;
581 case csqlSqlErrDuplicateFld:err_.set(ERROR_DUP_COL);break;
582 case csqlSqlErrSqlInternal:err_.set(ERROR_SQL_INT);break;*/
583 default: err_.set(ERROR_GENERAL);
585 return( SQL_ERROR );
587 // Set Stmt State
588 if( fsqlStmt_->isSelect() )
590 rowsAffected_ = -1;
591 state_ = S5;
593 else
595 rowsAffected_ = 1; //TODO::It should get this from SqlStatement
596 state_ = S4;
598 // Set Dbc State to Transaction Mode.
599 parentDbc_->state_ = C6;
600 // AutoCommit Mode
601 if( parentDbc_->autoCommit_ == SQL_AUTOCOMMIT_ON )
602 parentDbc_->SQLEndTran( SQL_COMMIT );
604 isPrepared_ = true;
605 return( SQL_SUCCESS );
608 SQLRETURN SQLPrepare(
609 SQLHSTMT StatementHandle, // IN
610 SQLCHAR *StatementText, // IN
611 SQLINTEGER TextLength) // IN
613 #ifdef DEBUG
614 printError(ErrWarning, "SQLPrepare: %s", StatementText);
615 #endif
617 // Is Stmt valid ?
618 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
619 return( SQL_INVALID_HANDLE );
621 // Prepare
622 return( ((CSqlOdbcStmt*) StatementHandle)->SQLPrepare( StatementText, TextLength ) );
625 SQLRETURN CSqlOdbcStmt::SQLPrepare(
626 SQLCHAR *statementText, // IN
627 SQLINTEGER textLength) // IN
629 // Start with NO_ERR
630 err_.set( NO_ERR );
632 // Can we proceed ?
633 if( chkStateForSQLPrepare() != SQL_SUCCESS )
634 return( SQL_ERROR );
636 // Invalid Buffer Length.
637 if( textLength < 0 && textLength != SQL_NTS )
639 err_.set( ERROR_BUFLEN );
640 return( SQL_ERROR );
642 if (NULL == statementText)
644 err_.set(ERROR_INVARGVAL);
645 return (SQL_ERROR);
649 // If Stmt is already prepared.
650 if( state_ >= S2 ) {
651 resetStmt();
654 if (parentDbc_->mode_ ==1)
655 fsqlStmt_ = SqlFactory::createStatement(CSql);
656 else if (parentDbc_->mode_ ==2)
657 fsqlStmt_ = SqlFactory::createStatement(CSqlAdapter);
658 else if (parentDbc_->mode_ ==3)
659 fsqlStmt_ = SqlFactory::createStatement(CSqlGateway);
660 else if (parentDbc_->mode_ ==4)
661 fsqlStmt_ = SqlFactory::createStatement(CSqlNetwork);
662 else if (parentDbc_->mode_ ==5)
663 fsqlStmt_ = SqlFactory::createStatement(CSqlNetworkAdapter);
664 else if (parentDbc_->mode_ ==6)
665 fsqlStmt_ = SqlFactory::createStatement(CSqlNetworkGateway);
666 fsqlStmt_->setConnection( parentDbc_->fsqlConn_ );
667 // Prepare
668 //CSqlOdbcError::printDbg("proxy:stmt:prepare");
669 DbRetVal rv=OK;
670 if( (rv=fsqlStmt_->prepare( (char*) statementText ))!= OK) // CSQL
672 state_ = S1;
673 resetStmt();
674 //err_.set(ERROR_GENERAL);
675 switch(rv)
677 case ErrNotExists: err_.set( ERROR_TBLNOTFOUND); break;
678 case ErrNotFound: err_.set( ERROR_NO_COLEXISTS); break;
679 case ErrAlready: err_.set( ERROR_TBLEXISTS); break;
680 case ErrSyntaxError:err_.set(ERROR_SQL_SYNTAX);break;
681 case ErrSyntax:err_.set(ERROR_SQL_SYNTAX);break;
682 /*case csqlSqlErrSchNotFound: err_.set( ERROR_SCHNOTFOUND); break;
683 case csqlSqlErrIndexNotFound: err_.set( ERROR_NO_IDXEXISTS); break;
684 case csqlSqlErrViewNotFound: err_.set( ERROR_TBLNOTFOUND); break;
685 case csqlSqlErrFldExists: err_.set( ERROR_COLEXISTS); break;
686 case csqlSqlErrIndexExists: err_.set( ERROR_IDXEXISTS); break;
687 case csqlSqlErrViewExists: err_.set( ERROR_TBLEXISTS); break;
688 case csqlSqlErrTooManyVals:err_.set(ERROR_MANY_VALS);break;
689 case csqlSqlErrTooFewVals:err_.set(ERROR_FEW_VALS);break;
690 case csqlSqlErrIncompatibleType:err_.set(ERROR_TYPE_INCMP);break;
691 case csqlSqlErrInvalidFormat:err_.set(ERROR_DATA_FORMAT);break;
692 case csqlSqlErrDuplicateFld:err_.set(ERROR_DUP_COL);break;
693 case csqlSqlErrSqlInternal:err_.set(ERROR_SQL_INT);break;*/
694 default: err_.set(ERROR_GENERAL);
696 return( SQL_ERROR );
698 if( fsqlStmt_->isSelect() != true ) // CSQL
699 state_ = S2; // With cursor
700 else
701 state_ = S3; // Without cursor
703 //parentDbc_->state_ = C6;
704 isPrepared_ = true;
705 return( SQL_SUCCESS );
708 SQLRETURN SQLExecute(SQLHSTMT StatementHandle) // IN
710 #ifdef DEBUG
711 printError(ErrWarning, "SQLExecute");
712 #endif
714 // Is Stmt valid ?
715 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
716 return( SQL_INVALID_HANDLE );
718 return( ((CSqlOdbcStmt*) StatementHandle)->SQLExecute() );
721 SQLRETURN CSqlOdbcStmt::SQLExecute() // TODO
723 // Start with NO_ERR
724 err_.set( NO_ERR );
725 // Can we proceed ?
726 if( chkStateForSQLExecute() != SQL_SUCCESS )
727 return( SQL_ERROR );
729 if( fsqlStmt_->noOfParamFields() > 0 )
732 // Iterate through all apd_;
733 CSqlOdbcDesc *appParamDesc;
734 ListIterator apdIter = apd_.descList_.getIterator();
735 CSqlOdbcDesc *csqlParamDesc;
736 ListIterator ipdIter = ipd_.descList_.getIterator();
738 //Get the source and the destination type
739 DataType sourceType = typeUnknown,destType = typeUnknown;
740 int paramNum=1,sourceLength=-1,destLength=-1;
741 bool nullFlag=false;
743 while(apdIter.hasElement() || ipdIter.hasElement()) {
744 appParamDesc= (CSqlOdbcDesc *) apdIter.nextElement();
745 csqlParamDesc=(CSqlOdbcDesc *) ipdIter.nextElement();
746 if(paramNum <= fsqlStmt_->noOfParamFields())
748 if( fsqlStmt_->getParamFldInfo(paramNum, fInfo ) != OK ) return( SQL_ERROR );
749 sourceType=getCSqlType(appParamDesc->cType_);
750 destType=fInfo->type;
751 sourceLength=(int)appParamDesc->length_;
752 destLength=fInfo->length;
753 if(sourceType != typeUnknown && destType != typeUnknown)
755 //Check if NULL is inserted
756 if((appParamDesc->indPtr_ != NULL ) && (*(SQLINTEGER *)appParamDesc->indPtr_) == SQL_NULL_DATA)
758 fsqlStmt_->setNull(paramNum);
760 else
762 //Only if both types are not the same, then we need to copy it onto intermediate buffer
763 //Else no need
764 if( (sourceType == typeString || sourceType == typeBinary) && (sourceLength <= 0))
766 if((appParamDesc->indPtr_!= NULL) && *(SQLINTEGER *)appParamDesc->indPtr_ > 0)
767 sourceLength=(int)(*(SQLINTEGER *)appParamDesc->indPtr_);
768 else if (appParamDesc->precision_ > 0)
769 sourceLength=appParamDesc->precision_;
770 else
772 err_.set( ERROR_BUFLEN );
773 return SQL_ERROR;
776 if(destType == typeString) //|| destType == typeVarString)
778 //fsqlStmt_->allocParam(paramNum,sourceLength); // CSQL TODO
779 destLength=sourceLength;
781 if(sourceType == destType)
782 //|| (sourceType == typeString && destType == typeVarString)
783 //|| (sourceType == typeBinary && destType == typeVarBinary))
785 copyFromOdbc(fsqlStmt_, paramNum, destLength, appParamDesc->dataPtr_, sourceLength,destType); // CSQL TODO
786 } else
788 getInputBuffer(&csqlParamDesc->dataPtr_ ,destType,destLength);
789 convertFromOdbc(sourceType,appParamDesc->dataPtr_,destType,csqlParamDesc->dataPtr_, destLength);
790 copyFromOdbc(fsqlStmt_, paramNum, destLength, csqlParamDesc->dataPtr_, destLength, destType);
794 else
796 err_.set(ERROR_GENERAL);
797 return SQL_ERROR;
800 paramNum++;
805 // Get the result
806 int rowsAffected=0;
807 DbRetVal rv = fsqlStmt_->execute( rowsAffected );
809 if( rowsAffected < 0 || rv!=OK )
811 if( isPrepared_ ) state_ = S2; else resetStmt();
812 err_.set( ERROR_GENERAL );
813 /*switch(rv)
815 case csqlSqlErrOverflow:err_.set(ERROR_OVERFLOW);break;
816 case csqlSqlErrUnderflow:err_.set(ERROR_UNDERFLOW);break;
817 case csqlSqlErrTooManyTpl:err_.set(ERROR_MANY_TUP);break;
818 case csqlSqlErrProjCnt:err_.set(ERROR_NUM_PROJ);break;
819 case csqlSqlErrStorageAttr:err_.set(ERROR_STORAGE_ATTR);break;
820 case csqlSqlErrFldCntMismatch:err_.set(ERROR_FLDCNT_MISMATCH);break;
821 case csqlSqlErrSqlInternal:err_.set(ERROR_SQL_INT);break;
822 case csqlSqlErrNoMatchKeyFound:err_.set(ERROR_MATCHKEY_NOTFOUND);break;
823 default:
824 err_.set( ERROR_GENERAL );break;
825 } */
826 return( SQL_ERROR );
829 // Set Stmt State
830 if( fsqlStmt_->isSelect() == true )
832 rowsAffected_ = -1;
833 state_ = S5;
835 else
837 rowsAffected_ = rowsAffected;
838 state_ = S4;
841 // Set Dbc State to Transaction Mode.
842 parentDbc_->state_ = C6;
844 // AutoCommit Mode
845 if( parentDbc_->autoCommit_ == SQL_AUTOCOMMIT_ON )
846 parentDbc_->SQLEndTran( SQL_COMMIT );
848 return( SQL_SUCCESS );
851 SQLRETURN SQLExecDirect(
852 SQLHSTMT StatementHandle,
853 SQLCHAR *StatementText,
854 SQLINTEGER TextLength)
856 #ifdef DEBUG
857 printError(ErrWarning, "SQLExecDirect");
858 #endif
860 // Is Stmt valid ?
861 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
862 return( SQL_INVALID_HANDLE );
864 return( ((CSqlOdbcStmt*) StatementHandle)->SQLExecDirect( StatementText, TextLength ) );
867 SQLRETURN CSqlOdbcStmt::SQLExecDirect(
868 SQLCHAR *statementText,
869 SQLINTEGER textLength)
871 SQLRETURN ret;
873 // Can we proceed ?
874 if( chkStateForSQLExecDirect() != SQL_SUCCESS )
875 return( SQL_ERROR );
877 // SQLExecDirect = SQLPrepare + SQLExecute.
878 if( SQLPrepare( statementText, textLength ) != SQL_SUCCESS )
879 return( SQL_ERROR );
881 ret = SQLExecute();
882 isPrepared_ = false; // Set Stmt as non-prepared stmt.
884 if( ret != SQL_SUCCESS )
885 return( SQL_ERROR );
887 return( SQL_SUCCESS );
890 SQLRETURN SQLSetStmtOption(
891 SQLHSTMT StatementHandle,
892 SQLUSMALLINT Option,
893 SQLUINTEGER Value)
895 #ifdef DEBUG
896 printError(ErrWarning, "SQLSetStmtOption");
897 #endif
899 return (SQLSetStmtAttr(StatementHandle, Option, (SQLPOINTER) Value, 0));
902 SQLRETURN SQL_API SQLSetStmtAttr(SQLHSTMT StatementHandle,
903 SQLINTEGER Attribute, SQLPOINTER Value,
904 SQLINTEGER StringLength)
906 #ifdef DEBUG
907 printError(ErrWarning, "SQLSetStmtAttr");
908 #endif
910 return (((CSqlOdbcStmt*)StatementHandle)->SQLSetStmtAttr(Attribute, Value,StringLength));
913 SQLRETURN CSqlOdbcStmt::SQLSetStmtAttr(
914 SQLINTEGER Attribute,
915 SQLPOINTER Value,
916 SQLINTEGER stringLength)
918 CSqlOdbcError::printDbg("proxy:stmt:SQLSetStmtAttr");
919 //HACK
920 /*switch(Attribute)
922 //Values: SQL_FETCH_SINGLE_TUPLE or SQL_FETCH_MULTIPLE_TUPLES
923 //Default is SQL_FETCH_SINGLE_TUPLE.
924 //In SQL_FETCH_SINGLE_TUPLE mode, only a single tuple
925 //is sent from server to client in a single packet whatever be
926 //the packet size. If a tuple size is 50 and network packet size
927 //is 500, the remaining 450 bytes can also be used to send more
928 //in a single packet so that in the next SQLFetch call one network
929 //packet transfer overhead is reduced.
930 case SQL_FETCH_MODE:
931 if(state_ <= S5)
932 //state_ > S5 means Fetch has already started on this statement.
933 fetchMode_ = (SQLINTEGER)Value;
934 else
935 printf("ODBC:Error in setting fetch mode, can't set after fetch is started.\n");
936 break;
937 default:
938 printf("ODBC: Error, Stmt Option %d is not supported.\n", Attribute);
940 return (SQL_SUCCESS);
943 SQLRETURN SQLFetch(SQLHSTMT StatementHandle)
945 #ifdef DEBUG
946 printError(ErrWarning, "SQLFetch");
947 #endif
949 // Is Stmt valid ?
950 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
951 return( SQL_INVALID_HANDLE );
953 return( ((CSqlOdbcStmt*) StatementHandle)->SQLFetch() );
956 SQLRETURN CSqlOdbcStmt::SQLFetch()
958 // Start with NO_ERR
959 err_.set( NO_ERR );
961 // Can we proceed ?
962 if( chkStateForSQLFetch() != SQL_SUCCESS )
963 return( SQL_ERROR );
965 void *tuple;
966 tuple = fsqlStmt_->next();
968 if( ! tuple ) // IF Row not found.
970 rowsAffected_ = 0;
971 state_ = S6;
972 return( SQL_NO_DATA_FOUND );
974 /*else if( rowsAffected != SQL_SUCCESS ) // IF Error
976 rowsAffected_ = -1;
977 err_.set( ERROR_GENERAL );
978 return( SQL_ERROR );
980 else // IF Row found.
982 rowsAffected_ = 1;
983 if (ard_.descList_.size() > 0) {
984 // Iterate through all ard_;
985 CSqlOdbcDesc *appColDesc;
986 ListIterator ardIter = ard_.descList_.getIterator();
987 //Get the input parameter data
988 CSqlOdbcDesc *csqlColDesc;
989 ListIterator irdIter = ird_.descList_.getIterator();
991 DataType sourceType = typeUnknown,destType = typeUnknown;
992 int colNum=-1,sourceLength=-1,destLength=-1;
993 SQLINTEGER ind;
994 void* sourceData = NULL;
995 while(ardIter.hasElement() || irdIter.hasElement()) {
996 appColDesc = (CSqlOdbcDesc *) ardIter.nextElement();
997 csqlColDesc = (CSqlOdbcDesc *) irdIter.nextElement();
999 colNum = appColDesc->col_ - 1;
1000 sourceType = (DataType)csqlColDesc->cType_;
1001 destType = getCSqlType(appColDesc->cType_);
1002 sourceLength = (int)csqlColDesc->length_;
1003 destLength = (int)appColDesc->length_;
1004 if( sourceType != typeUnknown && destType != typeUnknown )
1006 sourceData = fsqlStmt_->getFieldValuePtr( colNum );
1007 if(fsqlStmt_->isFldNull((char*)csqlColDesc->colName_) ||
1008 sourceData == NULL )
1010 if (appColDesc->indPtr_ != NULL)
1011 *((SQLINTEGER *)(appColDesc->indPtr_))=SQL_NULL_DATA;
1013 else
1015 /*if( sourceType == csqlSqlTvarBinary)
1016 sourceLength=resultSet_->getDataLength(colNum); */
1017 if (sourceType == typeString ) // CSQL TODO - handle varchar also
1019 sourceLength=(int)(strlen((char *) sourceData ));
1020 if(appColDesc->indPtr_ != NULL)
1021 *((SQLINTEGER *)(appColDesc->indPtr_))=copyToOdbc(appColDesc->dataPtr_,destLength,
1022 sourceData,sourceLength, sourceType, destType);
1023 else
1024 copyToOdbc(appColDesc->dataPtr_,destLength,sourceData,
1025 sourceLength, sourceType, destType);
1027 else
1029 //convert(sourceType,sourceData,destType, csqlColDesc->dataPtr_,sourceLength,destLength);
1030 if(appColDesc->indPtr_ != NULL){
1031 *((SQLINTEGER *)(appColDesc->indPtr_))=
1032 copyToOdbc(appColDesc->dataPtr_,destLength, sourceData, sourceLength, sourceType, destType);
1034 else
1035 copyToOdbc(appColDesc->dataPtr_,destLength, sourceData, sourceLength, sourceType,destType);
1038 // CSQL TODO - handle varstring, binary, varbinary
1039 if( sourceType == typeString && sourceLength > destLength )
1040 err_.set( ERROR_DATATRUNC );
1045 state_ = S6;
1047 if(err_.csqlErrCode == ERROR_DATATRUNC)
1048 return (SQL_SUCCESS_WITH_INFO);
1050 return( SQL_SUCCESS );
1053 SQLRETURN SQLCloseCursor(SQLHSTMT StatementHandle)
1055 #ifdef DEBUG
1056 printError(ErrWarning, "SQLCloseCursor");
1057 #endif
1058 // Is Stmt valid ?
1059 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1060 return( SQL_INVALID_HANDLE );
1062 return( ((CSqlOdbcStmt*) StatementHandle)->SQLCloseCursor() );
1065 SQLRETURN CSqlOdbcStmt::SQLCloseCursor()
1067 // Start with NO_ERR
1068 err_.set( NO_ERR );
1070 // Can we proceed ?
1071 if( chkStateForSQLCloseCursor() != SQL_SUCCESS )
1072 return( SQL_ERROR );
1074 // Close the cursor
1075 fsqlStmt_->close();
1076 state_ = S3;
1077 return( SQL_SUCCESS );
1080 SQLRETURN SQLSetCursorName(
1081 SQLHSTMT StatementHandle,
1082 SQLCHAR *CursorName,
1083 SQLSMALLINT NameLength)
1085 #ifdef DEBUG
1086 printError(ErrWarning, "SQLSetCursorName");
1087 #endif
1088 // Is Stmt valid ?
1089 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1090 return( SQL_INVALID_HANDLE );
1092 return( ((CSqlOdbcStmt*) StatementHandle)->SQLSetCursorName( CursorName, NameLength ) );
1095 SQLRETURN CSqlOdbcStmt::SQLSetCursorName(
1096 SQLCHAR *cursorName,
1097 SQLSMALLINT nameLength)
1099 // Start with NO_ERR
1100 err_.set( NO_ERR );
1102 // Can we proceed ?
1103 if( chkStateForSQLSetCursorName() != SQL_SUCCESS )
1104 return( SQL_ERROR );
1106 // Invalid Stmt Length.
1107 if( nameLength < 0 && nameLength != SQL_NTS )
1109 err_.set( ERROR_INVARGVAL );
1110 return( SQL_ERROR );
1113 // Validate Parameters
1114 if( cursorName == 0 || cursorName[0] == '\0' || strlen( (char*) cursorName ) > SQL_MAX_CURSOR_NAME_LEN ||
1115 nameLength > SQL_MAX_CURSOR_NAME_LEN )
1117 err_.set( ERROR_CURNAME );
1118 return( SQL_ERROR );
1121 // Check for duplicate Name
1122 ListIterator iter = parentDbc_->stmtList_.getIterator();
1123 CSqlOdbcStmt *stmtElem = NULL;
1124 while (iter.hasElement()) {
1125 stmtElem = (CSqlOdbcStmt *) iter.nextElement();
1126 if(stmtElem != this ) {
1127 if( strcmp((char*)cursorName, (char*)stmtElem->cursorName_) == 0) {
1128 err_.set( ERROR_DUP_CURNAME );
1129 return( SQL_ERROR );
1133 // Copy name
1134 strcpy( (char*) cursorName_, (char*) cursorName );
1135 return( SQL_SUCCESS );
1138 SQLRETURN SQLGetCursorName(
1139 SQLHSTMT StatementHandle,
1140 SQLCHAR *CursorName,
1141 SQLSMALLINT BufferLength,
1142 SQLSMALLINT *NameLength)
1144 #ifdef DEBUG
1145 printError(ErrWarning, "SQLGetCursorName");
1146 #endif
1148 // Is Stmt valid ?
1149 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1150 return( SQL_INVALID_HANDLE );
1152 return( ((CSqlOdbcStmt*) StatementHandle)->SQLGetCursorName( CursorName, BufferLength, NameLength ) );
1154 SQLRETURN CSqlOdbcStmt::SQLGetCursorName(
1155 SQLCHAR *cursorName,
1156 SQLSMALLINT bufferLength,
1157 SQLSMALLINT *nameLength)
1159 // Can we proceed ?
1160 if( chkStateForSQLGetCursorName() != SQL_SUCCESS )
1161 return( SQL_ERROR );
1162 if (NULL == cursorName || NULL == nameLength)
1164 err_.set(ERROR_INVARGVAL);
1165 return (SQL_ERROR);
1168 if( cursorName_[0] == '\0' )
1170 err_.set( ERROR_NOCURNAME );
1171 return( SQL_ERROR );
1174 // Copy
1175 *nameLength = (short)strlen( (char*) cursorName_ );
1176 if( *nameLength > bufferLength ) *nameLength = bufferLength;
1177 strncpy( (char*) cursorName, (char*) cursorName_, *nameLength );
1178 cursorName[ *nameLength ] = '\0';
1180 // Did truncate ?
1181 if( bufferLength < strlen( (char*) cursorName_ ) )
1183 err_.set( ERROR_DATATRUNC );
1184 return( SQL_SUCCESS_WITH_INFO );
1187 return( SQL_SUCCESS );
1190 SQLRETURN SQLNumResultCols(
1191 SQLHSTMT StatementHandle, // IN
1192 SQLSMALLINT *ColumnCount) // OUT
1194 #ifdef DEBUG
1195 printError(ErrWarning, "SQLNumResultCols");
1196 #endif
1198 // Is Stmt valid ?
1199 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1200 return( SQL_INVALID_HANDLE );
1202 return( ((CSqlOdbcStmt*) StatementHandle)->SQLNumResultCols( ColumnCount ) );
1205 SQLRETURN CSqlOdbcStmt::SQLNumResultCols(
1206 SQLSMALLINT *columnCount) // OUT
1208 // Start with NO_ERR
1209 err_.set( NO_ERR );
1210 // Can we proceed ?
1211 if( chkStateForSQLNumResultCols() != SQL_SUCCESS )
1212 return( SQL_ERROR );
1213 if (NULL == columnCount)
1215 err_.set(ERROR_INVARGVAL);
1216 return (SQL_ERROR);
1219 // If DML
1220 if( fsqlStmt_->isSelect() == false )
1222 *columnCount=0;
1223 return (SQL_SUCCESS);
1225 ResultSetPlan pl = fsqlStmt_->getResultSetPlan();
1226 if(pl != Normal)
1228 *columnCount =getNumResultset(pl);
1229 return( SQL_SUCCESS );
1231 // If Select
1232 SQLSMALLINT count = fsqlStmt_->noOfProjFields();
1233 if( count < 1 ) // Assume atleast one column is projected
1234 return( SQL_ERROR );
1236 // Fill Column Count
1237 *columnCount = count;
1239 return( SQL_SUCCESS );
1242 SQLRETURN SQL_API SQLRowCount(
1243 SQLHSTMT StatementHandle, // IN
1244 SQLINTEGER *RowCount) // OUT
1246 #ifdef DEBUG
1247 printError(ErrWarning, "SQLRowCount");
1248 #endif
1250 // Is Stmt valid ?
1251 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1252 return( SQL_INVALID_HANDLE );
1254 return( ((CSqlOdbcStmt*) StatementHandle)->SQLRowCount( RowCount ) );
1257 SQLRETURN CSqlOdbcStmt::SQLRowCount(
1258 SQLINTEGER *rowCount) // OUT
1259 { // TODO
1260 // Start with NO_ERR
1261 err_.set( NO_ERR );
1263 // Can we proceed ?
1264 if( chkStateForSQLRowCount() != SQL_SUCCESS )
1265 return( SQL_ERROR );
1267 if(rowCount == NULL)
1268 return SQL_SUCCESS;
1270 if( state_ == S4 ) // For INSERT/DELETE/UPDATE
1271 *rowCount = (SQLINTEGER) rowsAffected_;
1272 else if( state_ == S5 ) // For SELECT before SQLFetch()
1274 *rowCount = (SQLINTEGER) 0;
1275 // CSQL TODO - Think if you really want to do this!!!
1277 /*CSqlOdbcError::printDbg("proxy:stmt:getResultSet");
1278 CSqlResultSet *resultSet_ = fsqlStmt_.getResultSet();
1279 if( resultSet_->next() != csqlSqlErrNoTuple )
1280 *rowCount = (SQLINTEGER) 1;
1282 resultSet_->close();
1283 resultSet_->open(); */
1285 else if( state_ == S6 ) // For SELECT after SQLFetch();
1286 *rowCount = (SQLINTEGER) rowsAffected_;
1288 return( SQL_SUCCESS );
1291 SQLRETURN SQLDescribeCol(
1292 SQLHSTMT StatementHandle,
1293 SQLUSMALLINT ColumnNumber,
1294 SQLCHAR *ColumnName,
1295 SQLSMALLINT BufferLength,
1296 SQLSMALLINT *NameLength,
1297 SQLSMALLINT *DataType,
1298 SQLUINTEGER *ColumnSize,
1299 SQLSMALLINT *DecimalDigits,
1300 SQLSMALLINT *Nullable)
1302 #ifdef DEBUG
1303 printError(ErrWarning, "SQLDescribeCol");
1304 #endif
1306 // Is Stmt valid ?
1307 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1308 return( SQL_INVALID_HANDLE );
1310 return( ((CSqlOdbcStmt*) StatementHandle)->SQLDescribeCol( ColumnNumber, ColumnName, BufferLength,
1311 NameLength, DataType, ColumnSize, DecimalDigits, Nullable) );
1314 SQLRETURN CSqlOdbcStmt::SQLDescribeCol(
1315 SQLUSMALLINT columnNumber,
1316 SQLCHAR *columnName,
1317 SQLSMALLINT bufferLength,
1318 SQLSMALLINT *nameLength,
1319 SQLSMALLINT *dataType,
1320 SQLUINTEGER *columnSize,
1321 SQLSMALLINT *decimalDigits,
1322 SQLSMALLINT *nullable)
1324 int nameLen;
1325 int type;
1326 int colSize;
1327 int deciDigits;
1328 int isNullable;
1330 // Start with NO_ERR
1331 err_.set( NO_ERR );
1332 // Can we proceed ?
1333 if( chkStateForSQLDescribeCol() != SQL_SUCCESS )
1334 return( SQL_ERROR );
1336 if( columnNumber < 1 )
1338 err_.set( ERROR_COLNUM );
1339 return( SQL_ERROR );
1342 if(columnName == NULL) {
1343 err_.set( ERROR_INVARGVAL );
1344 return( SQL_ERROR );
1347 DbRetVal rv = fsqlStmt_->getProjFldInfo(columnNumber, fInfo);
1348 if (rv != OK) {
1349 err_.set( ERROR_COLNUM );
1350 return( SQL_ERROR );
1352 if (bufferLength <IDENTIFIER_LENGTH) {
1353 //strncpy( (char*)columnName, (char*)fInfo->fldName, bufferLength );
1354 //columnName[bufferLength-1] ='\0';
1355 err_.set (ERROR_BUFLEN);
1356 return (SQL_ERROR);
1357 }else {
1358 Table::getFieldNameAlone((char*)fInfo->fldName, (char*)columnName);
1361 if(nameLength != NULL)
1362 *nameLength=(short)strlen((const char*)columnName); // HARDCODED - TO DO, need support for n/w layer & sql layer
1363 if(dataType != NULL)
1364 *dataType = (SQLSMALLINT) getSQLType(fInfo->type); // Need to convert from SQL<->ODBC - TO DO
1365 if(columnSize != NULL)
1367 *columnSize = (SQLUINTEGER) fInfo->length;
1368 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1369 if(sqlType == SQL_CHAR )
1370 *columnSize = *columnSize -1;
1373 /*if(decimalDigits != NULL) // CSQL TODO
1374 *decimalDigits = (SQLSMALLINT) fsqlStmt_->getPrecision( columnNumber-1 );*/
1375 if (decimalDigits !=NULL) *decimalDigits = 0;
1376 if(nullable != NULL)
1378 if (fInfo->isNull)
1379 *nullable = SQL_NO_NULLS ;
1380 else
1381 *nullable = SQL_NULLABLE ;
1383 return( SQL_SUCCESS );
1386 SQLRETURN SQLColAttributes(
1387 SQLHSTMT StatementHandle,
1388 SQLUSMALLINT ColumnNumber,
1389 SQLUSMALLINT FieldIdentifier,
1390 SQLPOINTER CharacterAttributePtr,
1391 SQLSMALLINT BufferLength,
1392 SQLSMALLINT *StringLengthPtr,
1393 SQLINTEGER *NumericAttributePtr)
1395 #ifdef DEBUG
1396 printError(ErrWarning, "SQLColAttributes");
1397 #endif
1399 // Is Stmt valid ?
1400 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1401 return( SQL_INVALID_HANDLE );
1403 return( ((CSqlOdbcStmt*) StatementHandle)->SQLColAttribute(ColumnNumber ,FieldIdentifier ,
1404 CharacterAttributePtr, BufferLength, StringLengthPtr, (SQLPOINTER)NumericAttributePtr) );
1407 SQLRETURN SQLColAttribute(
1408 SQLHSTMT StatementHandle,
1409 SQLUSMALLINT ColumnNumber,
1410 SQLUSMALLINT FieldIdentifier,
1411 SQLPOINTER CharacterAttributePtr,
1412 SQLSMALLINT BufferLength,
1413 SQLSMALLINT * StringLengthPtr,
1414 SQLPOINTER NumericAttributePtr)
1416 #ifdef DEBUG
1417 printError(ErrWarning, "SQLColAttribute");
1418 #endif
1420 // Is Stmt valid ?
1421 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1422 return( SQL_INVALID_HANDLE );
1424 return( ((CSqlOdbcStmt*) StatementHandle)->SQLColAttribute(ColumnNumber ,FieldIdentifier ,
1425 CharacterAttributePtr, BufferLength, StringLengthPtr, NumericAttributePtr) );
1428 SQLRETURN CSqlOdbcStmt::SQLColAttribute(
1429 SQLUSMALLINT columnNumber,
1430 SQLUSMALLINT fieldIdentifier,
1431 SQLPOINTER characterAttributePtr,
1432 SQLSMALLINT bufferLength,
1433 SQLSMALLINT * stringLengthPtr,
1434 SQLPOINTER numericAttributePtr)
1436 int nameLen;
1437 int type;
1438 int colSize;
1439 int deciDigits;
1440 int isNullable;
1442 // Start with NO_ERR
1443 err_.set( NO_ERR );
1445 // Can we proceed ?
1446 if( chkStateForSQLDescribeCol() != SQL_SUCCESS )
1447 return( SQL_ERROR );
1449 if( columnNumber < 1 )
1451 err_.set( ERROR_COLNUM );
1452 return( SQL_ERROR );
1454 // If DML
1455 if( fsqlStmt_->isSelect() == false )
1456 return( SQL_ERROR );
1458 fsqlStmt_->getProjFldInfo(columnNumber, fInfo);
1460 // If SELECT
1461 if(columnNumber > fsqlStmt_->noOfProjFields())
1463 err_.set( ERROR_COLNUM );
1464 return( SQL_ERROR );
1467 switch(fieldIdentifier)
1469 case SQL_DESC_NAME:
1470 case SQL_COLUMN_LABEL:
1471 case SQL_COLUMN_NAME:
1472 if(characterAttributePtr != NULL)
1474 strncpy( (char*)characterAttributePtr, (char*)fInfo->fldName, bufferLength);
1475 if(stringLengthPtr != NULL)
1476 *stringLengthPtr=(short)strlen((char*)fInfo->fldName);
1478 break;
1479 case SQL_DESC_COUNT:
1480 case SQL_COLUMN_COUNT:
1481 if(numericAttributePtr != NULL)
1482 *(SQLINTEGER*)numericAttributePtr=fsqlStmt_->noOfProjFields();
1483 break;
1484 case SQL_DESC_TYPE:
1485 case SQL_COLUMN_TYPE:
1486 if(numericAttributePtr != NULL)
1487 *(SQLINTEGER *)numericAttributePtr=getSQLType(fInfo->type);
1488 break;
1489 case SQL_DESC_LENGTH:
1490 case SQL_COLUMN_LENGTH:
1491 if(numericAttributePtr != NULL)
1493 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1494 *(SQLINTEGER *)numericAttributePtr=(SQLUINTEGER) fInfo->length;
1495 if(sqlType == SQL_CHAR)
1496 *(SQLINTEGER *)numericAttributePtr=*(SQLINTEGER *)numericAttributePtr -1;
1498 break;
1499 case SQL_DESC_PRECISION:
1500 case SQL_COLUMN_PRECISION:
1501 /*if(numericAttributePtr != NULL) // CSQL TODO
1502 *(SQLINTEGER *)numericAttributePtr=(SQLSMALLINT) rsMetaData->getPrecision( columnNumber-1 ); */
1503 break;
1504 case SQL_DESC_SCALE:
1505 case SQL_COLUMN_SCALE:
1506 /*if(numericAttributePtr != NULL) // CSQL TODO
1507 *(SQLINTEGER*)numericAttributePtr=(SQLSMALLINT) rsMetaData->getScale( columnNumber-1 );*/
1508 break;
1509 case SQL_DESC_NULLABLE:
1510 case SQL_COLUMN_NULLABLE:
1511 /*if(numericAttributePtr != NULL) // CSQL TODO
1512 *(SQLINTEGER*)numericAttributePtr=(SQLSMALLINT) rsMetaData->isNullable( columnNumber-1 )?SQL_NULLABLE_N:SQL_NO_NULLS_N;*/
1513 break;
1514 case SQL_DESC_UNSIGNED:
1515 if(numericAttributePtr != NULL)
1517 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1518 if((sqlType != SQL_TIME) && (sqlType != SQL_DATE) && (sqlType != SQL_TIMESTAMP)
1519 && (sqlType != SQL_CHAR) && (sqlType != SQL_VARCHAR) && (sqlType != SQL_BINARY)
1520 && (sqlType != SQL_VARBINARY) && (sqlType != SQL_BIT))
1521 *(SQLINTEGER*)numericAttributePtr=SQL_FALSE;
1522 else
1523 *(SQLINTEGER*)numericAttributePtr=SQL_TRUE;
1525 break;
1526 case SQL_DESC_FIXED_PREC_SCALE:
1527 if(numericAttributePtr != NULL)
1528 *(SQLINTEGER*)numericAttributePtr=SQL_FALSE;
1529 break;
1530 case SQL_DESC_TYPE_NAME:
1531 if(characterAttributePtr != NULL)
1533 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1534 strncpy((char*)characterAttributePtr,(char *)(getSQLTypeName(sqlType)),bufferLength);
1535 if(stringLengthPtr != NULL)
1536 *stringLengthPtr=(int)strlen((char *)getSQLTypeName(sqlType));
1538 break;
1539 case SQL_DESC_UPDATABLE:
1540 if(numericAttributePtr != NULL)
1541 *(SQLINTEGER*)numericAttributePtr=SQL_ATTR_READWRITE_UNKNOWN;
1542 break;
1543 case SQL_DESC_AUTO_UNIQUE_VALUE:
1544 if(numericAttributePtr != NULL)
1545 *(SQLINTEGER*)numericAttributePtr=SQL_FALSE;
1546 break;
1547 case SQL_DESC_CASE_SENSITIVE:
1548 if(numericAttributePtr != NULL)
1550 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1551 if((sqlType != SQL_CHAR) && (sqlType != SQL_VARCHAR))
1552 *(SQLINTEGER*)numericAttributePtr=SQL_FALSE;
1553 else
1554 *(SQLINTEGER*)numericAttributePtr=SQL_TRUE;
1556 break;
1557 case SQL_DESC_SEARCHABLE:
1558 if(numericAttributePtr != NULL)
1560 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1561 if((sqlType != SQL_CHAR) && (sqlType != SQL_VARCHAR))
1562 *(SQLINTEGER*)numericAttributePtr=SQL_PRED_BASIC;
1563 else
1564 *(SQLINTEGER*)numericAttributePtr=SQL_PRED_SEARCHABLE;
1566 break;
1567 case SQL_COLUMN_DISPLAY_SIZE: {
1568 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1569 if(numericAttributePtr != NULL) {
1570 if(sqlType == SQL_CHAR || sqlType == SQL_BINARY)
1571 *(SQLINTEGER *)numericAttributePtr=fInfo->length;
1572 else
1573 *(SQLINTEGER *)numericAttributePtr=20;
1575 break;
1577 default:
1578 break;
1580 if(stringLengthPtr != NULL)
1582 if(*stringLengthPtr > bufferLength)
1584 err_.set( ERROR_DATATRUNC );
1585 return( SQL_SUCCESS_WITH_INFO );
1588 return( SQL_SUCCESS );
1591 SQLRETURN SQLNumParams(
1592 SQLHSTMT StatementHandle,
1593 SQLSMALLINT * ParameterCountPtr)
1595 #ifdef DEBUG
1596 printError(ErrWarning, "SQLNumParams");
1597 #endif
1599 // Is Stmt valid ?
1600 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1601 return( SQL_INVALID_HANDLE );
1603 return( ((CSqlOdbcStmt*) StatementHandle)->SQLNumParams(ParameterCountPtr) );
1606 SQLRETURN CSqlOdbcStmt::SQLNumParams(
1607 SQLSMALLINT * ParameterCount)
1609 // Start with NO_ERR
1610 err_.set( NO_ERR );
1611 // Can we proceed ?
1612 if( chkStateForSQLNumParams() != SQL_SUCCESS )
1613 return( SQL_ERROR );
1614 if(ParameterCount == NULL)
1615 return (SQL_ERROR);
1616 *ParameterCount=fsqlStmt_->noOfParamFields();
1618 return SQL_SUCCESS;
1621 SQLRETURN SQLDescribeParam(
1622 SQLHSTMT StatementHandle,
1623 SQLUSMALLINT ParameterNumber,
1624 SQLSMALLINT * DataTypePtr,
1625 SQLUINTEGER * ParameterSizePtr,
1626 SQLSMALLINT * DecimalDigitsPtr,
1627 SQLSMALLINT * NullablePtr)
1629 #ifdef DEBUG
1630 printError(ErrWarning, "SQLDescribeParam");
1631 #endif
1633 // Is Stmt valid ?
1634 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1635 return( SQL_INVALID_HANDLE );
1637 return( ((CSqlOdbcStmt*) StatementHandle)->SQLDescribeParam(ParameterNumber,DataTypePtr,
1638 ParameterSizePtr,DecimalDigitsPtr,NullablePtr ) );
1640 SQLRETURN CSqlOdbcStmt::SQLDescribeParam(
1641 SQLUSMALLINT paramNumber,
1642 SQLSMALLINT * dataType,
1643 SQLUINTEGER * paramSize,
1644 SQLSMALLINT * decimalDigits,
1645 SQLSMALLINT * isNullable)
1648 // Start with NO_ERR
1649 err_.set( NO_ERR );
1651 // Can we proceed ?
1652 if( chkStateForSQLDescribeParam() != SQL_SUCCESS )
1653 return( SQL_ERROR );
1655 if( paramNumber < 1 )
1657 err_.set( ERROR_PARAMNUM);
1658 return( SQL_ERROR );
1661 //CSqlOdbcError::printDbg("proxy:stmt:getMetaData");
1662 //CSqlParamMetaData *paramMetaData = fsqlStmt_->getParamMetaData();
1663 if(paramNumber > fsqlStmt_->noOfParamFields())
1665 err_.set( ERROR_PARAMNUM );
1666 return( SQL_ERROR );
1669 if( fsqlStmt_->getParamFldInfo( paramNumber, fInfo ) != OK ) {
1670 return( SQL_ERROR );
1672 if(dataType != NULL)
1673 *dataType = (SQLSMALLINT) getSQLType(fInfo->type);
1674 if(paramSize != NULL)
1676 *paramSize = (SQLUINTEGER) fInfo->length;
1677 SQLSMALLINT sqlType=getSQLType(fInfo->type);
1678 if(sqlType == SQL_CHAR )
1679 *paramSize= *paramSize -1;
1681 /*if(decimalDigits != NULL) // CSQL TODO
1682 *decimalDigits = (SQLSMALLINT) paramMetaData->getPrecision( paramNumber-1 );*/
1683 if (NULL != decimalDigits) *decimalDigits = 0;
1684 if(isNullable) {
1685 if (fInfo->isNull)
1686 *isNullable = SQL_NO_NULLS ;
1687 else
1688 *isNullable = SQL_NULLABLE ;
1691 return( SQL_SUCCESS );
1694 // Resets the Stmt to initial state. As if newly allocated.
1695 void CSqlOdbcStmt::resetStmt( void ) // TO DO
1697 SQLFreeStmt( SQL_CLOSE );
1698 SQLFreeStmt( SQL_UNBIND );
1699 SQLFreeStmt( SQL_RESET_PARAMS );
1700 if (fsqlStmt_) { fsqlStmt_->free(); delete fsqlStmt_; fsqlStmt_ = NULL; }
1701 isPrepared_ = false;
1702 state_ = S1;
1705 SQLRETURN SQLTables(
1706 SQLHSTMT StatementHandle,
1707 SQLCHAR * CatalogName,
1708 SQLSMALLINT NameLength1,
1709 SQLCHAR * SchemaName,
1710 SQLSMALLINT NameLength2,
1711 SQLCHAR * TableName,
1712 SQLSMALLINT NameLength3,
1713 SQLCHAR * TableType,
1714 SQLSMALLINT NameLength4)
1716 #ifdef DEBUG
1717 printError(ErrWarning, "SQLTables");
1718 #endif
1720 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1721 return( SQL_INVALID_HANDLE );
1723 return( ((CSqlOdbcStmt*) StatementHandle)->SQLTables(CatalogName,SchemaName,TableName,TableType ) );
1726 SQLRETURN CSqlOdbcStmt::SQLTables(
1727 SQLCHAR * CatalogName,
1728 SQLCHAR * SchemaName,
1729 SQLCHAR * TableName,
1730 SQLCHAR * TableType )
1732 // Start with NO_ERR
1733 err_.set( NO_ERR );
1734 SQLRETURN ret = SQL_SUCCESS;
1735 ret = SQLPrepare((SQLCHAR *)"GetAllTables", strlen("GetAllTables"));
1736 if( ret != SQL_SUCCESS ) return (ret);
1737 ret = SQLExecute();
1738 if( ret != SQL_SUCCESS ) return (ret);
1739 return( SQL_SUCCESS );
1743 SQLRETURN SQLColumns(
1744 SQLHSTMT StatementHandle,
1745 SQLCHAR * CatalogName,
1746 SQLSMALLINT NameLength1,
1747 SQLCHAR * SchemaName,
1748 SQLSMALLINT NameLength2,
1749 SQLCHAR * TableName,
1750 SQLSMALLINT NameLength3,
1751 SQLCHAR * ColumnName,
1752 SQLSMALLINT NameLength4)
1754 #ifdef DEBUG
1755 printError(ErrWarning, "SQLColumns");
1756 #endif
1758 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1759 return( SQL_INVALID_HANDLE );
1761 return( ((CSqlOdbcStmt*) StatementHandle)->SQLColumns(CatalogName,SchemaName,TableName,ColumnName ) );
1765 SQLRETURN CSqlOdbcStmt::SQLColumns(
1766 SQLCHAR * CatalogName,
1767 SQLCHAR * SchemaName,
1768 SQLCHAR * TableName,
1769 SQLCHAR * ColumnName )
1771 SQLRETURN ret = SQL_SUCCESS;
1772 if (NULL == TableName)
1774 err_.set(ERROR_INVARGVAL);
1775 return (SQL_ERROR);
1777 char str[256]="describe ";
1778 strcat(str,(char*)TableName);
1779 ret = SQLPrepare((SQLCHAR *)str, strlen(str));
1780 if( ret != SQL_SUCCESS ) return (ret);
1781 ret = SQLExecute();
1782 if( ret != SQL_SUCCESS ) return (ret);
1783 return( SQL_SUCCESS );
1786 SQLRETURN SQLPrimaryKeys(
1787 SQLHSTMT StatementHandle,
1788 SQLCHAR * CatalogName,
1789 SQLSMALLINT NameLength1,
1790 SQLCHAR * SchemaName,
1791 SQLSMALLINT NameLength2,
1792 SQLCHAR * TableName,
1793 SQLSMALLINT NameLength3)
1795 #ifdef DEBUG
1796 printError(ErrWarning, "SQLPrimaryKeys");
1797 #endif
1799 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1800 return( SQL_INVALID_HANDLE );
1802 return( ((CSqlOdbcStmt*) StatementHandle)->SQLPrimaryKeys(CatalogName,SchemaName,TableName ) );
1805 SQLRETURN CSqlOdbcStmt::SQLPrimaryKeys(
1806 SQLCHAR * CatalogName,
1807 SQLCHAR * SchemaName,
1808 SQLCHAR * TableName)
1810 SQLRETURN ret = SQL_SUCCESS;
1811 char str[256]="getprimarykey ";
1812 if (NULL == TableName)
1814 err_.set(ERROR_INVARGVAL);
1815 return (SQL_ERROR);
1817 strcat(str,(char*)TableName);
1818 ret = SQLPrepare((SQLCHAR *)str, strlen(str));
1819 if( ret != SQL_SUCCESS ) return (ret);
1820 ret = SQLExecute();
1821 if( ret != SQL_SUCCESS ) return (ret);
1822 return( SQL_SUCCESS );
1825 int CSqlOdbcStmt::getNumResultset(ResultSetPlan plan)
1827 switch(plan)
1829 case GetTables:
1830 return 5;
1831 case GetColumns:
1832 return 18;
1833 case GetIndexes:
1834 return 13;
1835 case GetPriIndex:
1836 return 6;
1837 default :
1838 break;
1842 SQLRETURN SQLGetData(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValuePtr, SQLLEN BufferLength, SQLLEN * StrLen_or_IndPtr)
1844 #ifdef DEBUG
1845 printError(ErrWarning, "SQLGetData");
1846 #endif
1848 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1849 return( SQL_INVALID_HANDLE );
1851 return( ((CSqlOdbcStmt*) StatementHandle)->SQLGetData(ColumnNumber,TargetType,TargetValuePtr,BufferLength,StrLen_or_IndPtr) );
1855 SQLRETURN CSqlOdbcStmt::SQLGetData(SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValuePtr,SQLLEN BufferLength, SQLLEN * StrLen_or_IndPtr)
1857 if(fsqlStmt_->isFldNull(ColumnNumber)){
1858 if(NULL != StrLen_or_IndPtr)
1859 *((SQLINTEGER *)StrLen_or_IndPtr ) = SQL_NULL_DATA;
1860 return (SQL_SUCCESS);
1862 if (NULL == TargetValuePtr)
1864 err_.set(ERROR_INVARGVAL);
1865 return (SQL_ERROR);
1867 void* sourceData = NULL;
1868 DataType sourceType = typeUnknown, destType = typeUnknown;
1869 DbRetVal rv = fsqlStmt_->getProjFldInfo(ColumnNumber, fInfo);
1870 if (rv != OK) {
1871 return SQL_INVALID_HANDLE;
1873 sourceType = fInfo->type;
1874 sourceData = fsqlStmt_->getFieldValuePtr(ColumnNumber-1);
1875 destType = getCSqlType( TargetType );
1876 int sourceLength=-1;
1877 if(sourceType == typeString)
1879 sourceLength=strlen((char *)sourceData);
1880 if (NULL != StrLen_or_IndPtr)
1881 *((SQLINTEGER *)StrLen_or_IndPtr) = copyToOdbc(TargetValuePtr,
1882 BufferLength,sourceData,sourceLength,sourceType,destType);
1883 } else
1885 copyToOdbc(TargetValuePtr,BufferLength,sourceData,sourceLength,sourceType,destType);
1887 return (SQL_SUCCESS);
1891 SQLRETURN SQLGetTypeInfo(
1892 SQLHSTMT StatementHandle,
1893 SQLSMALLINT DataType)
1895 #ifdef DEBUG
1896 printError(ErrWarning, "SQLGetTypeInfo");
1897 #endif
1899 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1900 return( SQL_INVALID_HANDLE );
1902 return( ((CSqlOdbcStmt*) StatementHandle)->SQLGetTypeInfo(DataType));
1905 SQLRETURN CSqlOdbcStmt::SQLGetTypeInfo(SQLSMALLINT DataType)
1907 return (SQL_SUCCESS);
1911 SQLRETURN SQLStatistics(
1912 SQLHSTMT StatementHandle,
1913 SQLCHAR * CatalogName,
1914 SQLSMALLINT NameLength1,
1915 SQLCHAR * SchemaName,
1916 SQLSMALLINT NameLength2,
1917 SQLCHAR * TableName,
1918 SQLSMALLINT NameLength3,
1919 SQLUSMALLINT Unique,
1920 SQLUSMALLINT Reserved)
1922 #ifdef DEBUG
1923 printError(ErrWarning, "SQLStatistics");
1924 #endif
1926 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1927 return( SQL_INVALID_HANDLE );
1929 return( ((CSqlOdbcStmt*) StatementHandle)->SQLStatistics(CatalogName,SchemaName,TableName,Unique,Reserved));
1932 SQLRETURN CSqlOdbcStmt::SQLStatistics(
1933 SQLCHAR * CatalogName,
1934 SQLCHAR * SchemaName,
1935 SQLCHAR * TableName,
1936 SQLUSMALLINT Unique,
1937 SQLUSMALLINT Reserved)
1939 SQLRETURN ret = SQL_SUCCESS;
1940 if(Unique != SQL_INDEX_ALL ) { printf("NOT SUPPORTED "); return (SQL_ERROR);}
1941 if (NULL == TableName)
1943 err_.set(ERROR_INVARGVAL);
1944 return (SQL_ERROR);
1947 char str[256]="describe index ";
1948 strcat(str,(char*)TableName);
1949 ret = SQLPrepare((SQLCHAR *)str, strlen(str));
1950 if( ret != SQL_SUCCESS ) return (ret);
1951 ret = SQLExecute();
1952 if( ret != SQL_SUCCESS ) return (ret);
1953 return( SQL_SUCCESS );
1956 SQLRETURN SQLForeignKeys(
1957 SQLHSTMT StatementHandle,
1958 SQLCHAR * PKCatalogName,
1959 SQLSMALLINT NameLength1,
1960 SQLCHAR * PKSchemaName,
1961 SQLSMALLINT NameLength2,
1962 SQLCHAR * PKTableName,
1963 SQLSMALLINT NameLength3,
1964 SQLCHAR * FKCatalogName,
1965 SQLSMALLINT NameLength4,
1966 SQLCHAR * FKSchemaName,
1967 SQLSMALLINT NameLength5,
1968 SQLCHAR * FKTableName,
1969 SQLSMALLINT NameLength6)
1971 #ifdef DEBUG
1972 printError(ErrWarning, "SQLForeignKeys");
1973 #endif
1974 if( PKCatalogName!=NULL || FKCatalogName!=NULL ){
1975 if(strcmp((char*)PKCatalogName,"csql")!=0 || strcmp((char*)PKCatalogName,"csql")!=0){
1976 //error
1977 printf("Error\n");
1980 if( isValidHandle( (CSqlOdbcStmt*) StatementHandle, SQL_HANDLE_STMT ) != SQL_SUCCESS )
1981 return( SQL_INVALID_HANDLE );
1983 return( ((CSqlOdbcStmt*) StatementHandle)->SQLForeignKeys(PKTableName, FKTableName));
1986 SQLRETURN CSqlOdbcStmt::SQLForeignKeys(
1987 SQLCHAR * PKTableName,
1988 SQLCHAR * FKTableName)
1990 SQLRETURN ret = SQL_SUCCESS;
1991 if(PKTableName!=NULL && FKTableName!=NULL) {
1992 printf("NOT SUPPORTED ");
1993 return (SQL_ERROR);
1995 char str[256];
1996 if(PKTableName!=NULL && FKTableName==NULL){
1997 sprintf(str,"ExportedKey %s;",(char*)PKTableName);
1999 else if(NULL == PKTableName && FKTableName!=NULL){
2000 sprintf(str,"ImportedKey %s;",(char*)FKTableName);
2002 ret = SQLPrepare((SQLCHAR *)str, strlen(str));
2003 if( ret != SQL_SUCCESS ) return (ret);
2004 ret = SQLExecute();
2005 if( ret != SQL_SUCCESS ) return (ret);
2006 return( SQL_SUCCESS );