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.40 by aga, Mon Jan 17 00:15:05 2005 UTC revision 1.41 by aga, Wed Jan 19 00:06:51 2005 UTC
# Line 2  Line 2 
2   *   *
3   * $Revision$   * $Revision$
4   * $Log$   * $Log$
5     * Revision 1.41  2005/01/19 00:06:51  aga
6     * ・updateIndexで、同じ名前の兄弟があるか名前が空であるならエラーにした.
7     * ・createSessionで、uidがPlatformユーザでないかactivateされていないならエラーにした.
8     *
9   * Revision 1.40  2005/01/17 00:15:05  aga   * Revision 1.40  2005/01/17 00:15:05  aga
10   * ・deleteIndex, updateIndexに失敗することがあるのを修正.   * ・deleteIndex, updateIndexに失敗することがあるのを修正.
11   *   *
# Line 2822  void logoutUser( sessionid_t sid ) Line 2826  void logoutUser( sessionid_t sid )
2826  /**  /**
2827   *   *
2828   * セッションの作成.<br>   * セッションの作成.<br>
2829   * XOOPSのsessionテーブルに記録されたsess_idと引数sess_idが等しけれ   * XOOPSのsessionテーブルに記録されたsess_idと引数sess_idが等しく、
2830   * ば,session_tを作成する。   * uidがPlatformユーザとしてactivateされていればsessionid_tを作成する。
2831   * データベースにセッションと引数の情報を記録する   * データベースにセッションと引数の情報を記録する
2832   *   *
2833   * @param sessionid xoopsのsession_id   * @param sessionid xoopsのsession_id
# Line 2832  void logoutUser( sessionid_t sid ) Line 2836  void logoutUser( sessionid_t sid )
2836   * @return RES_OK   * @return RES_OK
2837   * @return RES_ERROR   * @return RES_ERROR
2838   * @return RES_DB_QUERY_ERROR   * @return RES_DB_QUERY_ERROR
2839     * @return RES_NO_SUCH_USER
2840   *   *
2841   */   */
2842  result_t createSession( const char* sess_id, userid_t uid, sessionid_t* session )  result_t createSession( const char* sess_id, userid_t uid, sessionid_t* session )
# Line 2843  result_t createSession( const char* sess Line 2848  result_t createSession( const char* sess
2848      SQLHANDLE hstmt = NULL;      SQLHANDLE hstmt = NULL;
2849      SQLRETURN sqlcode;      SQLRETURN sqlcode;
2850            
2851        sql = "SELECT count(*) from " + dbprefix + "_xnpaccount_users where uid=" + unsignedIntToString( uid ) + " and activate=1";
2852        unsigned int count;
2853        ret = queryGetUnsignedInt( "createSession", sql, &count );
2854        if ( ret != RES_OK )
2855            return ret;
2856        if ( count = 0 )
2857            return RES_NO_SUCH_USER; // bad uid or activate=0
2858        
2859      string escSess_id = addSlashes(sess_id);      string escSess_id = addSlashes(sess_id);
     sql = "SELECT sess_id from " + dbprefix + "_session where sess_id='" + escSess_id + "'";  
2860      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
2861          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          sql = "SELECT sess_id from " + dbprefix + "_session where sess_id=?";
2862              if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){          sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
2863                  ret = addSession( uid, session );          if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
2864              }else{              SQLINTEGER cbSess_id = SQL_NTS;
2865                  ret = RES_ERROR;              SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, strlen(sess_id), 0, (SQLCHAR*)sess_id, 0, &cbSess_id );
2866                if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
2867                    if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
2868                        ret = addSession( uid, session );
2869                    }else{
2870                        ret = RES_ERROR;
2871                    }
2872                }else {
2873                    ret = RES_DB_QUERY_ERROR;
2874              }              }
         }else {  
             ret = RES_DB_QUERY_ERROR;  
2875          }          }
2876      }else{      }else{
2877          ret = RES_DB_QUERY_ERROR;          ret = RES_DB_QUERY_ERROR;
# Line 4013  result_t insertIndex( sessionid_t sid, i Line 4031  result_t insertIndex( sessionid_t sid, i
4031      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
4032      string sql;      string sql;
4033            
4034      SQLINTEGER cbTitle = SQL_NTS, parentXIDInd = 0;      SQLINTEGER cbTitle = SQL_NTS;
     SQLINTEGER parentXID = index->getParentIndexID();  
4035      string indexTable = dbprefix + "_xnpaccount_index";      string indexTable = dbprefix + "_xnpaccount_index";
4036      string itemTable = dbprefix + "_xnpaccount_item_basic";      string itemTable = dbprefix + "_xnpaccount_item_basic";
4037      sql = "SELECT tx_parent.uid, tx_parent.gid, tx_parent.open_level, tx_child.index_id, ti_child.item_id "      sql = "SELECT tx_parent.uid, tx_parent.gid, tx_parent.open_level, tx_child.index_id, ti_child.item_id "
4038          " FROM " + indexTable + " AS tx_parent "          " FROM " + indexTable + " AS tx_parent "
4039          " LEFT JOIN " + indexTable + " AS tx_child ON tx_child.parent_index_id = tx_parent.index_id "          " LEFT JOIN " + indexTable + " AS tx_child ON tx_child.parent_index_id = tx_parent.index_id "
4040          " LEFT JOIN " + itemTable  + " AS ti_child ON tx_child.index_id = ti_child.item_id AND ti_child.title = ? AND ti_child.item_type_id = " + unsignedIntToString( item::ITID_INDEX ) +          " LEFT JOIN " + itemTable  + " AS ti_child ON tx_child.index_id = ti_child.item_id AND ti_child.title = ? AND ti_child.item_type_id = " + unsignedIntToString( item::ITID_INDEX ) +
4041          " WHERE tx_parent.index_id = ? ";          " WHERE tx_parent.index_id = " + unsignedIntToString( index->getParentIndexID() );
4042      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
4043          SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_TITLE_LEN, 0, (SQLCHAR *)index->getTitle(), strlen(index->getTitle()), &cbTitle );          SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, XNP_ITEM_TITLE_LEN, 0, (SQLCHAR *)index->getTitle(), strlen(index->getTitle()), &cbTitle );
         SQLBindParameter(hstmt,  2, SQL_PARAM_INPUT, SQL_C_ULONG, SQL_INTEGER, 10, 0, &parentXID, 0, &parentXIDInd );  
4044          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){          if( ( sqlcode = SQLExecDirect( hstmt, (SQLCHAR*)sql.c_str(), sql.length() ) ) == SQL_SUCCESS ){
4045              SQLUINTEGER parentUID = 0, parentGID = 0, parentOpenLevel = 0, childXID = 0, childItemID = 0;              SQLUINTEGER parentUID = 0, parentGID = 0, parentOpenLevel = 0, childXID = 0, childItemID = 0;
4046              SQLINTEGER len1, len2, len3, len4, len5;              SQLINTEGER len1, len2, len3, len4, len5;
# Line 4232  static result_t getAllIndexLink( indexLi Line 4248  static result_t getAllIndexLink( indexLi
4248  }  }
4249  #endif  #endif
4250    
4251    result_t checkTitleConflict( sessionid_t sid, indexid_t parentIndexID, const char *title, bool *conflict ){
4252        SQLRETURN sqlcode;
4253        SQLHANDLE hstmt = NULL;    
4254        result_t result = RES_ERROR;
4255        
4256        string sql( "SELECT count(*) from " + dbprefix + "_xnpaccount_index as tx "
4257          " left join " + dbprefix + "_xnpaccount_item_basic as ti on ti.item_id=tx.index_id "
4258          " where parent_index_id = " + unsignedIntToString( parentIndexID ) +
4259          "   and ti.title = ? " );
4260        if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {
4261            sqlcode = SQLPrepare(hstmt, (SQLCHAR*)sql.c_str(), SQL_NTS);
4262            if( sqlcode == SQL_SUCCESS || sqlcode == SQL_SUCCESS_WITH_INFO ){
4263                SQLINTEGER cbTitle = SQL_NTS;
4264                SQLBindParameter(hstmt,  1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_LONGVARCHAR, strlen(title), 0, (SQLCHAR *)title, 0, &cbTitle );
4265                if( ( sqlcode = SQLExecute( hstmt ) ) == SQL_SUCCESS ){
4266                    SQLUINTEGER count = 0;
4267                    SQLINTEGER len;
4268                    SQLBindCol( hstmt, 1, SQL_C_ULONG, &count, 0, &len );
4269                    if( ( sqlcode = SQLFetch( hstmt ) ) == SQL_SUCCESS ){
4270                        if ( count == 0 ){
4271                            *conflict = false;
4272                            result = RES_OK;
4273                        }
4274                        else {
4275                            *conflict = true;
4276                            result = RES_OK;
4277                        }
4278                    } else {
4279                        setLastErrorString( "SQLFetch in checkTitleConflict" );
4280                        result = RES_ERROR;
4281                    }
4282                } else {
4283                    string
4284                    setLastErrorString( "SQLExec in checkTitleConflict" );
4285                    result = RES_ERROR;
4286                }
4287            } else {
4288                setLastErrorString( "SQLPrepare in checkTitleConflict" );
4289                result = RES_ERROR;
4290            }
4291            SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
4292        } else {
4293            setLastErrorString( "SQLAllocHandle in checkTitleConflict" );
4294            result =  RES_ERROR;
4295        }
4296        return result;
4297    }
4298    
4299    
4300    
4301    
4302  result_t updateIndexInternal( sessionid_t sid, userid_t uid, index_t *newIndex, const index_t *oldIndex, const index_t *newParentIndex, const index_t *oldParentIndex ){  result_t updateIndexInternal( sessionid_t sid, userid_t uid, index_t *newIndex, const index_t *oldIndex, const index_t *newParentIndex, const index_t *oldParentIndex ){
4303      bool move = ( newIndex->getParentIndexID() != oldIndex->getParentIndexID() );      bool move = ( newIndex->getParentIndexID() != oldIndex->getParentIndexID() );
# Line 4286  result_t updateIndexInternal( sessionid_ Line 4352  result_t updateIndexInternal( sessionid_
4352          }          }
4353      }      }
4354            
4355        // リネーム後のtitleが空文字列なら、リネームできない。
4356        if ( newIndex->getTitle()[0] == '\0' ){
4357            setLastErrorString( "in updateIndexInternal: empty title." );
4358            return RES_ERROR;
4359        }
4360        
4361        // リネーム・移動でtitleが衝突するなら、エラー。
4362        bool conflict = false;
4363        result = checkTitleConflict( sid, newIndex->getParentIndexID(), newIndex->getTitle(), &conflict );
4364        if ( result != RES_OK )
4365            return result;
4366        if ( conflict ){
4367            setLastErrorString( "in updateIndexInternal: title conflict" );
4368            return RES_ERROR;
4369        }
4370        
4371      if ( move ){      if ( move ){
4372          indexid_t *descXID = 0;          indexid_t *descXID = 0;
4373          int descXIDLen;          int descXIDLen;
# Line 4318  result_t updateIndexInternal( sessionid_ Line 4399  result_t updateIndexInternal( sessionid_
4399          }          }
4400          newIndex->setSortNumber( sortNumber );          newIndex->setSortNumber( sortNumber );
4401      }      }
4402        
4403        
4404        
4405        
4406      SQLRETURN sqlcode;      SQLRETURN sqlcode;
4407      SQLHANDLE hstmt = NULL;          SQLHANDLE hstmt = NULL;    
4408      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {      if( ( sqlcode = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt ) ) == SQL_SUCCESS ) {

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

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