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.39 by youi, Sat Jan 15 05:38:10 2005 UTC revision 1.40 by aga, Mon Jan 17 00:15:05 2005 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.40  2005/01/17 00:15:05  aga
6     * ・deleteIndex, updateIndexに失敗することがあるのを修正.
7     *
8   * Revision 1.39  2005/01/15 05:38:10  youi   * Revision 1.39  2005/01/15 05:38:10  youi
9   * insertAccount: 文字列バッファのサイズ調整など.   * insertAccount: 文字列バッファのサイズ調整など.
10   * updateAccount: 文字列バッファのサイズ調整など.   * updateAccount: 文字列バッファのサイズ調整など.
# Line 4109  result_t getDescendantIndexID( int xid, Line 4112  result_t getDescendantIndexID( int xid,
4112      /* *p 〜 *(pFill-1) : 未探索ノード。これが空になると探索終了。      /* *p 〜 *(pFill-1) : 未探索ノード。これが空になると探索終了。
4113         *pFill 〜 *(pEnd-1) : 空き領域。これが空になると、それ以上探索できないので異常終了         *pFill 〜 *(pEnd-1) : 空き領域。これが空になると、それ以上探索できないので異常終了
4114      */      */
4115      SQLRETURN sqlcode;      result = RES_ERROR;
4116      SQLHANDLE hstmt = NULL;          while ( true ) {
4117      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {          if ( p == pFill ){
4118          result = RES_ERROR;              // もう未探索ノードが無い。
4119          while ( true ) {              result = RES_OK;
4120              if ( p == pFill ){              break;
4121                  // もう未探索ノードが無い。          }
4122                  result = RES_OK;          else if ( pFill == pEnd ){
4123                  break;              // これ以上探索できない。
4124              }              result = RES_ERROR;
4125              else if ( pFill == pEnd ){              setLastErrorString( "getDescendantIndexID: index buffer overflow." );
4126                  // これ以上探索できない。              break;
4127                  result = RES_ERROR;          }
4128                  setLastErrorString( "getDescendantIndexID: index buffer overflow." );          
4129                  break;          xid = *p++; // 未探索ノードを1つ取り出す
4130              }          
4131                        // 子を列挙して未探索ノードとして追加。
4132              xid = *p++; // 未探索ノードを1つ取り出す          SQLRETURN sqlcode;
4133                        SQLHANDLE hstmt = NULL;    
4134              // 子を列挙して未探索ノードとして追加。          if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
4135              string sql = "SELECT index_id FROM " + dbprefix + "_xnpaccount_index WHERE parent_index_id=" + unsignedIntToString(xid);              string sql = "SELECT index_id FROM " + dbprefix + "_xnpaccount_index WHERE parent_index_id=" + unsignedIntToString(xid);
4136              if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){              if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
4137                  SQLUINTEGER sXID = 0;                  SQLUINTEGER sXID = 0;
# Line 4140  result_t getDescendantIndexID( int xid, Line 4143  result_t getDescendantIndexID( int xid,
4143                          break;                          break;
4144                  }                  }
4145              }else{              }else{
4146                  setLastErrorString( "SQLExecDirect in getDescendantIndexID" );                  string s( "SQLExecDirect in getDescendantIndexID" );
4147                  result = RES_ERROR;                  s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
4148                    s += "sql=";
4149                    s += string( sql );
4150                    setLastErrorString( s.c_str( ) );
4151                    result = RES_DB_QUERY_ERROR;
4152                  break;                  break;
4153              }              }
4154                SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
4155            }else{
4156                setLastErrorString( "SQLAllocHandle in getDescendantIndexID" );
4157                result = RES_ERROR;
4158          }          }
         SQLFreeHandle( SQL_HANDLE_STMT, hstmt );  
     }else{  
         setLastErrorString( "SQLAllocHandle in getDescendantIndexID" );  
         result = RES_ERROR;  
4159      }      }
4160            
4161      if ( result == RES_OK ){      if ( result == RES_OK ){
# Line 4230  result_t updateIndexInternal( sessionid_ Line 4237  result_t updateIndexInternal( sessionid_
4237      bool move = ( newIndex->getParentIndexID() != oldIndex->getParentIndexID() );      bool move = ( newIndex->getParentIndexID() != oldIndex->getParentIndexID() );
4238            
4239      result_t result = RES_ERROR;      result_t result = RES_ERROR;
     if ( ( oldIndex->getItemID() == item::IID_ROOT || oldIndex->getParentIndexID() == item::IID_ROOT || oldIndex->getIndexID() == item::IID_BINDERS )  
       && ( newIndex->getOwnerUID() != oldIndex->getOwnerUID()  
           || newIndex->getOwnerGID() != oldIndex->getOwnerGID()  
           || newIndex->getOpenLevel() != oldIndex->getOpenLevel() ) ){  
             setLastErrorString( "in updateIndex: cannot change owner/openlevel of system-created-index" );  
             return RES_ERROR; // Root/Binder/Public/Group/Privateの公開属性を書き換えることはできない。  
     }  
4240            
4241      // parent_index_idを書き換える場合は更に面倒なエラーチェックを行う      // parent_index_idを書き換える場合は更に面倒なエラーチェックを行う
4242      if ( move ){      if ( move ){
# Line 4252  result_t updateIndexInternal( sessionid_ Line 4252  result_t updateIndexInternal( sessionid_
4252              setLastErrorString( "in updateIndex: cannot change parent_index_id to ROOT" );              setLastErrorString( "in updateIndex: cannot change parent_index_id to ROOT" );
4253              return RES_ERROR; // 親がRootでないなら、親をRootにすることはできない。              return RES_ERROR; // 親がRootでないなら、親をRootにすることはできない。
4254          }          }
4255            else if ( oldIndex->getItemID() == item::IID_BINDERS && newParentIndex->getOpenLevel() != index::OL_PUBLIC ){
4256                setLastErrorString( "in updateIndex: BINDERS must be public" );
4257                return RES_ERROR; // BINDERSは必ず公開領域に置く必要がある。
4258            }
4259      }      }
4260            
4261      // 親ディレクトリに書き込めるかどうかチェック      // 親ディレクトリに書き込めるかどうかチェック
# Line 4513  result_t deleteIndex( sessionid_t sid, Line 4517  result_t deleteIndex( sessionid_t sid,
4517                  string strParentXID = unsignedIntToString( index->getParentIndexID() );                  string strParentXID = unsignedIntToString( index->getParentIndexID() );
4518                  for ( int i = descXIDLen-1; i >= 0; i-- ){ // 逆方向にして、途中で失敗した場合の惨事を防ぐ。descXIDは幅優先探索順に並んでいるので。                  for ( int i = descXIDLen-1; i >= 0; i-- ){ // 逆方向にして、途中で失敗した場合の惨事を防ぐ。descXIDは幅優先探索順に並んでいるので。
4519                      string strXID = unsignedIntToString(descXID[i]);                      string strXID = unsignedIntToString(descXID[i]);
4520                      string linkTable = dbprefix + "_index_item_link";                      string linkTable = dbprefix + "_xnpaccount_index_item_link";
4521                                            
4522                      // descXID[i] のアイテムの中で、被参照数が1のものを列挙 → 迷子にならないように移動                      // descXID[i] のアイテムの中で、被参照数が1のものを列挙 → 迷子にならないように移動
4523                      // HAVINGを使うべき? "select item_id, count(*) as v1, sum(index_id=$index_id) as v2 from $link_table having v1=1 and v2=1"                      // HAVINGを使うべき? "select item_id, count(*) as v1, sum(index_id=$index_id) as v2 from $link_table having v1=1 and v2=1"
# Line 4536  result_t deleteIndex( sessionid_t sid, Line 4540  result_t deleteIndex( sessionid_t sid,
4540                          if ( result != RES_OK )                          if ( result != RES_OK )
4541                              break;                              break;
4542                      }else{                      }else{
4543                          setLastErrorString( "SQLExecDirect in getDescendantIndexID" );                          string s( "SQLExecDirect in deleteIndex" );
4544                          result = RES_ERROR;                          s += odbcDiagString( SQL_HANDLE_STMT, hstmt, sqlcode );
4545                            s += "sql=";
4546                            s += string( sql );
4547                            setLastErrorString( s.c_str( ) );
4548                            result = RES_DB_QUERY_ERROR;
4549                          break;                          break;
4550                      }                      }
4551                                            
# Line 4546  result_t deleteIndex( sessionid_t sid, Line 4554  result_t deleteIndex( sessionid_t sid,
4554                      result = querySimple( functionName, sql );                      result = querySimple( functionName, sql );
4555                      if ( result == RES_OK ){                      if ( result == RES_OK ){
4556                          // descXID[i] を削除                          // descXID[i] を削除
4557                          sql = "DELETE from " + dbprefix + "_item_basic where item_id =" + strXID;                          sql = "DELETE from " + dbprefix + "_xnpaccount_item_basic where item_id =" + strXID;
4558                          result = querySimple( functionName, sql );                          result = querySimple( functionName, sql );
4559                          if ( result == RES_OK ){                          if ( result == RES_OK ){
4560                              sql = "DELETE from " + dbprefix + "_index      where index_id=" + strXID;                              sql = "DELETE from " + dbprefix + "_xnpaccount_index      where index_id=" + strXID;
4561                              result = querySimple( functionName, sql );                              result = querySimple( functionName, sql );
4562                          }                          }
4563                      }                      }

Legend:
Removed from v.1.39  
changed lines
  Added in v.1.40

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