00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "icatLowLevelOdbc.h"
00032 int _cllFreeStatementColumns(icatSessionStruct *icss, int statementNumber);
00033
00034 int
00035 _cllExecSqlNoResult(icatSessionStruct *icss, char *sql, int option);
00036
00037
00038 int cllBindVarCount=0;
00039 char *cllBindVars[MAX_BIND_VARS];
00040 int cllBindVarCountPrev=0;
00041
00042 SQLCHAR psgErrorMsg[SQL_MAX_MESSAGE_LENGTH + 10];
00043
00044 #ifdef ADDR_64BITS
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define SQL_INT_OR_LEN SQLLEN
00054 #define SQL_UINT_OR_ULEN SQLULEN
00055 #else
00056 #define SQL_INT_OR_LEN SQLINTEGER
00057 #define SQL_UINT_OR_ULEN SQLUINTEGER
00058 #endif
00059
00060
00061 #define MAX_TOKEN 256
00062
00063 #define TMP_STR_LEN 1040
00064
00065 SQLINTEGER columnLength[MAX_TOKEN];
00066
00067 #include <stdio.h>
00068 #include <pwd.h>
00069 #include <ctype.h>
00070
00071 static int didBegin=0;
00072
00073
00074
00075
00076
00077 static const short MAX_NUMBER_ICAT_COLUMS = 32;
00078 static SQLLEN resultDataSizeArray[ MAX_NUMBER_ICAT_COLUMS ];
00079
00080
00081
00082
00083
00084 int
00085 logPsgError(int level, HENV henv, HDBC hdbc, HSTMT hstmt, int dbType)
00086 {
00087 SQLCHAR sqlstate[ SQL_SQLSTATE_SIZE + 10];
00088 SQLINTEGER sqlcode;
00089 SQLSMALLINT length;
00090 int errorVal=-2;
00091 while (SQLError(henv, hdbc, hstmt, sqlstate, &sqlcode, psgErrorMsg,
00092 SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS) {
00093 if (dbType == DB_TYPE_MYSQL) {
00094 if (strcmp((char *)sqlstate,"23000") == 0 &&
00095 strstr((char *)psgErrorMsg, "Duplicate entry")) {
00096 errorVal = CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
00097 }
00098 }
00099 else {
00100 if (strstr((char *)psgErrorMsg, "duplicate key")) {
00101 errorVal = CATALOG_ALREADY_HAS_ITEM_BY_THAT_NAME;
00102 }
00103 }
00104 rodsLog(level,"SQLSTATE: %s", sqlstate);
00105 rodsLog(level,"SQLCODE: %ld", sqlcode);
00106 rodsLog(level,"SQL Error message: %s", psgErrorMsg);
00107 }
00108 return(errorVal);
00109 }
00110
00111 int
00112 cllGetLastErrorMessage(char *msg, int maxChars) {
00113 strncpy(msg, (char *)&psgErrorMsg, maxChars);
00114 return(0);
00115 }
00116
00117
00118
00119
00120 int
00121 cllOpenEnv(icatSessionStruct *icss) {
00122 RETCODE stat;
00123
00124 HENV myHenv;
00125 stat = SQLAllocEnv(&myHenv);
00126
00127 if (stat != SQL_SUCCESS) {
00128 rodsLog(LOG_ERROR, "cllOpenEnv: SQLAllocEnv failed");
00129 return (-1);
00130 }
00131
00132 icss->environPtr=myHenv;
00133 return(0);
00134 }
00135
00136
00137
00138
00139
00140 int
00141 cllCloseEnv(icatSessionStruct *icss) {
00142 RETCODE stat;
00143 HENV myHenv;
00144
00145 myHenv = icss->environPtr;
00146 stat =SQLFreeEnv(myHenv);
00147
00148 if (stat != SQL_SUCCESS) {
00149 rodsLog(LOG_ERROR, "cllCloseEnv: SQLFreeEnv failed");
00150 }
00151 return(stat);
00152 }
00153
00154
00155
00156
00157 int
00158 cllConnect(icatSessionStruct *icss) {
00159 RETCODE stat;
00160 RETCODE stat2;
00161
00162 SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
00163 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
00164 SQLINTEGER sqlcode;
00165 SQLSMALLINT length;
00166
00167 HDBC myHdbc;
00168
00169 stat = SQLAllocConnect(icss->environPtr,
00170 &myHdbc);
00171 if (stat != SQL_SUCCESS) {
00172 rodsLog(LOG_ERROR, "cllConnect: SQLAllocConnect failed: %d, stat");
00173 return (-1);
00174 }
00175
00176 stat = SQLConnect(myHdbc, (unsigned char *)CATALOG_ODBC_ENTRY_NAME, SQL_NTS,
00177 (unsigned char *)icss->databaseUsername, SQL_NTS,
00178 (unsigned char *)icss->databasePassword, SQL_NTS);
00179 if (stat != SQL_SUCCESS) {
00180 rodsLog(LOG_ERROR, "cllConnect: SQLConnect failed: %d", stat);
00181 rodsLog(LOG_ERROR,
00182 "cllConnect: SQLConnect failed:odbcEntry=%s,user=%s,pass=%s\n",
00183 CATALOG_ODBC_ENTRY_NAME,icss->databaseUsername,
00184 icss->databasePassword);
00185 while (SQLError(icss->environPtr,myHdbc , 0, sqlstate, &sqlcode, buffer,
00186 SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS) {
00187 rodsLog(LOG_ERROR, "cllConnect: SQLSTATE: %s\n", sqlstate);
00188 rodsLog(LOG_ERROR, "cllConnect: Native Error Code: %ld\n", sqlcode);
00189 rodsLog(LOG_ERROR, "cllConnect: %s \n", buffer);
00190 }
00191
00192 stat2 = SQLDisconnect(myHdbc);
00193 stat2 = SQLFreeConnect(myHdbc);
00194 return (-1);
00195 }
00196
00197 icss->connectPtr=myHdbc;
00198
00199 if (icss->databaseType == DB_TYPE_MYSQL) {
00200
00201
00202
00203
00204 cllExecSqlNoResult ( icss, "SET SESSION autocommit=0" ) ;
00205 cllExecSqlNoResult ( icss, "SET SESSION sql_mode='ANSI,STRICT_TRANS_TABLES'" ) ;
00206 cllExecSqlNoResult ( icss, "SET character_set_client = utf8" ) ;
00207 cllExecSqlNoResult ( icss, "SET character_set_results = utf8" ) ;
00208 cllExecSqlNoResult ( icss, "SET character_set_connection = utf8" ) ;
00209 }
00210
00211 return(0);
00212 }
00213
00214
00215
00216
00217 int
00218 cllConnectRda(icatSessionStruct *icss) {
00219 RETCODE stat;
00220 RETCODE stat2;
00221
00222 SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
00223 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
00224 SQLINTEGER sqlcode;
00225 SQLSMALLINT length;
00226
00227 HDBC myHdbc;
00228
00229 stat = SQLAllocConnect(icss->environPtr,
00230 &myHdbc);
00231 if (stat != SQL_SUCCESS) {
00232 rodsLog(LOG_ERROR, "cllConnect: SQLAllocConnect failed: %d, stat");
00233 return (-1);
00234 }
00235
00236 stat = SQLSetConnectOption(myHdbc,
00237 SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
00238 if (stat != SQL_SUCCESS) {
00239 rodsLog(LOG_ERROR, "cllConnect: SQLSetConnectOption failed: %d", stat);
00240 return (-1);
00241 }
00242
00243 stat = SQLConnect(myHdbc, (unsigned char *)RDA_ODBC_ENTRY_NAME, SQL_NTS,
00244 (unsigned char *)icss->databaseUsername, SQL_NTS,
00245 (unsigned char *)icss->databasePassword, SQL_NTS);
00246 if (stat != SQL_SUCCESS) {
00247 rodsLog(LOG_ERROR, "cllConnect: SQLConnect failed: %d", stat);
00248 rodsLog(LOG_ERROR,
00249 "cllConnect: SQLConnect failed:odbcEntry=%s,user=%s,pass=%s\n",
00250 RDA_ODBC_ENTRY_NAME,icss->databaseUsername, icss->databasePassword);
00251 while (SQLError(icss->environPtr,myHdbc , 0, sqlstate, &sqlcode, buffer,
00252 SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS) {
00253 rodsLog(LOG_ERROR, "cllConnect: SQLSTATE: %s\n", sqlstate);
00254 rodsLog(LOG_ERROR, "cllConnect: Native Error Code: %ld\n", sqlcode);
00255 rodsLog(LOG_ERROR, "cllConnect: %s \n", buffer);
00256 }
00257
00258 stat2 = SQLDisconnect(myHdbc);
00259 stat2 = SQLFreeConnect(myHdbc);
00260 return (-1);
00261 }
00262
00263 icss->connectPtr=myHdbc;
00264
00265 if (icss->databaseType == DB_TYPE_MYSQL) {
00266
00267
00268
00269
00270
00271
00272 cllExecSqlNoResult ( icss, "SET SESSION autocommit=0" ) ;
00273 cllExecSqlNoResult ( icss,
00274 "SET SESSION sql_mode='ANSI,STRICT_TRANS_TABLES'" );
00275 }
00276 return(0);
00277 }
00278
00279
00280
00281
00282 int
00283 cllConnectDbr(icatSessionStruct *icss, char *odbcEntryName) {
00284 RETCODE stat;
00285 RETCODE stat2;
00286
00287 SQLCHAR buffer[SQL_MAX_MESSAGE_LENGTH + 1];
00288 SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
00289 SQLINTEGER sqlcode;
00290 SQLSMALLINT length;
00291
00292 HDBC myHdbc;
00293
00294 stat = SQLAllocConnect(icss->environPtr,
00295 &myHdbc);
00296 if (stat != SQL_SUCCESS) {
00297 rodsLog(LOG_ERROR, "cllConnect: SQLAllocConnect failed: %d, stat");
00298 return (-1);
00299 }
00300
00301 stat = SQLSetConnectOption(myHdbc,
00302 SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
00303 if (stat != SQL_SUCCESS) {
00304 rodsLog(LOG_ERROR, "cllConnect: SQLSetConnectOption failed: %d", stat);
00305 return (-1);
00306 }
00307
00308 stat = SQLConnect(myHdbc, (unsigned char *)odbcEntryName, SQL_NTS,
00309 (unsigned char *)icss->databaseUsername, SQL_NTS,
00310 (unsigned char *)icss->databasePassword, SQL_NTS);
00311 if (stat != SQL_SUCCESS) {
00312 rodsLog(LOG_ERROR, "cllConnect: SQLConnect failed: %d", stat);
00313 rodsLog(LOG_ERROR,
00314 "cllConnect: SQLConnect failed:odbcEntry=%s,user=%s,pass=%s\n",
00315 odbcEntryName,icss->databaseUsername, icss->databasePassword);
00316 while (SQLError(icss->environPtr,myHdbc , 0, sqlstate, &sqlcode, buffer,
00317 SQL_MAX_MESSAGE_LENGTH + 1, &length) == SQL_SUCCESS) {
00318 rodsLog(LOG_ERROR, "cllConnect: SQLSTATE: %s\n", sqlstate);
00319 rodsLog(LOG_ERROR, "cllConnect: Native Error Code: %ld\n", sqlcode);
00320 rodsLog(LOG_ERROR, "cllConnect: %s \n", buffer);
00321 }
00322
00323 stat2 = SQLDisconnect(myHdbc);
00324 stat2 = SQLFreeConnect(myHdbc);
00325 return (-1);
00326 }
00327
00328 icss->connectPtr=myHdbc;
00329
00330 if (icss->databaseType == DB_TYPE_MYSQL) {
00331
00332
00333
00334
00335
00336
00337 cllExecSqlNoResult ( icss, "SET SESSION autocommit=0" ) ;
00338 cllExecSqlNoResult ( icss,
00339 "SET SESSION sql_mode='ANSI,STRICT_TRANS_TABLES'" );
00340 }
00341 return(0);
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 #define maxPendingToRecord 5
00355 #define pendingRecordSize 30
00356 #define pBufferSize (maxPendingToRecord*pendingRecordSize)
00357 int
00358 cllCheckPending(char *sql, int option, int dbType) {
00359 static int pendingCount=0;
00360 static int pendingIx=0;
00361 static int pendingAudits=0;
00362 static char pBuffer[pBufferSize+2];
00363 static int firstTime=1;
00364
00365 if (firstTime) {
00366 firstTime=0;
00367 memset(pBuffer, 0, pBufferSize);
00368 }
00369 if (option==0) {
00370 if (strncmp(sql,"commit", 6)==0 ||
00371 strncmp(sql,"rollback", 8)==0) {
00372 pendingIx=0;
00373 pendingCount=0;
00374 pendingAudits=0;
00375 memset(pBuffer, 0, pBufferSize);
00376 return(0);
00377 }
00378 if (pendingIx < maxPendingToRecord) {
00379 strncpy((char *)&pBuffer[pendingIx*pendingRecordSize], sql,
00380 pendingRecordSize-1);
00381 pendingIx++;
00382 }
00383 pendingCount++;
00384 return(0);
00385 }
00386 if (option==2) {
00387 pendingAudits++;
00388 return(0);
00389 }
00390
00391
00392 if (pendingCount > pendingAudits) {
00393 int i, max;
00394 int skip;
00395
00396 if (pendingIx == 1) {
00397 if (strncmp((char *)&pBuffer[0], "begin", 5)==0) {
00398 return(0);
00399 }
00400 }
00401 if (dbType == DB_TYPE_MYSQL) {
00402
00403
00404 skip=1;
00405 if (strncmp((char *)&pBuffer[0], "begin", 5)!=0) skip=0;
00406 max = maxPendingToRecord;
00407 if (pendingIx < max) max = pendingIx;
00408 for (i=1;i<max && skip==1;i++) {
00409 if (strncmp((char *)&pBuffer[i*pendingRecordSize],
00410 "SET SESSION",11) !=0) {
00411 skip=0;
00412 }
00413 }
00414 if (skip) return(0);
00415 }
00416
00417 rodsLog(LOG_NOTICE, "Warning, pending SQL at cllDisconnect, count: %d",
00418 pendingCount);
00419 max = maxPendingToRecord;
00420 if (pendingIx < max) max = pendingIx;
00421 for (i=0;i<max;i++) {
00422 rodsLog(LOG_NOTICE, "Warning, pending SQL: %s ...",
00423 (char *)&pBuffer[i*pendingRecordSize]);
00424 }
00425 if (pendingAudits > 0) {
00426 rodsLog(LOG_NOTICE, "Warning, SQL will be commited with audits");
00427 }
00428 }
00429
00430 if (pendingAudits > 0) {
00431 rodsLog(LOG_NOTICE,
00432 "Notice, pending Auditing SQL committed at cllDisconnect");
00433 return(1);
00434 }
00435 return(0);
00436 }
00437
00438
00439
00440
00441 int
00442 cllDisconnect(icatSessionStruct *icss) {
00443 RETCODE stat;
00444 HDBC myHdbc;
00445 int i;
00446
00447 myHdbc = icss->connectPtr;
00448
00449 i = cllCheckPending("", 1, icss->databaseType);
00450 if (i==1) {
00451 i = cllExecSqlNoResult(icss, "commit");
00452
00453
00454
00455 }
00456
00457 stat = SQLDisconnect(myHdbc);
00458 if (stat != SQL_SUCCESS) {
00459 rodsLog(LOG_ERROR, "cllDisconnect: SQLDisconnect failed: %d", stat);
00460 return(-1);
00461 }
00462
00463 stat = SQLFreeConnect(myHdbc);
00464 if (stat != SQL_SUCCESS) {
00465 rodsLog(LOG_ERROR, "cllDisconnect: SQLFreeConnect failed: %d", stat);
00466 return(-2);
00467 }
00468
00469 icss->connectPtr = myHdbc;
00470 return(0);
00471 }
00472
00473
00474
00475
00476
00477
00478 int
00479 cllExecSqlNoResult(icatSessionStruct *icss, char *sql)
00480 {
00481 int status;
00482
00483 if (strncmp(sql,"commit", 6)==0 ||
00484 strncmp(sql,"rollback", 8)==0) {
00485 didBegin=0;
00486 }
00487 else {
00488 if (didBegin==0) {
00489 status = _cllExecSqlNoResult(icss, "begin", 1);
00490 if (status != SQL_SUCCESS) return(status);
00491 }
00492 didBegin=1;
00493 }
00494 return (_cllExecSqlNoResult(icss, sql, 0));
00495 }
00496
00497
00498
00499
00500 void
00501 logTheBindVariables(int level)
00502 {
00503 int i;
00504 char tmpStr[TMP_STR_LEN+2];
00505 for (i=0;i<cllBindVarCountPrev;i++) {
00506 snprintf(tmpStr, TMP_STR_LEN, "bindVar[%d]=%s", i+1, cllBindVars[i]);
00507 rodsLog(level, tmpStr);
00508 }
00509 }
00510
00511
00512
00513
00514 int
00515 bindTheVariables(HSTMT myHstmt, char *sql) {
00516 int myBindVarCount;
00517 RETCODE stat;
00518 int i;
00519 char tmpStr[TMP_STR_LEN+2];
00520
00521 myBindVarCount = cllBindVarCount;
00522 cllBindVarCountPrev=cllBindVarCount;
00523 cllBindVarCount = 0;
00524
00525 if (myBindVarCount > 0) {
00526 rodsLogSql("SQLPrepare");
00527 stat = SQLPrepare(myHstmt, (unsigned char *)sql, SQL_NTS);
00528 if (stat != SQL_SUCCESS) {
00529 rodsLog(LOG_ERROR, "bindTheVariables: SQLPrepare failed: %d",
00530 stat);
00531 return(-1);
00532 }
00533
00534 for (i=0;i<myBindVarCount;i++) {
00535 stat = SQLBindParameter(myHstmt, i+1, SQL_PARAM_INPUT, SQL_C_CHAR,
00536 SQL_C_CHAR, 0, 0, cllBindVars[i], 0, 0);
00537 snprintf(tmpStr, TMP_STR_LEN, "bindVar[%d]=%s", i+1, cllBindVars[i]);
00538 rodsLogSql(tmpStr);
00539 if (stat != SQL_SUCCESS) {
00540 rodsLog(LOG_ERROR,
00541 "bindTheVariables: SQLBindParameter failed: %d", stat);
00542 return(-1);
00543 }
00544 }
00545
00546 if (stat != SQL_SUCCESS) {
00547 rodsLog(LOG_ERROR, "bindTheVariables: SQLAllocStmt failed: %d",
00548 stat);
00549 return(-1);
00550 }
00551 }
00552 return(0);
00553 }
00554
00555
00556
00557
00558
00559
00560 #ifdef NEW_ODBC
00561 static int cmp_stmt (char *str1, char *str2)
00562 {
00563
00564 while ( isspace(*str1) ) ++str1 ;
00565
00566
00567 for ( ; *str1 && *str2 ; ++str1, ++str2 ) {
00568 if ( tolower(*str1) != *str2 ) return 0 ;
00569 }
00570
00571
00572 while ( isspace(*str1) ) ++str1 ;
00573
00574
00575 return *str1 == *str2 ;
00576 }
00577 #endif
00578
00579
00580
00581
00582
00583
00584 int
00585 _cllExecSqlNoResult(icatSessionStruct *icss, char *sql,
00586 int option) {
00587 RETCODE stat;
00588 HDBC myHdbc;
00589 HSTMT myHstmt;
00590 int result;
00591 char *status;
00592 SQL_INT_OR_LEN rowCount;
00593 #ifdef NEW_ODBC
00594 int i;
00595 #endif
00596 myHdbc = icss->connectPtr;
00597 rodsLog(LOG_DEBUG1, sql);
00598 stat = SQLAllocStmt(myHdbc, &myHstmt);
00599 if (stat != SQL_SUCCESS) {
00600 rodsLog(LOG_ERROR, "_cllExecSqlNoResult: SQLAllocStmt failed: %d", stat);
00601 return(-1);
00602 }
00603
00604 #if 0
00605 if (bindVar1 != 0 && *bindVar1 != '\0') {
00606 stat = SQLBindParameter(myHstmt, 1, SQL_PARAM_INPUT, SQL_C_SBIGINT,
00607 SQL_C_SBIGINT, 0, 0, 0, 0, 0);
00608 if (stat != SQL_SUCCESS) {
00609 rodsLog(LOG_ERROR, "_cllExecSqlNoResult: SQLAllocStmt failed: %d",
00610 stat);
00611 return(-1);
00612 }
00613 }
00614 #endif
00615
00616 if (option==0) {
00617 if (bindTheVariables(myHstmt, sql) != 0) return(-1);
00618 }
00619
00620 rodsLogSql(sql);
00621
00622 stat = SQLExecDirect(myHstmt, (unsigned char *)sql, SQL_NTS);
00623 status = "UNKNOWN";
00624 if (stat == SQL_SUCCESS) status= "SUCCESS";
00625 if (stat == SQL_SUCCESS_WITH_INFO) status="SUCCESS_WITH_INFO";
00626 if (stat == SQL_NO_DATA_FOUND) status="NO_DATA";
00627 if (stat == SQL_ERROR) status="SQL_ERROR";
00628 if (stat == SQL_INVALID_HANDLE) status="HANDLE_ERROR";
00629 rodsLogSqlResult(status);
00630
00631 if (stat == SQL_SUCCESS || stat == SQL_SUCCESS_WITH_INFO ||
00632 stat == SQL_NO_DATA_FOUND) {
00633 cllCheckPending(sql, 0, icss->databaseType);
00634 result = 0;
00635 if (stat == SQL_NO_DATA_FOUND) result = CAT_SUCCESS_BUT_WITH_NO_INFO;
00636 #ifdef NEW_ODBC
00637
00638
00639
00640
00641 if ( ! cmp_stmt(sql,"begin") && ! cmp_stmt(sql,"commit") && ! cmp_stmt(sql,"rollback") ) {
00642
00643 i = SQLRowCount (myHstmt, (SQL_INT_OR_LEN *)&rowCount);
00644 if (i) {
00645
00646 result = CAT_SUCCESS_BUT_WITH_NO_INFO;
00647 }
00648 if (rowCount==0) result = CAT_SUCCESS_BUT_WITH_NO_INFO;
00649 }
00650 #else
00651 rowCount=0;
00652 #endif
00653 }
00654 else {
00655 if (option==0) {
00656 logTheBindVariables(LOG_NOTICE);
00657 }
00658 rodsLog(LOG_NOTICE,"_cllExecSqlNoResult: SQLExecDirect error: %d sql:%s",
00659 stat, sql);
00660 result = logPsgError(LOG_NOTICE, icss->environPtr, myHdbc, myHstmt,
00661 icss->databaseType);
00662 }
00663
00664 stat = SQLFreeStmt(myHstmt, SQL_DROP);
00665 if (stat != SQL_SUCCESS) {
00666 rodsLog(LOG_ERROR, "_cllExecSqlNoResult: SQLFreeStmt error: %d", stat);
00667 }
00668
00669 return(result);
00670 }
00671
00672
00673
00674
00675
00676
00677 int
00678 cllExecSqlWithResult(icatSessionStruct *icss, int *stmtNum, char *sql) {
00679
00680 RETCODE stat;
00681 HDBC myHdbc;
00682 HSTMT hstmt;
00683 SQLSMALLINT numColumns;
00684
00685 SQLCHAR colName[MAX_TOKEN];
00686 SQLSMALLINT colType;
00687 SQLSMALLINT colNameLen;
00688 SQL_UINT_OR_ULEN precision;
00689 SQLSMALLINT scale;
00690 SQL_INT_OR_LEN displaysize;
00691 #ifndef NEW_ODBC
00692 static SQLINTEGER resultDataSize;
00693 #endif
00694
00695 icatStmtStrct *myStatement;
00696
00697 int i;
00698 int statementNumber;
00699 char *status;
00700
00701
00702
00703
00704
00705
00706
00707
00708 myHdbc = icss->connectPtr;
00709 rodsLog(LOG_DEBUG1, sql);
00710 stat = SQLAllocStmt(myHdbc, &hstmt);
00711 if (stat != SQL_SUCCESS) {
00712 rodsLog(LOG_ERROR, "cllExecSqlWithResult: SQLAllocStmt failed: %d",
00713 stat);
00714 return(-1);
00715 }
00716
00717 statementNumber=-1;
00718 for (i=0;i<MAX_NUM_OF_CONCURRENT_STMTS && statementNumber<0;i++) {
00719 if (icss->stmtPtr[i]==0) {
00720 statementNumber=i;
00721 }
00722 }
00723 if (statementNumber<0) {
00724 rodsLog(LOG_ERROR,
00725 "cllExecSqlWithResult: too many concurrent statements");
00726 return(-2);
00727 }
00728
00729 myStatement = (icatStmtStrct *)malloc(sizeof(icatStmtStrct));
00730 icss->stmtPtr[statementNumber]=myStatement;
00731
00732 myStatement->stmtPtr=hstmt;
00733
00734 if (bindTheVariables(hstmt, sql) != 0) return(-1);
00735
00736 rodsLogSql(sql);
00737
00738 stat = SQLExecDirect(hstmt, (unsigned char *)sql, SQL_NTS);
00739 status = "UNKNOWN";
00740 if (stat == SQL_SUCCESS) status= "SUCCESS";
00741 if (stat == SQL_SUCCESS_WITH_INFO) status="SUCCESS_WITH_INFO";
00742 if (stat == SQL_NO_DATA_FOUND) status="NO_DATA";
00743 if (stat == SQL_ERROR) status="SQL_ERROR";
00744 if (stat == SQL_INVALID_HANDLE) status="HANDLE_ERROR";
00745 rodsLogSqlResult(status);
00746
00747 if (stat == SQL_SUCCESS ||
00748 stat == SQL_SUCCESS_WITH_INFO ||
00749 stat == SQL_NO_DATA_FOUND) {
00750 }
00751 else {
00752 logTheBindVariables(LOG_NOTICE);
00753 rodsLog(LOG_NOTICE,
00754 "cllExecSqlWithResult: SQLExecDirect error: %d, sql:%s",
00755 stat, sql);
00756 logPsgError(LOG_NOTICE, icss->environPtr, myHdbc, hstmt,
00757 icss->databaseType);
00758 return(-1);
00759 }
00760
00761 stat = SQLNumResultCols(hstmt, &numColumns);
00762 if (stat != SQL_SUCCESS) {
00763 rodsLog(LOG_ERROR, "cllExecSqlWithResult: SQLNumResultCols failed: %d",
00764 stat);
00765 return(-2);
00766 }
00767 myStatement->numOfCols=numColumns;
00768
00769 for (i = 0; i<numColumns; i++) {
00770 stat = SQLDescribeCol(hstmt, i+1, colName, sizeof(colName),
00771 &colNameLen, &colType, &precision, &scale, NULL);
00772 if (stat != SQL_SUCCESS) {
00773 rodsLog(LOG_ERROR, "cllExecSqlWithResult: SQLDescribeCol failed: %d",
00774 stat);
00775 return(-3);
00776 }
00777
00778 columnLength[i]=precision;
00779 stat = SQLColAttribute(hstmt, i+1, SQL_COLUMN_DISPLAY_SIZE,
00780 NULL, 0, NULL, &displaysize);
00781 if (stat != SQL_SUCCESS) {
00782 rodsLog(LOG_ERROR,
00783 "cllExecSqlWithResult: SQLColAttributes failed: %d",
00784 stat);
00785 return(-3);
00786 }
00787
00788 if (displaysize > ((int)strlen((char *) colName))) {
00789 columnLength[i] = displaysize + 1;
00790 }
00791 else {
00792 columnLength[i] = strlen((char *) colName) + 1;
00793 }
00794
00795
00796 myStatement->resultValue[i] = (char*)malloc((int)columnLength[i]);
00797
00798 strcpy((char *)myStatement->resultValue[i],"");
00799
00800 #if 1
00801
00802
00803 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i], columnLength[i], &resultDataSizeArray[ i ] );
00804 #else
00805 #if NEW_ODBC
00806 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i],
00807 columnLength[i], NULL);
00808
00809
00810
00811 #else
00812
00813 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i],
00814 columnLength[i], &resultDataSize);
00815 #endif
00816 #endif
00817 if (stat != SQL_SUCCESS) {
00818 rodsLog(LOG_ERROR,
00819 "cllExecSqlWithResult: SQLColAttributes failed: %d",
00820 stat);
00821 return(-4);
00822 }
00823
00824
00825 myStatement->resultColName[i] = (char*)malloc((int)columnLength[i]);
00826 strncpy(myStatement->resultColName[i], (char *)colName, columnLength[i]);
00827
00828 }
00829 *stmtNum = statementNumber;
00830 return(0);
00831 }
00832
00833
00834
00835
00836
00837 void
00838 logBindVars(int level, char *bindVar1, char *bindVar2, char *bindVar3,
00839 char *bindVar4, char *bindVar5, char *bindVar6) {
00840 if (bindVar1 != 0 && *bindVar1 != '\0') {
00841 rodsLog(level,"bindVar1=%s", bindVar1);
00842 }
00843 if (bindVar2 != 0 && *bindVar2 != '\0') {
00844 rodsLog(level,"bindVar2=%s", bindVar2);
00845 }
00846 if (bindVar3 != 0 && *bindVar3 != '\0') {
00847 rodsLog(level,"bindVar3=%s", bindVar3);
00848 }
00849 if (bindVar4 != 0 && *bindVar4 != '\0') {
00850 rodsLog(level,"bindVar4=%s", bindVar4);
00851 }
00852 }
00853
00854
00855
00856
00857
00858
00859 int
00860 cllExecSqlWithResultBV(icatSessionStruct *icss, int *stmtNum, char *sql,
00861 char *bindVar1, char *bindVar2, char *bindVar3,
00862 char *bindVar4, char *bindVar5, char *bindVar6) {
00863
00864 RETCODE stat;
00865 HDBC myHdbc;
00866 HSTMT hstmt;
00867 SQLSMALLINT numColumns;
00868
00869 SQLCHAR colName[MAX_TOKEN];
00870 SQLSMALLINT colType;
00871 SQLSMALLINT colNameLen;
00872 SQL_UINT_OR_ULEN precision;
00873 SQLSMALLINT scale;
00874 SQL_INT_OR_LEN displaysize;
00875 #ifndef NEW_ODBC
00876 static SQLINTEGER resultDataSize;
00877 #endif
00878
00879 icatStmtStrct *myStatement;
00880
00881 int i;
00882 int statementNumber;
00883 char *status;
00884 char tmpStr[TMP_STR_LEN+2];
00885
00886 myHdbc = icss->connectPtr;
00887 rodsLog(LOG_DEBUG1, sql);
00888 stat = SQLAllocStmt(myHdbc, &hstmt);
00889 if (stat != SQL_SUCCESS) {
00890 rodsLog(LOG_ERROR, "cllExecSqlWithResultBV: SQLAllocStmt failed: %d",
00891 stat);
00892 return(-1);
00893 }
00894
00895 statementNumber=-1;
00896 for (i=0;i<MAX_NUM_OF_CONCURRENT_STMTS && statementNumber<0;i++) {
00897 if (icss->stmtPtr[i]==0) {
00898 statementNumber=i;
00899 }
00900 }
00901 if (statementNumber<0) {
00902 rodsLog(LOG_ERROR,
00903 "cllExecSqlWithResultBV: too many concurrent statements");
00904 return(-2);
00905 }
00906
00907 myStatement = (icatStmtStrct *)malloc(sizeof(icatStmtStrct));
00908 icss->stmtPtr[statementNumber]=myStatement;
00909
00910 myStatement->stmtPtr=hstmt;
00911
00912 if ((bindVar1 != 0 && *bindVar1 != '\0') ||
00913 (bindVar2 != 0 && *bindVar2 != '\0') ||
00914 (bindVar3 != 0 && *bindVar3 != '\0') ||
00915 (bindVar4 != 0 && *bindVar4 != '\0')) {
00916
00917 rodsLogSql("SQLPrepare");
00918 stat = SQLPrepare(hstmt, (unsigned char *)sql, SQL_NTS);
00919 if (stat != SQL_SUCCESS) {
00920 rodsLog(LOG_ERROR, "cllExecSqlNoResult: SQLPrepare failed: %d",
00921 stat);
00922 return(-1);
00923 }
00924
00925 if (bindVar1 != 0 && *bindVar1 != '\0') {
00926 stat = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
00927 SQL_C_CHAR, 0, 0, bindVar1, 0, 0);
00928 snprintf(tmpStr, TMP_STR_LEN,
00929 "bindVar1=%s", bindVar1);
00930 rodsLogSql(tmpStr);
00931 if (stat != SQL_SUCCESS) {
00932 rodsLog(LOG_ERROR,
00933 "cllExecSqlNoResult: SQLBindParameter failed: %d", stat);
00934 return(-1);
00935 }
00936 }
00937 if (bindVar2 != 0 && *bindVar2 != '\0') {
00938 stat = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR,
00939 SQL_C_CHAR, 0, 0, bindVar2, 0, 0);
00940 snprintf(tmpStr, TMP_STR_LEN,
00941 "bindVar2=%s", bindVar2);
00942 rodsLogSql(tmpStr);
00943 if (stat != SQL_SUCCESS) {
00944 rodsLog(LOG_ERROR,
00945 "cllExecSqlNoResult: SQLBindParameter failed: %d", stat);
00946 return(-1);
00947 }
00948 }
00949 if (bindVar3 != 0 && *bindVar3 != '\0') {
00950 stat = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR,
00951 SQL_C_CHAR, 0, 0, bindVar3, 0, 0);
00952 snprintf(tmpStr, TMP_STR_LEN,
00953 "bindVar3=%s", bindVar3);
00954 rodsLogSql(tmpStr);
00955 if (stat != SQL_SUCCESS) {
00956 rodsLog(LOG_ERROR, "cllExecSqlNoResult: SQLBindParameter failed: %d",
00957 stat);
00958 return(-1);
00959 }
00960 }
00961 if (bindVar4 != 0 && *bindVar4 != '\0') {
00962 stat = SQLBindParameter(hstmt, 4, SQL_PARAM_INPUT, SQL_C_CHAR,
00963 SQL_C_CHAR, 0, 0, bindVar4, 0, 0);
00964 snprintf(tmpStr, TMP_STR_LEN,
00965 "bindVar4=%s", bindVar4);
00966 rodsLogSql(tmpStr);
00967 if (stat != SQL_SUCCESS) {
00968 rodsLog(LOG_ERROR, "cllExecSqlNoResult: SQLBindParameter failed: %d",
00969 stat);
00970 return(-1);
00971 }
00972 }
00973 if (bindVar5 != 0 && *bindVar5 != '\0') {
00974 stat = SQLBindParameter(hstmt, 5, SQL_PARAM_INPUT, SQL_C_CHAR,
00975 SQL_C_CHAR, 0, 0, bindVar5, 0, 0);
00976 snprintf(tmpStr, TMP_STR_LEN,
00977 "bindVar5=%s", bindVar5);
00978 rodsLogSql(tmpStr);
00979 if (stat != SQL_SUCCESS) {
00980 rodsLog(LOG_ERROR, "cllExecSqlNoResult: SQLBindParameter failed: %d",
00981 stat);
00982 return(-1);
00983 }
00984 }
00985 rodsLogSql(sql);
00986 stat = SQLExecute(hstmt);
00987 }
00988 else {
00989 rodsLogSql(sql);
00990 stat = SQLExecDirect(hstmt, (unsigned char *)sql, SQL_NTS);
00991 }
00992
00993 status = "UNKNOWN";
00994 if (stat == SQL_SUCCESS) status= "SUCCESS";
00995 if (stat == SQL_SUCCESS_WITH_INFO) status="SUCCESS_WITH_INFO";
00996 if (stat == SQL_NO_DATA_FOUND) status="NO_DATA";
00997 if (stat == SQL_ERROR) status="SQL_ERROR";
00998 if (stat == SQL_INVALID_HANDLE) status="HANDLE_ERROR";
00999 rodsLogSqlResult(status);
01000
01001 if (stat == SQL_SUCCESS ||
01002 stat == SQL_SUCCESS_WITH_INFO ||
01003 stat == SQL_NO_DATA_FOUND) {
01004 }
01005 else {
01006 logBindVars(LOG_NOTICE, bindVar1, bindVar2, bindVar3, bindVar4,
01007 bindVar5, bindVar6);
01008 rodsLog(LOG_NOTICE,
01009 "cllExecSqlWithResultBV: SQLExecDirect error: %d, sql:%s",
01010 stat, sql);
01011 logPsgError(LOG_NOTICE, icss->environPtr, myHdbc, hstmt,
01012 icss->databaseType);
01013 return(-1);
01014 }
01015
01016 stat = SQLNumResultCols(hstmt, &numColumns);
01017 if (stat != SQL_SUCCESS) {
01018 rodsLog(LOG_ERROR, "cllExecSqlWithResultBV: SQLNumResultCols failed: %d",
01019 stat);
01020 return(-2);
01021 }
01022 myStatement->numOfCols=numColumns;
01023
01024 for (i = 0; i<numColumns; i++) {
01025 stat = SQLDescribeCol(hstmt, i+1, colName, sizeof(colName),
01026 &colNameLen, &colType, &precision, &scale, NULL);
01027 if (stat != SQL_SUCCESS) {
01028 rodsLog(LOG_ERROR, "cllExecSqlWithResultBV: SQLDescribeCol failed: %d",
01029 stat);
01030 return(-3);
01031 }
01032
01033 columnLength[i]=precision;
01034 stat = SQLColAttribute(hstmt, i+1, SQL_COLUMN_DISPLAY_SIZE,
01035 NULL, 0, NULL, &displaysize);
01036 if (stat != SQL_SUCCESS) {
01037 rodsLog(LOG_ERROR,
01038 "cllExecSqlWithResultBV: SQLColAttributes failed: %d",
01039 stat);
01040 return(-3);
01041 }
01042
01043 if (displaysize > ((int)strlen((char *) colName))) {
01044 columnLength[i] = displaysize + 1;
01045 }
01046 else {
01047 columnLength[i] = strlen((char *) colName) + 1;
01048 }
01049
01050
01051 myStatement->resultValue[i] = (char*)malloc((int)columnLength[i]);
01052
01053 strcpy((char *)myStatement->resultValue[i],"");
01054 #if 1
01055
01056
01057 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i], columnLength[i], &resultDataSizeArray[i] );
01058 #else
01059 #ifdef NEW_ODBC
01060 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i],
01061 columnLength[i], NULL);
01062
01063
01064
01065 #else
01066
01067 stat = SQLBindCol(hstmt, i+1, SQL_C_CHAR, myStatement->resultValue[i],
01068 columnLength[i], &resultDataSize);
01069 #endif
01070 #endif
01071
01072 if (stat != SQL_SUCCESS) {
01073 rodsLog(LOG_ERROR,
01074 "cllExecSqlWithResultBV: SQLColAttributes failed: %d",
01075 stat);
01076 return(-4);
01077 }
01078
01079
01080 myStatement->resultColName[i] = (char*)malloc((int)columnLength[i]);
01081 strncpy(myStatement->resultColName[i], (char *)colName, columnLength[i]);
01082
01083 }
01084 *stmtNum = statementNumber;
01085 return(0);
01086 }
01087
01088
01089
01090
01091 int
01092 cllGetRow(icatSessionStruct *icss, int statementNumber) {
01093 HSTMT hstmt;
01094 RETCODE stat;
01095 int nCols, i;
01096 icatStmtStrct *myStatement;
01097 int logGetRows=0;
01098
01099
01100
01101
01102 myStatement=icss->stmtPtr[statementNumber];
01103 hstmt = myStatement->stmtPtr;
01104 nCols = myStatement->numOfCols;
01105
01106 for (i=0;i<nCols;i++) {
01107 strcpy((char *)myStatement->resultValue[i],"");
01108 }
01109 stat = SQLFetch(hstmt);
01110 if (stat != SQL_SUCCESS && stat != SQL_NO_DATA_FOUND) {
01111 rodsLog(LOG_ERROR, "cllGetRow: SQLFetch failed: %d", stat);
01112 return(-1);
01113 }
01114 if (stat == SQL_NO_DATA_FOUND) {
01115 if (logGetRows) {
01116 rodsLogSql("cllGetRow: NO DATA FOUND");
01117
01118 char tmpstr[210];
01119 snprintf(tmpstr, 200, "cllGetRow: NO DATA FOUND, statement:%d", statementNumber);
01120 }
01121 _cllFreeStatementColumns(icss,statementNumber);
01122 myStatement->numOfCols=0;
01123 }
01124 else {
01125 if (logGetRows) {
01126 char tmpstr[210];
01127
01128 snprintf(tmpstr, 200, "cllGetRow statement:%d columns:%d first column: %s", statementNumber, nCols, myStatement->resultValue[0]);
01129
01130 rodsLogSql(tmpstr);
01131 }
01132 }
01133 return(0);
01134 }
01135
01136
01137
01138
01139
01140 int
01141 cllNextValueString(char *itemName, char *outString, int maxSize) {
01142 #ifdef MY_ICAT
01143 snprintf(outString, maxSize, "%s_nextval()", itemName);
01144 #else
01145 snprintf(outString, maxSize, "nextval('%s')", itemName);
01146 #endif
01147 return 0;
01148 }
01149
01150 int
01151 cllGetRowCount(icatSessionStruct *icss, int statementNumber) {
01152 int i;
01153 HSTMT hstmt;
01154 icatStmtStrct *myStatement;
01155 SQL_INT_OR_LEN RowCount;
01156
01157 myStatement=icss->stmtPtr[statementNumber];
01158 hstmt = myStatement->stmtPtr;
01159
01160 i = SQLRowCount (hstmt, (SQL_INT_OR_LEN *)&RowCount);
01161 if (i) return(i);
01162 return(RowCount);
01163 }
01164
01165 int
01166 cllCurrentValueString(char *itemName, char *outString, int maxSize) {
01167 #ifdef MY_ICAT
01168 snprintf(outString, maxSize, "%s_currval()", itemName);
01169 #else
01170 snprintf(outString, maxSize, "currval('%s')", itemName);
01171 #endif
01172 return 0;
01173 }
01174
01175
01176
01177
01178
01179 int
01180 cllFreeStatement(icatSessionStruct *icss, int statementNumber) {
01181 HSTMT hstmt;
01182 RETCODE stat;
01183 int i;
01184
01185 icatStmtStrct *myStatement;
01186
01187 myStatement=icss->stmtPtr[statementNumber];
01188 if (myStatement==NULL) {
01189 return(0);
01190 }
01191 hstmt = myStatement->stmtPtr;
01192
01193 for (i=0;i<myStatement->numOfCols;i++) {
01194 free(myStatement->resultValue[i]);
01195 free(myStatement->resultColName[i]);
01196 }
01197
01198 stat = SQLFreeStmt(hstmt, SQL_DROP);
01199 if (stat != SQL_SUCCESS) {
01200 rodsLog(LOG_ERROR, "cllFreeStatement SQLFreeStmt error: %d", stat);
01201 }
01202
01203 free(myStatement);
01204
01205 icss->stmtPtr[statementNumber]=0;
01206
01207 return (0);
01208 }
01209
01210
01211
01212
01213
01214 int
01215 _cllFreeStatementColumns(icatSessionStruct *icss, int statementNumber) {
01216 HSTMT hstmt;
01217 int i;
01218
01219 icatStmtStrct *myStatement;
01220
01221 myStatement=icss->stmtPtr[statementNumber];
01222 hstmt = myStatement->stmtPtr;
01223
01224 for (i=0;i<myStatement->numOfCols;i++) {
01225 free(myStatement->resultValue[i]);
01226 free(myStatement->resultColName[i]);
01227 }
01228 return (0);
01229 }
01230
01231
01232
01233
01234
01235 int cllTest(char *userArg, char *pwArg) {
01236 int i;
01237 int j, k;
01238 int OK;
01239 int stmt;
01240 int numOfCols;
01241 char userName[500];
01242 int ival;
01243
01244 struct passwd *ppasswd;
01245 icatSessionStruct icss;
01246
01247 icss.stmtPtr[0]=0;
01248 icss.databaseType = DB_TYPE_POSTGRES;
01249 #ifdef MY_ICAT
01250 icss.databaseType = DB_TYPE_MYSQL;
01251 #endif
01252
01253 rodsLogSqlReq(1);
01254 OK=1;
01255 i = cllOpenEnv(&icss);
01256 if (i != 0) OK=0;
01257
01258 if (userArg==0 || *userArg=='\0') {
01259 ppasswd = getpwuid(getuid());
01260 strcpy(userName,ppasswd->pw_name);
01261 }
01262 else {
01263 strncpy(userName, userArg, 500);
01264 }
01265 printf("userName=%s\n",userName);
01266 printf("password=%s\n",pwArg);
01267
01268 strncpy(icss.databaseUsername,userName, DB_USERNAME_LEN);
01269
01270 if (pwArg==0 || *pwArg=='\0') {
01271 strcpy(icss.databasePassword,"");
01272 }
01273 else {
01274 strncpy(icss.databasePassword,pwArg, DB_PASSWORD_LEN);
01275 }
01276
01277 i = cllConnect(&icss);
01278 if (i != 0) exit(-1);
01279
01280 i = cllExecSqlNoResult(&icss,"create table test (i integer, j integer, a varchar(32))");
01281 if (i != 0 && i != CAT_SUCCESS_BUT_WITH_NO_INFO) OK=0;
01282
01283 i = cllExecSqlNoResult(&icss, "insert into test values (2, 3, 'a')");
01284 if (i != 0) OK=0;
01285
01286 i = cllExecSqlNoResult(&icss, "commit");
01287 if (i != 0) OK=0;
01288
01289 i = cllExecSqlNoResult(&icss, "bad sql");
01290 if (i == 0) OK=0;
01291 i = cllExecSqlNoResult(&icss, "rollback");
01292
01293 i = cllExecSqlNoResult(&icss, "delete from test where i = 1");
01294 if (i != 0 && i != CAT_SUCCESS_BUT_WITH_NO_INFO) OK=0;
01295
01296 i = cllExecSqlNoResult(&icss, "commit");
01297 if (i != 0) OK=0;
01298
01299 i = cllExecSqlWithResultBV(&icss, &stmt,
01300 "select * from test where a = ?",
01301 "a",0 ,0,0,0,0);
01302 if (i != 0) OK=0;
01303
01304 if (i == 0) {
01305 numOfCols = 1;
01306 for (j=0;j<10 && numOfCols>0;j++) {
01307 i = cllGetRow(&icss, stmt);
01308 if (i != 0) {
01309 OK=0;
01310 }
01311 else {
01312 numOfCols = icss.stmtPtr[stmt]->numOfCols;
01313 if (numOfCols == 0) {
01314 printf("No more rows returned\n");
01315 i = cllFreeStatement(&icss,stmt);
01316 }
01317 else {
01318 for (k=0; k<numOfCols || k < icss.stmtPtr[stmt]->numOfCols; k++){
01319 printf("resultValue[%d]=%s\n",k,
01320 icss.stmtPtr[stmt]->resultValue[k]);
01321 }
01322 }
01323 }
01324 }
01325 }
01326
01327 ival=2;
01328 i = cllExecSqlWithResultBV(&icss, &stmt,
01329 "select * from test where i = ?",
01330 "2",0,0,0,0,0);
01331 if (i != 0) OK=0;
01332
01333 if (i == 0) {
01334 numOfCols = 1;
01335 for (j=0;j<10 && numOfCols>0;j++) {
01336 i = cllGetRow(&icss, stmt);
01337 if (i != 0) {
01338 OK=0;
01339 }
01340 else {
01341 numOfCols = icss.stmtPtr[stmt]->numOfCols;
01342 if (numOfCols == 0) {
01343 printf("No more rows returned\n");
01344 i = cllFreeStatement(&icss,stmt);
01345 }
01346 else {
01347 for (k=0; k<numOfCols || k < icss.stmtPtr[stmt]->numOfCols; k++){
01348 printf("resultValue[%d]=%s\n",k,
01349 icss.stmtPtr[stmt]->resultValue[k]);
01350 }
01351 }
01352 }
01353 }
01354 }
01355
01356 i = cllExecSqlNoResult(&icss,"drop table test;");
01357 if (i != 0 && i != CAT_SUCCESS_BUT_WITH_NO_INFO) OK=0;
01358
01359 i = cllExecSqlNoResult(&icss, "commit");
01360 if (i != 0) OK=0;
01361
01362 i = cllDisconnect(&icss);
01363 if (i != 0) OK=0;
01364
01365 i = cllCloseEnv(&icss);
01366 if (i != 0) OK=0;
01367
01368 if (OK) {
01369 printf("The tests all completed normally\n");
01370 return(0);
01371 }
01372 else {
01373 printf("One or more tests DID NOT complete normally\n");
01374 return(-1);
01375 }
01376 }