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.71 by aga4096, Thu Feb 24 11:32:55 2005 UTC revision 1.72 by tani, Fri Feb 25 01:03:42 2005 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.72  2005/02/25 01:03:42  tani
6     * dbtype==DBTYPE_SQLITEの時の処理を分岐.
7     *
8   * Revision 1.71  2005/02/24 11:32:55  aga4096   * Revision 1.71  2005/02/24 11:32:55  aga4096
9   * ・updateGroupでグループインデックスの名前を変更するよう修正.   * ・updateGroupでグループインデックスの名前を変更するよう修正.
10   *   *
# Line 349  void syslog_printf( char* format, ... ) Line 352  void syslog_printf( char* format, ... )
352      va_start(ap, format);      va_start(ap, format);
353      openlog( "commonal", LOG_ODELAY, LOG_USER );      openlog( "commonal", LOG_ODELAY, LOG_USER );
354      vsyslog( LOG_DEBUG, format, ap );      vsyslog( LOG_DEBUG, format, ap );
355      closelog( );      #endif
 #endif  
356  }  }
357    
358  /**  /**
# Line 413  static certify_t getInitialCertifyStateF Line 415  static certify_t getInitialCertifyStateF
415              //certify by moderator or group admin              //certify by moderator or group admin
416              ret = index::CERTIFY_REQUIRED;              ret = index::CERTIFY_REQUIRED;
417          }          }
418            syslog_printf( "\ngetInitialCertifyStateFromConfig certify_item_val=%s", certify_item_val );
419          freeString( certify_item_val );          freeString( certify_item_val );
420      }      }
421      return ret;      return ret;
# Line 597  string getResultCol( SQLHANDLE hstmt, in Line 600  string getResultCol( SQLHANDLE hstmt, in
600      SQLLEN     BinaryLenOrInd;      SQLLEN     BinaryLenOrInd;
601      SQLINTEGER NumBytes;      SQLINTEGER NumBytes;
602            
603        syslog_printf( "getResultCol" );
604      while ( ( sqlcode = SQLGetData(hstmt, col, SQL_C_CHAR, BinaryPtr, sizeof(BinaryPtr),      while ( ( sqlcode = SQLGetData(hstmt, col, SQL_C_CHAR, BinaryPtr, sizeof(BinaryPtr),
605                                     &BinaryLenOrInd)) != SQL_NO_DATA) {                                     &BinaryLenOrInd)) != SQL_NO_DATA) {
606            syslog_printf( "SQLGetData BinaryLenOrInd=%d", BinaryLenOrInd );
607          NumBytes = (BinaryLenOrInd > 5000) || (BinaryLenOrInd == SQL_NO_TOTAL) ? 5000 : BinaryLenOrInd;          NumBytes = (BinaryLenOrInd > 5000) || (BinaryLenOrInd == SQL_NO_TOTAL) ? 5000 : BinaryLenOrInd;
608          if( NumBytes >= 0 ){          if( NumBytes <= 0 ) break;
609            else if( NumBytes > 0 ){
610              s += string( (char*)BinaryPtr, NumBytes );              s += string( (char*)BinaryPtr, NumBytes );
611          }          }
612      }      }
613  #ifdef USE_SYSLOG      syslog_printf( "getResultCol returns %s", s.c_str() );
 //    openlog( "commonal", LOG_ODELAY, LOG_USER );  
 //    syslog( LOG_DEBUG, "getResultCol col=%d ret='%s'\n", col, s.c_str());  
 //    closelog( );  
 #endif  
614      return s;      return s;
615  }  }
616    
# Line 742  static result_t sessionID2UID( sessionid Line 744  static result_t sessionID2UID( sessionid
744      }      }
745      else {      else {
746          string sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString(sid);          string sql = "SELECT uid FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString(sid);
747            syslog_printf( "sql=%s", sql.c_str() );
748          return queryGetUnsignedInt( "sessionID2UID", sql, uid );          return queryGetUnsignedInt( "sessionID2UID", sql, uid );
749      }      }
750  }  }
# Line 884  result_t initializeDB( const char* dsn, Line 887  result_t initializeDB( const char* dsn,
887  {  {
888      SQLRETURN sqlcode;      SQLRETURN sqlcode;
889    
 #ifdef USE_SYSLOG  
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
 #endif  
890      // 既に接続中なら、一旦切断      // 既に接続中なら、一旦切断
891      if ( hdbc != NULL )      if ( hdbc != NULL )
892          SQLDisconnect( hdbc );          SQLDisconnect( hdbc );
# Line 900  result_t initializeDB( const char* dsn, Line 900  result_t initializeDB( const char* dsn,
900          string s( "SQLAllocHandle(SQL_HANDLE_ENV,...) in initializeDB" );          string s( "SQLAllocHandle(SQL_HANDLE_ENV,...) in initializeDB" );
901          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
902          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
903  #ifdef USE_SYSLOG          syslog_printf( "initializeDB %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );  
         closelog( );  
 #endif  
904          return RES_DB_INITIALIZE_ERROR;          return RES_DB_INITIALIZE_ERROR;
905      }      }
906      //ODBC Ver.3 として振舞うように属性を設定      //ODBC Ver.3 として振舞うように属性を設定
# Line 913  result_t initializeDB( const char* dsn, Line 910  result_t initializeDB( const char* dsn,
910          string s( "SQLAllocHandle(SQL_HANDLE_DBC,...) in initializeDB" );          string s( "SQLAllocHandle(SQL_HANDLE_DBC,...) in initializeDB" );
911          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
912          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
913  #ifdef USE_SYSLOG          syslog_printf( "initializeDB %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );  
         closelog( );  
 #endif  
914          return RES_DB_INITIALIZE_ERROR;          return RES_DB_INITIALIZE_ERROR;
915      }      }
916      //ログインに5秒以上要したらタイムアウトする設定      //ログインに5秒以上要したらタイムアウトする設定
# Line 926  result_t initializeDB( const char* dsn, Line 920  result_t initializeDB( const char* dsn,
920          string s( "SQLConnect in initializeDB " );          string s( "SQLConnect in initializeDB " );
921          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
922          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
923  #ifdef USE_SYSLOG          syslog_printf( "initializeDB %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "initializeDB %s", getLastErrorString( ) );  
         closelog( );  
 #endif  
924          return RES_DB_CONNECT_ERROR;          return RES_DB_CONNECT_ERROR;
925      }      }
926  #ifdef USE_SYSLOG      syslog_printf( "initializeDB succeed" );
     syslog( LOG_DEBUG, "initializeDB succeed" );  
     closelog( );  
 #endif  
927      return RES_OK;      return RES_OK;
928  }  }
929    
# Line 1257  result_t getAccounts( sessionid_t sid, c Line 1245  result_t getAccounts( sessionid_t sid, c
1245      if( uidsLen <= 0 ){      if( uidsLen <= 0 ){
1246          *accounts = new account_t[ 0 ];          *accounts = new account_t[ 0 ];
1247          *accountsLen = 0;          *accountsLen = 0;
1248  #ifdef USE_SYSLOG      syslog_printf( "getAccounts succeed len=0" );
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
     syslog( LOG_DEBUG, "getAccounts succeed len=0" );  
     closelog( );  
 #endif  
1249          return RES_OK;          return RES_OK;
1250      }      }
1251            
1252  #ifdef USE_SYSLOG      syslog_printf( "begin of getAccounts" );
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
     syslog( LOG_DEBUG, "begin of getAccounts" );  
 #endif  
1253      result_t ret = RES_ERROR;      result_t ret = RES_ERROR;
1254      SQLRETURN sqlcode;      SQLRETURN sqlcode;
1255      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
# Line 1279  result_t getAccounts( sessionid_t sid, c Line 1260  result_t getAccounts( sessionid_t sid, c
1260      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_xnpaccount_users AS u2 ";      sql += "FROM " + dbprefix + "_users AS u1, " + dbprefix + "_xnpaccount_users AS u2 ";
1261      sql += "WHERE u1.uid = u2.uid ";      sql += "WHERE u1.uid = u2.uid ";
1262      if( uidsLen > 0 ){      if( uidsLen > 0 ){
1263  #ifdef USE_SYSLOG          syslog_printf( "set uid[%d] value=%d to ...", 0, uids[0] );
         syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", 0, uids[0] );  
 #endif  
1264          sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );          sql += "AND ( u1.uid=" + string( unsignedIntToString( uids[ 0 ] ) );
1265          for( int i = 1; i < uidsLen; i++ ){          for( int i = 1; i < uidsLen; i++ ){
1266  #ifdef USE_SYSLOG              syslog_printf( "set uid[%d] value=%d to ...", i, uids[i] );
         syslog( LOG_DEBUG, "set uid[%d] value=%d to ...", i, uids[i] );  
 #endif  
1267              sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );              sql += " OR u1.uid=" + string( unsignedIntToString( uids[ i ] ) );
1268          }          }
1269          sql += " ) ";          sql += " ) ";
1270      }      }
1271      sql += criteria2str( cri );      sql += criteria2str( cri );
1272  #ifdef USE_SYSLOG      syslog_printf( "sql=%s", sql.c_str() );
         syslog( LOG_DEBUG, "sql=%s", sql.c_str() );  
 #endif  
1273            
1274      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
1275            syslog_printf( "SQLAllocHandle" );
1276          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
1277                syslog_printf( "SQLExecDirect" );
1278              SQLLEN len = 0;              SQLLEN len = 0;
1279              userid_t uid = 0;              userid_t uid = 0;
1280              SQLBindCol( hstmt, 1, SQL_C_ULONG, &uid, 0, &len );              SQLBindCol( hstmt, 1, SQL_C_ULONG, &uid, 0, &len );
1281                syslog_printf( "SQLBindCol" );
1282              *accountsLen=0;              *accountsLen=0;
1283              for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < uidsLen ; i++ ){              for( int i = 0; ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS && i < uidsLen ; i++ ){
1284                    syslog_printf( "SQLFetch" );
1285                  dst[ i ].setUID( uid );                  dst[ i ].setUID( uid );
1286                  dst[ i ].setName( getResultCol( hstmt, 2 ).c_str() );                  dst[ i ].setName( getResultCol( hstmt, 2 ).c_str() );
1287                  dst[ i ].setUname( getResultCol( hstmt, 3 ).c_str() );                  dst[ i ].setUname( getResultCol( hstmt, 3 ).c_str() );
# Line 1345  result_t getAccounts( sessionid_t sid, c Line 1324  result_t getAccounts( sessionid_t sid, c
1324                  dst[ i ].setNoticeMail( atoi( getResultCol( hstmt, 40 ).c_str() ));                  dst[ i ].setNoticeMail( atoi( getResultCol( hstmt, 40 ).c_str() ));
1325                  dst[ i ].setNoticeMailSince( atoi( getResultCol( hstmt, 41 ).c_str() ));                  dst[ i ].setNoticeMailSince( atoi( getResultCol( hstmt, 41 ).c_str() ));
1326                  dst[ i ].setPrivateIndexID( atoi( getResultCol( hstmt, 42 ).c_str() ));                  dst[ i ].setPrivateIndexID( atoi( getResultCol( hstmt, 42 ).c_str() ));
1327  #ifdef USE_SYSLOG                  syslog_printf( "set to account_t %d", i );
                 syslog( LOG_DEBUG, "set to account_t %d", i );  
 #endif  
1328                  ( *accountsLen )++;                  ( *accountsLen )++;
1329              }              }
1330              *accounts = dst;              *accounts = dst;
1331  #ifdef USE_SYSLOG              syslog_printf( "getAccounts succeed" );
             syslog( LOG_DEBUG, "getAccounts succeed" );  
 #endif  
1332              ret = RES_OK;              ret = RES_OK;
1333          }else{          }else{
1334              string s( "SQLExecDirect in getAccounts" );              string s( "SQLExecDirect in getAccounts" );
1335              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
1336              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
1337              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
1338  #ifdef USE_SYSLOG              syslog_printf( "getAccounts %s", getLastErrorString( ) );
             syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );  
 #endif  
1339              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1340          }          }
1341          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
# Line 1370  result_t getAccounts( sessionid_t sid, c Line 1343  result_t getAccounts( sessionid_t sid, c
1343          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getAccounts" );
1344          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1345          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
1346  #ifdef USE_SYSLOG          syslog_printf( "getAccounts %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "getAccounts %s", getLastErrorString( ) );  
 #endif  
1347          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
1348      }      }
 #ifdef USE_SYSLOG  
     closelog( );  
 #endif  
1349      return ret;      return ret;
1350  }  }
1351    
# Line 1494  result_t insertAccount( sessionid_t sid, Line 1462  result_t insertAccount( sessionid_t sid,
1462                  SQLLEN count = 0;                  SQLLEN count = 0;
1463                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
1464                      //ユーザIDを取得する                      //ユーザIDを取得する
1465                      sql = "SELECT LAST_INSERT_ID()";                      if( dbtype == DBTYPE_MYSQL ){
1466                            sql = "SELECT LAST_INSERT_ID()";
1467                        }else if( dbtype == DBTYPE_SQLITE ){
1468                            sql = "SELECT LAST_INSERT_ROWID()";
1469                        }
1470                      ret = queryGetUnsignedInt( "insertAccount", sql, (unsigned int*)uid );                      ret = queryGetUnsignedInt( "insertAccount", sql, (unsigned int*)uid );
1471                  }else{                  }else{
1472                      string s( "SQLRowCount in insertAccount sql=" );                      string s( "SQLRowCount in insertAccount sql=" );
# Line 1927  result_t dumpUids( sessionid_t sid, crit Line 1899  result_t dumpUids( sessionid_t sid, crit
1899      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
1900      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
1901            
 #ifdef USE_SYSLOG  
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
 #endif  
       
1902      result_t ret = RES_ERROR;      result_t ret = RES_ERROR;
1903      userid_t* dst = 0;      userid_t* dst = 0;
1904      string sql;      string sql;
# Line 1957  result_t dumpUids( sessionid_t sid, crit Line 1925  result_t dumpUids( sessionid_t sid, crit
1925                  dst[ i ] = uid;                  dst[ i ] = uid;
1926              }              }
1927                            
1928  #ifdef USE_SYSLOG              syslog_printf( "dumpUids succeed" );
             syslog( LOG_DEBUG, "dumpUids succeed" );  
 #endif  
1929              ret = RES_OK;              ret = RES_OK;
1930          }else{          }else{
1931              string s( "SQLExecDirect in dumpUids " );              string s( "SQLExecDirect in dumpUids " );
# Line 1967  result_t dumpUids( sessionid_t sid, crit Line 1933  result_t dumpUids( sessionid_t sid, crit
1933              s += "sql=";              s += "sql=";
1934              s += string( sql );              s += string( sql );
1935              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
1936  #ifdef USE_SYSLOG              syslog_printf( "dumpUids %s", getLastErrorString( ) );
             syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );  
 #endif  
1937              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
1938          }          }
1939          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
# Line 1977  result_t dumpUids( sessionid_t sid, crit Line 1941  result_t dumpUids( sessionid_t sid, crit
1941          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in dumpUids" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in dumpUids" );
1942          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
1943          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
1944  #ifdef USE_SYSLOG          syslog_printf( "dumpUids %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "dumpUids %s", getLastErrorString( ) );  
 #endif  
1945          ret = RES_ERROR;          ret = RES_ERROR;
1946      }      }
1947      return ret;      return ret;
# Line 2612  result_t insertGroup( sessionid_t sid, c Line 2574  result_t insertGroup( sessionid_t sid, c
2574                  SQLLEN count = 0;                  SQLLEN count = 0;
2575                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
2576                      //グループIDを取得する                      //グループIDを取得する
2577                      sql = "SELECT LAST_INSERT_ID()";                      if( dbtype == DBTYPE_MYSQL ){
2578                            sql = "SELECT LAST_INSERT_ID()";
2579                        }else if( dbtype == DBTYPE_SQLITE ){
2580                            sql = "SELECT LAST_INSERT_ROWID()";
2581                        }
2582                      ret = queryGetUnsignedInt( "insertGroup", sql, (unsigned int*)gid );                      ret = queryGetUnsignedInt( "insertGroup", sql, (unsigned int*)gid );
2583                  }else{                  }else{
2584                      string s( "SQLRowCount in insertGroup sql=" );                      string s( "SQLRowCount in insertGroup sql=" );
# Line 2839  result_t getGroups( sessionid_t sid, gro Line 2805  result_t getGroups( sessionid_t sid, gro
2805      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;      if( hdbc == NULL ) return RES_DB_NOT_INITIALIZED;
2806      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;      if( !isValidSessionID( sid ) ) return RES_NO_SUCH_SESSION;
2807    
 #ifdef USE_SYSLOG  
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
 #endif  
       
2808      SQLRETURN sqlcode;      SQLRETURN sqlcode;
2809      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
2810      result_t ret = RES_ERROR;      result_t ret = RES_ERROR;
# Line 2873  result_t getGroups( sessionid_t sid, gro Line 2835  result_t getGroups( sessionid_t sid, gro
2835                  ( *groupsLen )++;                  ( *groupsLen )++;
2836              }              }
2837              *groups = dst;              *groups = dst;
2838  #ifdef USE_SYSLOG              syslog_printf( "getGroups succeed" );
             syslog( LOG_DEBUG, "getGroups succeed" );  
 #endif  
2839              ret = RES_OK;              ret = RES_OK;
2840          }else{          }else{
2841              string s( "SQLExecDirect in getGroups" );              string s( "SQLExecDirect in getGroups" );
2842              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
2843              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
2844              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
2845  #ifdef USE_SYSLOG              syslog_printf( "getGroups %s", getLastErrorString( ) );
             syslog( LOG_DEBUG, "getGroups %s", getLastErrorString( ) );  
 #endif  
2846              ret = RES_DB_QUERY_ERROR;              ret = RES_DB_QUERY_ERROR;
2847          }          }
2848          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
# Line 2892  result_t getGroups( sessionid_t sid, gro Line 2850  result_t getGroups( sessionid_t sid, gro
2850          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getGroups" );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in getGroups" );
2851          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
2852          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
2853  #ifdef USE_SYSLOG          syslog_printf( "getGroups %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "getGroups %s", getLastErrorString( ) );  
 #endif  
2854          ret = RES_ERROR;          ret = RES_ERROR;
2855      }      }
 #ifdef USE_SYSLOG  
     closelog( );  
 #endif  
2856      return ret;      return ret;
2857  }  }
2858    
# Line 3031  result_t getUid( const char* uname, user Line 2984  result_t getUid( const char* uname, user
2984  static result_t addSession( userid_t uid, sessionid_t* session )  static result_t addSession( userid_t uid, sessionid_t* session )
2985  {  {
2986      char *functionName = "addSession";      char *functionName = "addSession";
2987      string sql = "INSERT INTO " + dbprefix + "_xnpaccount_session (uid) values (" +      string sql;
2988        unsignedIntToString(uid) + ")";      if( dbtype == DBTYPE_MYSQL ){
2989            sql = "INSERT INTO " + dbprefix + "_xnpaccount_session (uid) values (" +
2990                unsignedIntToString(uid) + ")";
2991        }else if( dbtype == DBTYPE_SQLITE ){
2992            sql = "INSERT INTO " + dbprefix + "_xnpaccount_session (uid, timestamp) values (" +
2993                unsignedIntToString(uid) + "," + unsignedIntToString( time( NULL ) ) + ")";
2994        }
2995      result_t ret = querySimple( functionName, sql );      result_t ret = querySimple( functionName, sql );
2996      if ( ret == RES_OK ){      if ( ret == RES_OK ){
2997          sql = "SELECT LAST_INSERT_ID()";          if( dbtype == DBTYPE_MYSQL ){
2998                sql = "SELECT LAST_INSERT_ID()";
2999            }else if( dbtype == DBTYPE_SQLITE ){
3000                sql = "SELECT LAST_INSERT_ROWID()";
3001            }
3002          ret = queryGetUnsignedInt( functionName, sql, (unsigned int*)session );          ret = queryGetUnsignedInt( functionName, sql, (unsigned int*)session );
3003      }      }
3004      return ret;      return ret;
# Line 3216  result_t getSession( sessionid_t sid, co Line 3179  result_t getSession( sessionid_t sid, co
3179      SQLHANDLE hstmt = NULL;      SQLHANDLE hstmt = NULL;
3180      SQLRETURN sqlcode;      SQLRETURN sqlcode;
3181            
3182      sql = "SELECT sid, uid, unix_timestamp(timestamp) from " + dbprefix +      if( dbtype == DBTYPE_MYSQL ){
3183        "_xnpaccount_session where sid=" + unsignedIntToString((unsigned int)sid);          sql = "SELECT sid, uid, unix_timestamp(timestamp) from " + dbprefix +
3184                "_xnpaccount_session where sid=" + unsignedIntToString((unsigned int)sid);
3185        }else if( dbtype == DBTYPE_SQLITE ){
3186            sql = "SELECT sid, uid, timestamp from " + dbprefix +
3187                "_xnpaccount_session where sid=" + unsignedIntToString((unsigned int)sid);
3188        }
3189      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
3190          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
3191              userid_t uid = 0;              userid_t uid = 0;
# Line 3327  result_t insertItem( sessionid_t sid, co Line 3295  result_t insertItem( sessionid_t sid, co
3295      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
3296          string sql;          string sql;
3297          sql = "INSERT INTO " + dbprefix + "_xnpaccount_item_basic (item_type_id, title, keywords, description, doi, uid, creation_date, last_update_date, publication_year, publication_month, publication_mday) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";          sql = "INSERT INTO " + dbprefix + "_xnpaccount_item_basic (item_type_id, title, keywords, description, doi, uid, creation_date, last_update_date, publication_year, publication_month, publication_mday) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
3298            syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() );
3299          sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);          sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
3300          if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){          if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
3301              SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &item_type_id, 0, &cbItem_type_id );              SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 0, 0, &item_type_id, 0, &cbItem_type_id );
# Line 3357  result_t insertItem( sessionid_t sid, co Line 3326  result_t insertItem( sessionid_t sid, co
3326                  SQLLEN count = 0;                  SQLLEN count = 0;
3327                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){                  if( ( sqlcode = SQLRowCount( hstmt, &count ) ) == SQL_SUCCESS && count > 0 ){
3328                      //アイテムIDを取得する                      //アイテムIDを取得する
3329                      sql = "SELECT LAST_INSERT_ID()";                      if( dbtype == DBTYPE_MYSQL ){
3330                            sql = "SELECT LAST_INSERT_ID()";
3331                        }else if( dbtype == DBTYPE_SQLITE ){
3332                            sql = "SELECT LAST_INSERT_ROWID()";
3333                        }
3334                      if( ( ret = queryGetUnsignedInt( "insertItem", sql, (unsigned int*)itemid ) ) == RES_OK ){                      if( ( ret = queryGetUnsignedInt( "insertItem", sql, (unsigned int*)itemid ) ) == RES_OK ){
3335                          if( item -> getItemTypeID( ) == item::ITID_BINDER ){                          if( item -> getItemTypeID( ) == item::ITID_BINDER ){
3336                              //insert into binder index                              //insert into binder index
# Line 3477  result_t getItems( sessionid_t sid, cons Line 3450  result_t getItems( sessionid_t sid, cons
3450          where = string( unsignedIntToString( iids[ i ] ) ) + ", " + where;          where = string( unsignedIntToString( iids[ i ] ) ) + ", " + where;
3451      }      }
3452            
3453      sql = "SELECT DISTINCT ti.item_id as item_id, item_type_id, title, keywords, description, doi, ti.uid as uid, creation_date, last_update_date, publication_year, publication_month, publication_mday ";  
3454      sql+= " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";      if( dbtype == DBTYPE_MYSQL ){
3455      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";          sql = "SELECT DISTINCT ti.item_id as item_id, item_type_id, title, keywords, description, doi, ti.uid as uid, creation_date, last_update_date, publication_year, publication_month, publication_mday ";
3456      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";          sql+= " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
3457            sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";
3458            sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";
3459        }else if( dbtype == DBTYPE_SQLITE ){
3460            sql = "SELECT DISTINCT xtest_xnpaccount_item_basic.item_id as item_id, item_type_id, title, keywords, description, doi, xtest_xnpaccount_item_basic.uid as uid, creation_date, last_update_date, publication_year, publication_month, publication_mday ";
3461            sql+= " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
3462            sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";
3463            sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic ON tlink.item_id = xtest_xnpaccount_item_basic.item_id";
3464        }
3465      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link as tgulink ON tx.gid=tgulink.gid";      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link as tgulink ON tx.gid=tgulink.gid";
3466      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_session AS tsess ON tsess.uid=" + unsignedIntToString( uid );      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_session AS tsess ON tsess.uid=" + unsignedIntToString( uid );
3467      sql+= " AND tsess.sid=" + unsignedIntToString( sid );      sql+= " AND tsess.sid=" + unsignedIntToString( sid );
# Line 4043  result_t getPrivateItemID( sessionid_t s Line 4024  result_t getPrivateItemID( sessionid_t s
4024      sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";      sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
4025      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id=tx.index_id";      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id=tx.index_id";
4026      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id=ti.item_id";      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id=ti.item_id";
4027      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid AND tx.open_level=" + unsignedIntToString( index::OL_GROUP_ONLY );          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid";
4028    
4029      sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );      sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );
4030      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFIED );      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFIED );
4031      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );
# Line 4156  result_t getItemIDByIndexID( sessionid_t Line 4138  result_t getItemIDByIndexID( sessionid_t
4138      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";
4139  //    sql+=       " AND certify_state=" + unsignedIntToString( index::CERTIFIED );  //    sql+=       " AND certify_state=" + unsignedIntToString( index::CERTIFIED );
4140      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";
4141      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link as tgulink ON tx.gid=tgulink.gid AND (ti.uid=";      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link as tgulink ON tx.gid=tgulink.gid";
4142      sql+= unsignedIntToString( uid ) + " OR ";      sql+= " LEFT JOIN " + dbprefix + "_xnpaccount_session AS tsess ON tsess.uid=" + unsignedIntToString( uid );
     sql+= string( isModerator( sid, uid ) ? "1" : "0" ) + ") LEFT JOIN ";  
     sql+= dbprefix + "_xnpaccount_session AS tsess ON tsess.uid=" + unsignedIntToString( uid );  
4143      sql+= " AND tsess.sid=" + unsignedIntToString( sid );      sql+= " AND tsess.sid=" + unsignedIntToString( sid );
4144      sql+= " WHERE ( " + string( public_item_target_user_all( ) ? "1" : "0" );      sql+= " WHERE ( " + string( public_item_target_user_all( ) ? "1" : "0" );
4145      sql+=       " AND tx.open_level=" + unsignedIntToString( index::OL_PUBLIC ) + " AND tsess.uid IS NULL";      sql+=       " AND tx.open_level=" + unsignedIntToString( index::OL_PUBLIC ) + " AND tsess.uid IS NULL";
4146      sql+=    " OR " + string( !public_item_target_user_all( ) ? "1" : "0" );      sql+=    " OR " + string( !public_item_target_user_all( ) ? "1" : "0" );
4147      sql+=       " AND tx.open_level=" + unsignedIntToString( index::OL_PUBLIC ) + " AND tsess.uid IS NOT NULL";      sql+=       " AND tx.open_level=" + unsignedIntToString( index::OL_PUBLIC ) + " AND tsess.uid IS NOT NULL";
 //    sql+=    " OR tgulink.uid=" + unsignedIntToString( uid );  
4148      sql+=    " OR tx.open_level=" + unsignedIntToString( index::OL_PRIVATE );      sql+=    " OR tx.open_level=" + unsignedIntToString( index::OL_PRIVATE );
4149      sql+=       " AND tx.uid=" + unsignedIntToString( uid );      sql+=       " AND tx.uid=" + unsignedIntToString( uid );
4150      sql+=    " OR " + string( isModerator( sid, uid ) ? "1" : "0" );      sql+=    " OR " + string( isModerator( sid, uid ) ? "1" : "0" );
# Line 4240  result_t getItemIDByBinderID( sessionid_ Line 4219  result_t getItemIDByBinderID( sessionid_
4219      SQLRETURN sqlcode;      SQLRETURN sqlcode;
4220      SQLLEN count = 0;      SQLLEN count = 0;
4221            
4222      sql = "SELECT t1.item_id FROM " + dbprefix + "_xnpaccount_item_basic as t1, "      if( dbtype == DBTYPE_MYSQL ){
4223          + dbprefix + "_xnpbinder_binder_item_link as t2 ";          sql = "SELECT t1.item_id FROM " + dbprefix + "_xnpaccount_item_basic as t1, "
4224      sql += " WHERE t1.item_id = t2.item_id";              + dbprefix + "_xnpbinder_binder_item_link as t2 ";
4225            sql += " WHERE t1.item_id = t2.item_id";
4226        }else if( dbtype == DBTYPE_SQLITE ){
4227            sql = "SELECT " + dbprefix + "_xnpaccount_item_basic.item_id FROM " + dbprefix + "_xnpaccount_item_basic, "
4228                + dbprefix + "_xnpbinder_binder_item_link as t2 ";
4229            sql += " WHERE " + dbprefix + "_xnpaccount_item_basic.item_id = t2.item_id";
4230        }
4231      sql += " AND t2.binder_id=" + unsignedIntToString( binderid );      sql += " AND t2.binder_id=" + unsignedIntToString( binderid );
4232      sql += criteria2str( cri );      sql += criteria2str( cri );
4233      if( countResultRows( sql.c_str(), &count ) == RES_OK ){      if( countResultRows( sql.c_str(), &count ) == RES_OK ){
# Line 4327  result_t setCertifyState( sessionid_t si Line 4312  result_t setCertifyState( sessionid_t si
4312          + unsignedIntToString( state )          + unsignedIntToString( state )
4313          + " WHERE index_id=" + unsignedIntToString( xid )          + " WHERE index_id=" + unsignedIntToString( xid )
4314          + " AND item_id=" + unsignedIntToString( iid );          + " AND item_id=" + unsignedIntToString( iid );
4315        syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() );
4316      return querySimple( "setCertifyState", sql );      return querySimple( "setCertifyState", sql );
4317  }  }
4318    
# Line 4358  bool getCertifyPermission( sessionid_t s Line 4344  bool getCertifyPermission( sessionid_t s
4344          sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";          sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
4345          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";
4346          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";
4347          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid AND tx.open_level =" + unsignedIntToString( index::OL_GROUP_ONLY );;          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid";
4348          sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );          sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );
4349      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );
4350          sql += " AND ti.item_id=" + unsignedIntToString( iid );          sql += " AND ti.item_id=" + unsignedIntToString( iid );
# Line 4746  bool isValidSessionID( sessionid_t sid ) Line 4732  bool isValidSessionID( sessionid_t sid )
4732          }          }
4733      }      }
4734            
 #ifdef USE_SYSLOG  
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
 #endif  
4735      sql = "SELECT * FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString( sid );      sql = "SELECT * FROM " + dbprefix + "_xnpaccount_session WHERE sid=" + unsignedIntToString( sid );
4736      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
4737          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
4738              if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){              if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
4739  #ifdef USE_SYSLOG                  syslog_printf( "isValidSessionID succeed" );
                 syslog( LOG_DEBUG, "isValidSessionID succeed" );  
 #endif  
4740                  ret = true;                  ret = true;
4741              }else{              }else{
4742                  string s( "SQLFetch in isValidSessionID " );                  string s( "SQLFetch in isValidSessionID " );
4743                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
4744                  s += string( ", sql=" ) + string( sql );                  s += string( ", sql=" ) + string( sql );
4745                  setLastErrorString( s.c_str() );                  setLastErrorString( s.c_str() );
4746  #ifdef USE_SYSLOG                  syslog_printf( "isValidSessionID %s", getLastErrorString( ) );
                 syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );  
 #endif  
4747                  ret = false;                  ret = false;
4748              }              }
4749          }else{          }else{
# Line 4772  bool isValidSessionID( sessionid_t sid ) Line 4751  bool isValidSessionID( sessionid_t sid )
4751              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
4752              s += string( ", sql=" ) + string( sql );              s += string( ", sql=" ) + string( sql );
4753              setLastErrorString( s.c_str( ) );              setLastErrorString( s.c_str( ) );
4754  #ifdef USE_SYSLOG              syslog_printf( "isValidSessionID %s", getLastErrorString( ) );
             syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );  
 #endif  
4755              ret = false;              ret = false;
4756          }          }
4757          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );          SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
# Line 4782  bool isValidSessionID( sessionid_t sid ) Line 4759  bool isValidSessionID( sessionid_t sid )
4759          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in isValidSessionID " );          string s( "SQLAllocHandle(SQL_HANDLE_STMT,...) in isValidSessionID " );
4760          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );          s += odbcDiagString( SQL_HANDLE_DBC, hdbc, sqlcode );
4761          setLastErrorString( s.c_str( ) );          setLastErrorString( s.c_str( ) );
4762  #ifdef USE_SYSLOG          syslog_printf( "isValidSessionID %s", getLastErrorString( ) );
         syslog( LOG_DEBUG, "isValidSessionID %s", getLastErrorString( ) );  
 #endif  
4763          ret = false;          ret = false;
4764      }      }
 #ifdef USE_SYSLOG  
     closelog( );  
 #endif  
4765      return ret;      return ret;
4766  }  }
4767    
# Line 5215  static result_t insertIndexInternal( ses Line 5187  static result_t insertIndexInternal( ses
5187              *xid = iid;              *xid = iid;
5188          }          }
5189          else {          else {
5190              sql = "DELETE FROM " + dbprefix + "_xnpaccount_item where item_id=" + unsignedIntToString( iid  );              string sql2 = "DELETE FROM " + dbprefix + "_xnpaccount_item_basic where item_id=" + unsignedIntToString( iid  );
5191              querySimple( "insertIndexInternal", sql );              querySimple( "insertIndexInternal", sql2 );
5192              string message( "in insertIndexInternal: bad uid/gid/openlevel. sql=" );              string message( "in insertIndexInternal: bad uid/gid/openlevel. sql=" );
5193              message = message + sql;              message = message + sql;
5194              setLastErrorString( message.c_str() );              setLastErrorString( message.c_str() );
# Line 6084  result_t getConfigValue( const char* key Line 6056  result_t getConfigValue( const char* key
6056              SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_CONFIG_NAME_LEN, 0, (SQLCHAR*)key, strlen(key), &cbKey );              SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_CONFIG_NAME_LEN, 0, (SQLCHAR*)key, strlen(key), &cbKey );
6057              if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){              if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
6058                  while( SQLFetch( hstmt ) == SQL_SUCCESS ){                  while( SQLFetch( hstmt ) == SQL_SUCCESS ){
                     string valuestr;  
6059                      SQLLEN length = 0;                      SQLLEN length = 0;
6060                      syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() );                      syslog_printf( "\nsql at %d=%s", __LINE__, sql.c_str() );
6061                      // get amount of data                      if( dbtype == DBTYPE_MYSQL ){
6062                      if( SQLGetData(hstmt, 1, SQL_C_BINARY, *value, 0, &length)                          // get amount of data
6063                          == SQL_SUCCESS_WITH_INFO ){                          if( SQLGetData(hstmt, 1, SQL_C_BINARY, *value, 0, &length)
6064                                == SQL_SUCCESS_WITH_INFO ){
6065                                                    
6066                          // Get all the data at once.                              // Get all the data at once.
6067                          *value = new char[ length + 1 ];                              *value = new char[ length + 1 ];
6068                          memset( *value, '\0', length + 1 );                              memset( *value, '\0', length + 1 );
6069                          if( SQLGetData(hstmt, 1, SQL_C_DEFAULT, *value,                              syslog_printf( "\ngetConfigValue length=%d", length );
6070                                         length, &length) == SQL_SUCCESS ){                              if( SQLGetData(hstmt, 1, SQL_C_DEFAULT, *value,
6071                              ret = RES_OK;                                             length, &length) == SQL_SUCCESS ){
6072                                    ret = RES_OK;
6073                                    syslog_printf( "\ngetConfigValue returns '%s'", *value );
6074                                    break;
6075                                }else{
6076                                    string s( "SQLGetData in getConfigValue" );
6077                                    s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
6078                                    s += "sql=";
6079                                    s += string( sql );
6080                                    setLastErrorString( s.c_str( ) );
6081                                    ret = RES_DB_QUERY_ERROR;
6082                                }
6083                          }else{                          }else{
6084                              string s( "SQLGetData in getConfigValue" );                              string s( "SQLGetData in getConfigValue" );
6085                              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );                              s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
6086                              s += "sql=";                              s += "sql=";
6087                              s += string( sql );                              s += string( sql );
6088                              setLastErrorString( s.c_str( ) );                              setLastErrorString( s.c_str( ) );
6089                              ret = RES_DB_QUERY_ERROR;                              ret = RES_DB_QUERY_ERROR;
6090                          }                          }
6091                      }else{                      }else if( dbtype == DBTYPE_SQLITE ){
6092                          string s( "SQLGetData in getConfigValue" );                          string val = getResultCol( hstmt, 1 );
6093                          s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );                          *value = new char[ val.length() + 1 ];                    
6094                          s += "sql=";                          strcpy( *value, val.c_str() );
6095                          s += string( sql );                          syslog_printf( "\ngetConfigValue value=%s", *value );
6096                          setLastErrorString( s.c_str( ) );                          ret = RES_OK;
6097                          ret = RES_DB_QUERY_ERROR;                          break;
6098                      }                      }
                     break;  
6099                  }                  }
6100              }else{              }else{
6101                  string s( "SQLExecDirect in getConfigValue" );                  string s( "SQLExecDirect in getConfigValue" );
# Line 6310  const char* getLastErrorString() Line 6292  const char* getLastErrorString()
6292  void setLastErrorString( const char* str )  void setLastErrorString( const char* str )
6293  {  {
6294      errstr = str;      errstr = str;
6295  #ifdef USE_SYSLOG      syslog_printf( "%s", str );
     openlog( "commonal", LOG_ODELAY, LOG_USER );  
     syslog( LOG_DEBUG, "%s", str );  
     closelog( );  
 #endif  
6296      syslog_printf( "\nsetLastErrorString( '%s' );", str );      syslog_printf( "\nsetLastErrorString( '%s' );", str );
6297  }  }
6298    
# Line 6696  result_t getUncertifiedLink( sessionid_t Line 6674  result_t getUncertifiedLink( sessionid_t
6674          sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";          sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
6675          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id = tx.index_id";
6676          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id = ti.item_id";
6677          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid AND tx.open_level =" + unsignedIntToString( index::OL_GROUP_ONLY );;          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid";
6678          sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );          sql += " WHERE open_level<=" + unsignedIntToString( index::OL_GROUP_ONLY );
6679      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFY_REQUIRED );      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFY_REQUIRED );
6680      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );
# Line 6888  result_t getOwnPublicItemID( sessionid_t Line 6866  result_t getOwnPublicItemID( sessionid_t
6866      sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";      sql += " FROM " + dbprefix + "_xnpaccount_index_item_link AS tlink";
6867      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id=tx.index_id";      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_index AS tx ON tlink.index_id=tx.index_id";
6868      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id=ti.item_id";      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_item_basic AS ti ON tlink.item_id=ti.item_id";
6869      sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON tgulink.gid = tx.gid AND tx.open_level=" + unsignedIntToString( index::OL_GROUP_ONLY );          sql += " LEFT JOIN " + dbprefix + "_xnpaccount_groups_users_link AS tgulink ON ( tgulink.gid = tx.gid AND tx.open_level =" + unsignedIntToString( index::OL_GROUP_ONLY );
6870        sql += ") OR tx.open_level=" + unsignedIntToString( index::OL_PUBLIC );
6871      sql += " WHERE open_level=" + unsignedIntToString( index::OL_PUBLIC );      sql += " WHERE open_level=" + unsignedIntToString( index::OL_PUBLIC );
6872      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFIED );      sql += " AND certify_state=" + unsignedIntToString( index::CERTIFIED );
6873      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );      sql += " AND item_type_id !=" + unsignedIntToString( item::ITID_INDEX );

Legend:
Removed from v.1.71  
changed lines
  Added in v.1.72

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