Develop and Download Open Source Software

Browse CVS Repository

Diff of /xoonips/AL/commonal.cc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.32 by youi, Sat Dec 25 09:46:47 2004 UTC revision 1.33 by youi, Mon Dec 27 05:56:23 2004 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.33  2004/12/27 05:56:23  youi
6     * odbcDiagString: STMT以外のハンドルも処理するように変更した.
7     * syslogメッセージの処理を追加した.
8     *
9   * Revision 1.32  2004/12/25 09:46:47  youi   * Revision 1.32  2004/12/25 09:46:47  youi
10   * MySQL+MyODBCで動作するように修正した.   * MySQL+MyODBCで動作するように修正した.
11   *   *
# Line 165  static SQLHANDLE henv = NULL; Line 169  static SQLHANDLE henv = NULL;
169  static SQLHANDLE hdbc = NULL;  static SQLHANDLE hdbc = NULL;
170  static SQLHANDLE hstmt = NULL;  static SQLHANDLE hstmt = NULL;
171    
172  static string odbcDiagString( SQLHANDLE hstmt, SQLRETURN sqlcode );  static string odbcDiagString( SQLSMALLINT HandleType, SQLHANDLE hstmt, SQLRETURN sqlcode );
173    
174  static result_t countResultRows( const char* sql, SQLINTEGER* count )  static result_t countResultRows( const char* sql, SQLINTEGER* count )
175  {  {
# Line 179  static result_t countResultRows( const c Line 183  static result_t countResultRows( const c
183              ret = RES_OK;              ret = RES_OK;
184          }else{          }else{
185              string s( "SQLExecDirect in countResultRows " );              string s( "SQLExecDirect in countResultRows " );
186              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
187              s += "sql=";              s += "sql=";
188              s += string( sql );              s += string( sql );
189              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 213  static char* strncpy2( char* dst, const Line 217  static char* strncpy2( char* dst, const
217   * @param sqlcode SQLExecDirect,SQLExecuteの戻り値   * @param sqlcode SQLExecDirect,SQLExecuteの戻り値
218   * @return エラー文字列   * @return エラー文字列
219   */   */
220  static string odbcDiagString( SQLHANDLE hstmt, SQLRETURN sqlcode )  static string odbcDiagString( SQLSMALLINT HandleType, SQLHANDLE hstmt, SQLRETURN sqlcode )
221  {  {
222      string s;      string s;
223      if( sqlcode == SQL_ERROR || sqlcode == SQL_SUCCESS_WITH_INFO ){      if( sqlcode == SQL_ERROR || sqlcode == SQL_SUCCESS_WITH_INFO ){
# Line 222  static string odbcDiagString( SQLHANDLE Line 226  static string odbcDiagString( SQLHANDLE
226          SQLCHAR MessageText[ 1024 ];          SQLCHAR MessageText[ 1024 ];
227          SQLSMALLINT BufferLength;          SQLSMALLINT BufferLength;
228          SQLSMALLINT TextLength;          SQLSMALLINT TextLength;
229          SQLGetDiagRec( SQL_HANDLE_STMT, hstmt, 1, SQLState, &NativeError, MessageText, 1024, &TextLength );          SQLGetDiagRec( HandleType, hstmt, 1, SQLState, &NativeError, MessageText, 1024, &TextLength );
230                    
231          s += string( (char*)MessageText );          s += string( (char*)MessageText );
232          s += " SQLSTATE=";          s += " SQLSTATE=";
# Line 251  string getResultCol( SQLHANDLE hstmt, in Line 255  string getResultCol( SQLHANDLE hstmt, in
255      while ( ( sqlcode = SQLGetData(hstmt, col, SQL_C_CHAR, BinaryPtr, sizeof(BinaryPtr),      while ( ( sqlcode = SQLGetData(hstmt, col, SQL_C_CHAR, BinaryPtr, sizeof(BinaryPtr),
256                                     &BinaryLenOrInd)) != SQL_NO_DATA) {                                     &BinaryLenOrInd)) != SQL_NO_DATA) {
257          NumBytes = (BinaryLenOrInd > 5000) || (BinaryLenOrInd == SQL_NO_TOTAL) ? 5000 : BinaryLenOrInd;          NumBytes = (BinaryLenOrInd > 5000) || (BinaryLenOrInd == SQL_NO_TOTAL) ? 5000 : BinaryLenOrInd;
258          s += string( (char*)BinaryPtr, NumBytes );          if( NumBytes >= 0 ){
259                s += string( (char*)BinaryPtr, NumBytes );
260            }
261      }      }
262  //    fprintf( stderr, "getResultCol col=%d ret='%s'\n", col, s.c_str());  #ifdef USE_SYSLOG
263    //    openlog( "commonal", LOG_ODELAY, LOG_USER );
264    //    syslog( LOG_DEBUG, "getResultCol col=%d ret='%s'\n", col, s.c_str());
265    //    closelog( );
266    #endif
267      return s;      return s;
268  }  }
269    
# Line 361  static bool uidExists( userid_t uid ) Line 371  static bool uidExists( userid_t uid )
371                  ret = true;                  ret = true;
372              }else{              }else{
373                  string s( "SQLFetch in uidExists ");                  string s( "SQLFetch in uidExists ");
374                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
375                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
376                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
377                  ret = false;                  ret = false;
378              }              }
379          }else{          }else{
380              string s( "SQLExecDirect in uidExists ");              string s( "SQLExecDirect in uidExists ");
381              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
382              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
383              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
384              ret = false;              ret = false;
385          }          }
386      }else{      }else{
387          string s( "SQLAllocHandle in uidExists ");          string s( "SQLAllocHandle in uidExists ");
388          s += odbcDiagString( hstmt, sqlcode );          s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
389          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
390          ret = false;          ret = false;
391      }      }
# Line 430  result_t initializeDB( const char* dsn, Line 440  result_t initializeDB( const char* dsn,
440  {  {
441      SQLRETURN sqlcode;      SQLRETURN sqlcode;
442    
443    #ifdef USE_SYSLOG
444        openlog( "commonal", LOG_ODELAY, LOG_USER );
445    #endif
446      // 既に接続中なら、一旦切断      // 既に接続中なら、一旦切断
447      if ( hdbc != NULL )      if ( hdbc != NULL )
448          SQLDisconnect( hdbc );          SQLDisconnect( hdbc );
# Line 440  result_t initializeDB( const char* dsn, Line 453  result_t initializeDB( const char* dsn,
453  //    if( SQLAllocEnv( &henv ) != SQL_SUCCESS ) {  //    if( SQLAllocEnv( &henv ) != SQL_SUCCESS ) {
454      if( SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) != SQL_SUCCESS ) {      if( SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv ) != SQL_SUCCESS ) {
455          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_ENV,...) in initializeDB" );          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_ENV,...) in initializeDB" );
456    #ifdef USE_SYSLOG
457            syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
458            closelog( );
459    #endif
460          return RES_DB_INITIALIZE_ERROR;          return RES_DB_INITIALIZE_ERROR;
461      }      }
462      //ODBC Ver.3 として振舞うように属性を設定      //ODBC Ver.3 として振舞うように属性を設定
463      SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);      SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0);
464            
 //    if( ( sqlcode = SQLAllocConnect( henv, &hdbc ) ) != SQL_SUCCESS ) {  
465      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc ) ) != SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc ) ) != SQL_SUCCESS ) {
466          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_DBC,...) in initializeDB" );          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_DBC,...) in initializeDB" );
467    #ifdef USE_SYSLOG
468            syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
469            closelog( );
470    #endif
471          return RES_DB_INITIALIZE_ERROR;          return RES_DB_INITIALIZE_ERROR;
472      }      }
473      //ログインに5秒以上要したらタイムアウトする設定      //ログインに5秒以上要したらタイムアウトする設定
474      SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);      SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER *)5, 0);
475        
476      if ( ( sqlcode = SQLConnect( hdbc, (SQLCHAR*)dsn, strlen( dsn ), (SQLCHAR*)user, strlen( user ), (SQLCHAR*)password, strlen( password ) ) ) != SQL_SUCCESS ){      if ( ( sqlcode = SQLConnect( hdbc, (SQLCHAR*)dsn, strlen( dsn ), (SQLCHAR*)user, strlen( user ), (SQLCHAR*)password, strlen( password ) ) ) != SQL_SUCCESS ){
477          setLastErrorString( "SQLConnect in initializeDB" );          string s( "SQLConnect in initializeDB " );
478            s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
479            setLastErrorString( s.c_str( ) );
480    #ifdef USE_SYSLOG
481            syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );
482            closelog( );
483    #endif
484          return RES_DB_CONNECT_ERROR;          return RES_DB_CONNECT_ERROR;
485      }      }
486    #ifdef USE_SYSLOG
487        syslog( LOG_DEBUG, "initializeDB succeed" );
488        closelog( );
489    #endif
490      return RES_OK;      return RES_OK;
491  }  }
492    
# Line 504  bool isActivated( sessionid_t sid, useri Line 534  bool isActivated( sessionid_t sid, useri
534                  ret = true;                  ret = true;
535              }else{              }else{
536                  string s( "SQLFetch in isActivated " );                  string s( "SQLFetch in isActivated " );
537                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
538                  s += ", sql=" + sql;                  s += ", sql=" + sql;
539                  setLastErrorString( s.c_str() );                  setLastErrorString( s.c_str() );
540                  ret = false;                  ret = false;
541              }              }
542          }else{          }else{
543              string s( "SQLExecDirect in isActivated " );              string s( "SQLExecDirect in isActivated " );
544              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
545              s += ", sql=" + sql;              s += ", sql=" + sql;
546              setLastErrorString( s.c_str() );              setLastErrorString( s.c_str() );
547              ret = false;              ret = false;
# Line 554  result_t activate( sessionid_t sid, user Line 584  result_t activate( sessionid_t sid, user
584                  ret = RES_OK;                  ret = RES_OK;
585              }else{              }else{
586                  string s( "SQLRowCount in activate ");                  string s( "SQLRowCount in activate ");
587                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
588                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
589                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
590                  ret = RES_NO_SUCH_USER;                  ret = RES_NO_SUCH_USER;
591              }              }
592          }else{          }else{
593              string s( "SQLExecDirect in activate " );              string s( "SQLExecDirect in activate " );
594              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
595              s += ", sql=";              s += ", sql=";
596              s += string( sql );              s += string( sql );
597              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 650  result_t deleteAccount( sessionid_t sid, Line 680  result_t deleteAccount( sessionid_t sid,
680                  ret1 = RES_OK;                  ret1 = RES_OK;
681              }else{              }else{
682                  string s( "SQLRowCount in deleteAccount" );                  string s( "SQLRowCount in deleteAccount" );
683                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
684                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
685                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
686                  ret1 = RES_NO_SUCH_USER;                  ret1 = RES_NO_SUCH_USER;
687              }              }
688          }else{          }else{
689              string s( "SQLExecDirect in deleteAccount" );              string s( "SQLExecDirect in deleteAccount" );
690              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
691              s += ", sql=";              s += ", sql=";
692              s += string( sql );              s += string( sql );
693              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 678  result_t deleteAccount( sessionid_t sid, Line 708  result_t deleteAccount( sessionid_t sid,
708                  ret2 = RES_OK;                  ret2 = RES_OK;
709              }else{              }else{
710                  string s( "SQLRowCount in deleteAccount" );                  string s( "SQLRowCount in deleteAccount" );
711                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
712                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
713                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
714                  ret2 = RES_NO_SUCH_USER;                  ret2 = RES_NO_SUCH_USER;
715              }              }
716          }else{          }else{
717              string s( "SQLExecDirect in deleteAccount" );              string s( "SQLExecDirect in deleteAccount" );
718              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
719              s += ", sql=";              s += ", sql=";
720              s += string( sql );              s += string( sql );
721              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 742  result_t getAccount( sessionid_t sid, us Line 772  result_t getAccount( sessionid_t sid, us
772   */   */
773  result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )  result_t getAccounts( sessionid_t sid, const userid_t* uids, int uidsLen, criteria_t* cri, const account_t** accounts, int* accountsLen )
774  {  {
 #ifdef USE_SYSLOG  
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
 #endif  
775      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
776      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
777      if( uidsLen <= 0 ){      if( uidsLen <= 0 ){
778          *accounts = new account_t[ 0 ];          *accounts = new account_t[ 0 ];
779          *accountsLen = 0;          *accountsLen = 0;
780  #ifdef USE_SYSLOG  #ifdef USE_SYSLOG
781          closelog( );      openlog( "commonal", LOG_ODELAY, LOG_USER );
782        syslog( LOG_DEBUG, "getAccounts succeed len=0" );
783        closelog( );
784  #endif  #endif
785          return RES_OK;          return RES_OK;
786      }      }
787            
788    #ifdef USE_SYSLOG
789        openlog( "commonal", LOG_ODELAY, LOG_USER );
790        syslog( LOG_DEBUG, "begin of getAccounts" );
791    #endif
792      result_t ret = RES_ERROR;      result_t ret = RES_ERROR;
793      SQLRETURN sqlcode;      SQLRETURN sqlcode;
794      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
# Line 766  result_t getAccounts( sessionid_t sid, c Line 799  result_t getAccounts( sessionid_t sid, c
799      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_vpaccount_users AS u2 ";      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_vpaccount_users AS u2 ";
800      sql += "WHERE u1.uid = u2.uid ";      sql += "WHERE u1.uid = u2.uid ";
801      if( uidsLen > 0 ){      if( uidsLen > 0 ){
802    #ifdef USE_SYSLOG
803            syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", 0, uids[0] );
804    #endif
805          sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );          sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );
806          for( int i = 1; i < uidsLen; i++ ){          for( int i = 1; i < uidsLen; i++ ){
807    #ifdef USE_SYSLOG
808            syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", i, uids[i] );
809    #endif
810              sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );              sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );
811          }          }
812          sql += " ) ";          sql += " ) ";
813      }      }
814      sql += criteria2str( cri );      sql += criteria2str( cri );
815    #ifdef USE_SYSLOG
816            syslog( LOG_DEBUG, "sql=%s", sql.c_str() );
817    #endif
818            
819      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
820          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
# Line 823  result_t getAccounts( sessionid_t sid, c Line 865  result_t getAccounts( sessionid_t sid, c
865                  dst[ i ].setBaseURL( getResultCol( hstmt, 40 ).c_str() );                  dst[ i ].setBaseURL( getResultCol( hstmt, 40 ).c_str() );
866                  dst[ i ].setNoticeMail( atoi( getResultCol( hstmt, 41 ).c_str() ));                  dst[ i ].setNoticeMail( atoi( getResultCol( hstmt, 41 ).c_str() ));
867                  dst[ i ].setNoticeMailSince( atoi( getResultCol( hstmt, 42 ).c_str() ));                  dst[ i ].setNoticeMailSince( atoi( getResultCol( hstmt, 42 ).c_str() ));
868    #ifdef USE_SYSLOG
869                    syslog( LOG_DEBUG, "set to account_t %d", i );
870    #endif
871                  ( *accountsLen )++;                  ( *accountsLen )++;
872              }              }
873              *accounts = dst;              *accounts = dst;
874    #ifdef USE_SYSLOG
875                syslog( LOG_DEBUG, "getAccounts succeed" );
876    #endif
877              ret = RES_OK;              ret = RES_OK;
878          }else{          }else{
879              setLastErrorString( "SQLExecDirect in getAccounts" );              string s( "SQLExecDirect in getAccounts" );
880                s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
881                s += string( ", sql=" ) + string( sql );
882                setLastErrorString( s.c_str( ) );
883    #ifdef USE_SYSLOG
884                syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );
885    #endif
886              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
887          }          }
888          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
889      }else{      }else{
890          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );
891            s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
892            s += string( ", sql=" ) + string( sql );
893            setLastErrorString( s.c_str( ) );
894    #ifdef USE_SYSLOG
895            syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );
896    #endif
897          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
898      }      }
899    #ifdef USE_SYSLOG
900        closelog( );
901    #endif
902      return ret;      return ret;
903  }  }
904    
# Line 958  result_t insertAccount( sessionid_t sid, Line 1021  result_t insertAccount( sessionid_t sid,
1021                              }else{                              }else{
1022                                  ret = RES_DB_QUERY_ERROR;                                  ret = RES_DB_QUERY_ERROR;
1023                                  string s( "SQLFetch in insertAccount " );                                  string s( "SQLFetch in insertAccount " );
1024                                  s += odbcDiagString( hstmt, sqlcode );                                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1025                                  setLastErrorString( s.c_str( ) );                                  setLastErrorString( s.c_str( ) );
1026                              }                              }
1027                          }else{                          }else{
1028                              string s( "SQLExecDirect in insertAccount " );                              string s( "SQLExecDirect in insertAccount " );
1029                              s += odbcDiagString( hstmt, sqlcode );                              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1030                              setLastErrorString( s.c_str( ) );                              setLastErrorString( s.c_str( ) );
1031                              ret = RES_DB_QUERY_ERROR;                              ret = RES_DB_QUERY_ERROR;
1032                          }                          }
# Line 977  result_t insertAccount( sessionid_t sid, Line 1040  result_t insertAccount( sessionid_t sid,
1040                  }                  }
1041              }else{              }else{
1042                  string s( "SQLExecute in insertAccount " );                  string s( "SQLExecute in insertAccount " );
1043                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1044                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1045                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
1046              }              }
1047          }else{          }else{
1048              string s( "SQLPrepare in insertAccount " );              string s( "SQLPrepare in insertAccount " );
1049              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1050              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
1051              ret = RES_ERROR;              ret = RES_ERROR;
1052          }          }
# Line 1049  result_t insertAccount( sessionid_t sid, Line 1112  result_t insertAccount( sessionid_t sid,
1112                  }                  }
1113              }else{              }else{
1114                  string s( "SQLExecute in insertAccount " );                  string s( "SQLExecute in insertAccount " );
1115                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1116                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1117                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
1118              }              }
# Line 1237  result_t updateAccount( sessionid_t sid, Line 1300  result_t updateAccount( sessionid_t sid,
1300                  }                  }
1301              }else{              }else{
1302                  string s( "SQLExecute in updateAccount " );                  string s( "SQLExecute in updateAccount " );
1303                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1304                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1305                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
1306              }              }
# Line 1309  result_t updateAccount( sessionid_t sid, Line 1372  result_t updateAccount( sessionid_t sid,
1372                  }                  }
1373              }else{              }else{
1374                  string s( "SQLExecute in updateAccount " );                  string s( "SQLExecute in updateAccount " );
1375                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1376                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1377                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
1378              }              }
# Line 1346  result_t dumpUids( sessionid_t sid, crit Line 1409  result_t dumpUids( sessionid_t sid, crit
1409      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1410      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1411            
1412    #ifdef USE_SYSLOG
1413        openlog( "commonal", LOG_ODELAY, LOG_USER );
1414    #endif
1415        
1416      result_t ret = RES_ERROR;      result_t ret = RES_ERROR;
1417      userid_t* dst = 0;      userid_t* dst = 0;
1418      string sql;      string sql;
# Line 1372  result_t dumpUids( sessionid_t sid, crit Line 1439  result_t dumpUids( sessionid_t sid, crit
1439                  dst[ i ] = uid;                  dst[ i ] = uid;
1440              }              }
1441                            
1442    #ifdef USE_SYSLOG
1443                syslog( LOG_DEBUG, "dumpUids succeed" );
1444    #endif
1445              ret = RES_OK;              ret = RES_OK;
1446          }else{          }else{
1447              string s( "SQLExecDirect in dumpUids " );              string s( "SQLExecDirect in dumpUids " );
1448              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1449              s += "sql=";              s += "sql=";
1450              s += string( sql );              s += string( sql );
1451              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
1452    #ifdef USE_SYSLOG
1453                syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );
1454    #endif
1455              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1456          }          }
1457          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
1458      }else{      }else{
1459          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_STMT,...) in dumpUids " );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in dumpUids" );
1460            s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1461            s += string( ", sql=" ) + string( sql );
1462            setLastErrorString( s.c_str( ) );
1463    #ifdef USE_SYSLOG
1464            syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );
1465    #endif
1466          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
1467      }      }
1468      return ret;      return ret;
# Line 1496  result_t getGroupsByUid( sessionid_t sid Line 1575  result_t getGroupsByUid( sessionid_t sid
1575                          ret = RES_OK;                          ret = RES_OK;
1576                      }else{                      }else{
1577                          string s( "SQLExecDirect in getGroupsByUid " );                          string s( "SQLExecDirect in getGroupsByUid " );
1578                          s += odbcDiagString( hstmt, sqlcode );                          s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1579                          s += string( ", sql=" ) + string( sql );                          s += string( ", sql=" ) + string( sql );
1580                          ret = RES_DB_QUERY_ERROR;                          ret = RES_DB_QUERY_ERROR;
1581                      }                      }
1582                  }else{                  }else{
1583                      string s( "SQLAllocHandle in getGroupsByUid " );                      string s( "SQLAllocHandle in getGroupsByUid " );
1584                      s += odbcDiagString( hstmt, sqlcode );                      s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1585                      s += string( ", sql=" ) + string( sql );                      s += string( ", sql=" ) + string( sql );
1586                      ret = RES_DB_QUERY_ERROR;                      ret = RES_DB_QUERY_ERROR;
1587                  }                  }
# Line 1511  result_t getGroupsByUid( sessionid_t sid Line 1590  result_t getGroupsByUid( sessionid_t sid
1590              }              }
1591          }else{          }else{
1592              string s( "SQLExecDirect in getGroupsByUid " );              string s( "SQLExecDirect in getGroupsByUid " );
1593              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1594              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
1595              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1596          }          }
# Line 1612  result_t dumpGids( sessionid_t sid, crit Line 1691  result_t dumpGids( sessionid_t sid, crit
1691              ret = RES_OK;              ret = RES_OK;
1692          }else{          }else{
1693              string s( "SQLExecDirect in dumpGids " );              string s( "SQLExecDirect in dumpGids " );
1694              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1695              s += "sql=";              s += "sql=";
1696              s += string( sql );              s += string( sql );
1697              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 1670  result_t dumpGroupAdmins( sessionid_t si Line 1749  result_t dumpGroupAdmins( sessionid_t si
1749              ret = RES_OK;              ret = RES_OK;
1750          }else{          }else{
1751              string s( "SQLExecDirect in dumpGroupAdmins " );              string s( "SQLExecDirect in dumpGroupAdmins " );
1752              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1753              s += "sql=";              s += "sql=";
1754              s += string( sql );              s += string( sql );
1755              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 1719  result_t deleteMember( sessionid_t sid, Line 1798  result_t deleteMember( sessionid_t sid,
1798                  ret = RES_OK;                  ret = RES_OK;
1799              }else{              }else{
1800                  string s( "SQLRowCount in deleteMember" );                  string s( "SQLRowCount in deleteMember" );
1801                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1802                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
1803                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1804                  ret = RES_NO_SUCH_USER;                  ret = RES_NO_SUCH_USER;
1805              }              }
1806          }else{          }else{
1807              string s( "SQLExecDirect in deleteMember" );              string s( "SQLExecDirect in deleteMember" );
1808              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1809              s += ", sql=";              s += ", sql=";
1810              s += string( sql );              s += string( sql );
1811              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 1780  result_t insertMember( sessionid_t sid, Line 1859  result_t insertMember( sessionid_t sid,
1859                  ret = RES_OK;                  ret = RES_OK;
1860              }else{              }else{
1861                  string s( "SQLRowCount in insertMember " );                  string s( "SQLRowCount in insertMember " );
1862                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1863                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
1864                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
1865                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
1866              }              }
1867          }else{          }else{
1868              string s( "SQLExecDirect in insertMember " );              string s( "SQLExecDirect in insertMember " );
1869              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1870              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
1871              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
1872              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
# Line 1919  result_t deleteGroup( sessionid_t sid, g Line 1998  result_t deleteGroup( sessionid_t sid, g
1998                  ret = RES_OK;                  ret = RES_OK;
1999              }else{              }else{
2000                  string s( "SQLRowCount in deleteGroup" );                  string s( "SQLRowCount in deleteGroup" );
2001                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2002                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
2003                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
2004                  ret = RES_NO_SUCH_USER;                  ret = RES_NO_SUCH_USER;
2005              }              }
2006          }else{          }else{
2007              string s( "SQLExecDirect in deleteGroup" );              string s( "SQLExecDirect in deleteGroup" );
2008              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2009              s += ", sql=";              s += ", sql=";
2010              s += string( sql );              s += string( sql );
2011              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 1992  result_t insertGroup( sessionid_t sid, c Line 2071  result_t insertGroup( sessionid_t sid, c
2071                              }else{                              }else{
2072                                  ret = RES_DB_QUERY_ERROR;                                  ret = RES_DB_QUERY_ERROR;
2073                                  string s( "SQLFetch in insertGroup " );                                  string s( "SQLFetch in insertGroup " );
2074                                  s += odbcDiagString( hstmt, sqlcode );                                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2075                                  setLastErrorString( s.c_str( ) );                                  setLastErrorString( s.c_str( ) );
2076                              }                              }
2077                          }else{                          }else{
2078                              string s( "SQLExecDirect in insertGroup " );                              string s( "SQLExecDirect in insertGroup " );
2079                              s += odbcDiagString( hstmt, sqlcode );                              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2080                              setLastErrorString( s.c_str( ) );                              setLastErrorString( s.c_str( ) );
2081                              ret = RES_DB_QUERY_ERROR;                              ret = RES_DB_QUERY_ERROR;
2082                          }                          }
# Line 2011  result_t insertGroup( sessionid_t sid, c Line 2090  result_t insertGroup( sessionid_t sid, c
2090                  }                  }
2091              }else{              }else{
2092                  string s( "SQLExecute in insertGroup " );                  string s( "SQLExecute in insertGroup " );
2093                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2094                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
2095                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
2096              }              }
2097          }else{          }else{
2098              string s( "SQLPrepare in insertGroup " );              string s( "SQLPrepare in insertGroup " );
2099              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2100              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
2101              ret = RES_ERROR;              ret = RES_ERROR;
2102          }          }
# Line 2076  result_t updateGroup( sessionid_t sid, c Line 2155  result_t updateGroup( sessionid_t sid, c
2155                  }                  }
2156              }else{              }else{
2157                  string s( "SQLExecute in updateGroup " );                  string s( "SQLExecute in updateGroup " );
2158                  s += odbcDiagString( hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2159                  setLastErrorString( s.c_str( ) );                  setLastErrorString( s.c_str( ) );
2160                  ret = RES_DB_QUERY_ERROR;                  ret = RES_DB_QUERY_ERROR;
2161              }              }
# Line 2135  result_t getGroups( sessionid_t sid, gro Line 2214  result_t getGroups( sessionid_t sid, gro
2214  {  {
2215      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
2216      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
2217    
2218    #ifdef USE_SYSLOG
2219        openlog( "commonal", LOG_ODELAY, LOG_USER );
2220    #endif
2221            
2222      SQLRETURN sqlcode;      SQLRETURN sqlcode;
2223      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
# Line 2165  result_t getGroups( sessionid_t sid, gro Line 2248  result_t getGroups( sessionid_t sid, gro
2248                  ( *groupsLen )++;                  ( *groupsLen )++;
2249              }              }
2250              *groups = dst;              *groups = dst;
2251    #ifdef USE_SYSLOG
2252                syslog( LOG_DEBUG, "getGroups succeed" );
2253    #endif
2254              ret = RES_OK;              ret = RES_OK;
2255          }else{          }else{
2256              setLastErrorString( "SQLExecDirect in getAccounts" );              string s( "SQLExecDirect in getGroups" );
2257                s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2258                s += string( ", sql=" ) + string( sql );
2259                setLastErrorString( s.c_str( ) );
2260    #ifdef USE_SYSLOG
2261                syslog( LOG_DEBUG, "getGroups %s", getLastErrorString( ) );
2262    #endif
2263              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
2264          }          }
2265          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
2266      }else{      }else{
2267          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getGroups" );
2268            s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2269            s += string( ", sql=" ) + string( sql );
2270            setLastErrorString( s.c_str( ) );
2271    #ifdef USE_SYSLOG
2272            syslog( LOG_DEBUG, "getGroups %s", getLastErrorString( ) );
2273    #endif
2274          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
2275      }      }
2276    #ifdef USE_SYSLOG
2277        closelog( );
2278    #endif
2279      return ret;      return ret;
2280  }  }
2281    
# Line 2221  bool isModerator( sessionid_t sid, useri Line 2322  bool isModerator( sessionid_t sid, useri
2322              }              }
2323          }else{          }else{
2324              string s( "SQLExecDirect in isModerator " );              string s( "SQLExecDirect in isModerator " );
2325              s += odbcDiagString( hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2326              s += ", sql=";              s += ", sql=";
2327              s += string( sql );              s += string( sql );
2328              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
# Line 2463  result_t getSession( sessionid_t sid, co Line 2564  result_t getSession( sessionid_t sid, co
2564  {  {
2565      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
2566            
2567      result_t ret;      result_t ret = RES_ERROR;
2568      string sql;      string sql;
2569            
2570  /*  /*
# Line 2490  result_t getSession( sessionid_t sid, co Line 2591  result_t getSession( sessionid_t sid, co
2591      }else{      }else{
2592          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
2593      }      }
       
2594  */  */
2595      return ret;      return ret;
2596  }  }
# Line 2515  bool isValidSessionID( sessionid_t sid ) Line 2615  bool isValidSessionID( sessionid_t sid )
2615      SQLRETURN sqlcode;      SQLRETURN sqlcode;
2616      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
2617            
2618    #ifdef USE_SYSLOG
2619        openlog( "commonal", LOG_ODELAY, LOG_USER );
2620    #endif
2621      sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf );      sql = "SELECT * FROM " + dbprefix + "_vpaccount_session WHERE sid=" + string( buf );
2622      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
2623          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
2624              if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){              if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
2625    #ifdef USE_SYSLOG
2626                    syslog( LOG_DEBUG, "isValidSessionID succeed" );
2627    #endif
2628                  ret = true;                  ret = true;
2629              }else{              }else{
2630                  snprintf( buf, 12, "%d", sqlcode );                  string s( "SQLFetch in isValidSessionID " );
2631                  string s( "SQLFetch in isValidSessionID(sqlcode=" );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2632                  s += string( buf ) + ", sql=" + sql + ")";                  s += string( ", sql=" ) + string( sql );
2633                  setLastErrorString( s.c_str() );                  setLastErrorString( s.c_str() );
2634    #ifdef USE_SYSLOG
2635                    syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );
2636    #endif
2637                  ret = false;                  ret = false;
2638              }              }
2639          }else{          }else{
2640              setLastErrorString( "SQLExecDirect in isValidSessionID" );              string s( "SQLExecDirect in isValidSessionID " );
2641                s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2642                s += string( ", sql=" ) + string( sql );
2643                setLastErrorString( s.c_str( ) );
2644    #ifdef USE_SYSLOG
2645                syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );
2646    #endif
2647              ret = false;              ret = false;
2648          }          }
2649          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
2650      }else{      }else{
2651          setLastErrorString( "SQLAllocHandle(SQL_HANDLE_STMT,...) in isValidSessionID" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in isValidSessionID " );
2652            s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2653            s += string( ", sql=" ) + string( sql );
2654            setLastErrorString( s.c_str( ) );
2655    #ifdef USE_SYSLOG
2656            syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );
2657    #endif
2658          ret = false;          ret = false;
2659      }      }
2660    #ifdef USE_SYSLOG
2661        closelog( );
2662    #endif
2663      return ret;      return ret;
2664  }  }
2665    
# Line 2554  const char* getLastErrorString() Line 2678  const char* getLastErrorString()
2678  void setLastErrorString( const char* str )  void setLastErrorString( const char* str )
2679  {  {
2680      errstr = str;      errstr = str;
2681    #ifdef USE_SYSLOG
2682        openlog( "commonal", LOG_ODELAY, LOG_USER );
2683        syslog( LOG_DEBUG, "%s", str );
2684        closelog( );
2685    #endif
2686  //    fprintf( stderr, "setLastErrorString( '%s' );\n", str );  //    fprintf( stderr, "setLastErrorString( '%s' );\n", str );
2687  }  }

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.33

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26