Changeset 489

Show
Ignore:
Timestamp:
04/07/06 10:18:22 (2 years ago)
Author:
common
Message:

library
- sqlhandler-postgres PQgetResult() can come up more than one time, therefore i had to change the sqlresult serialisation in doRecv()
- sqlhandler-postgres we should not send any new query during processing a current query, this happend when a SQLQuery's callback created a new query, now we dont allow sending new results while processing an result, and we are done.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/trunk/modules/sqlhandler-postgres/sqlhandler-postgres.cpp

    r488 r489  
    8585 
    8686        g_Library = library; 
     87        m_LockSend = false; 
    8788} 
    8889 
     
    145146        logPF(); 
    146147        m_Queries.push_back(query); 
    147         if (PQisBusy(m_PGConnection) == 0
     148        if (PQisBusy(m_PGConnection) == 0 && m_LockSend == false
    148149        { 
    149150                logInfo("sending query %s\n",m_Queries.front()->getQuery().c_str()); 
     
    177178{ 
    178179        logPF(); 
    179         if (PQconsumeInput(m_PGConnection) == 1) 
    180         { 
    181                 if (PQisBusy(m_PGConnection) == 0) 
     180        if ( PQconsumeInput(m_PGConnection) != 1 ) 
     181                return 1; 
     182 
     183        if ( PQisBusy(m_PGConnection) != 0 ) 
     184                return 1; 
     185 
     186        PGresult   *res=NULL; 
     187        PGSQLResult *sqlresult = NULL; 
     188        SQLQuery *sqlquery = m_Queries.front(); 
     189        m_Queries.pop_front(); 
     190 
     191//      int foo = rand()%1024; 
     192 
     193        vector< map<string,string> >        result; 
     194 
     195        while ( (res = PQgetResult(m_PGConnection)) != NULL ) 
     196        { 
     197//              logCrit("README %i %x %x\n",foo,res,sqlquery); 
     198                switch ( PQresultStatus(res) ) 
    182199                { 
    183                         PGresult   *res=NULL; 
    184                         PGSQLResult *sqlresult = NULL; 
    185                         while ( (res = PQgetResult(m_PGConnection)) != NULL ) 
     200                case PGRES_COMMAND_OK: 
     201                        break; 
     202                case PGRES_TUPLES_OK: 
     203                        if ( sqlquery->getCallback() != NULL ) 
    186204                        { 
    187                                 switch (PQresultStatus(res)) 
     205                                int i,j; 
     206                                for ( j = 0;  j < PQntuples(res); j++ ) 
    188207                                { 
    189                                 case PGRES_COMMAND_OK: 
    190                                 case PGRES_TUPLES_OK: 
    191                     break; 
    192  
    193                                 default: 
    194                                         logCrit("Query failure. Query'%s' Error '%s' ('%s')\n", 
    195                                                         m_Queries.front()->getQuery().c_str(), 
    196                                                         PQresStatus(PQresultStatus(res)), 
    197                                                 PQresultErrorMessage(res)); 
    198                                 } 
    199  
    200  
    201                                 if ( m_Queries.front()->getCallback() != NULL ) 
    202                                 { 
    203  
    204                                         sqlresult = new PGSQLResult(res,m_Queries.front()->getQuery(),m_Queries.front()->getObject()); 
    205  
    206                                         switch (PQresultStatus(res)) 
     208                                        map<string,string> foo; 
     209                                        for ( i=0;i<PQnfields(res);i++ ) 
    207210                                        { 
    208                                         case PGRES_COMMAND_OK: 
    209                                         case PGRES_TUPLES_OK: 
    210                                                 m_Queries.front()->getCallback()->sqlSuccess(sqlresult); 
    211                                                 break; 
    212  
    213                                         default: 
    214                                                 m_Queries.front()->getCallback()->sqlFailure(sqlresult); 
     211                                                foo[PQfname(res,i)] = PQgetvalue(res, j, i); 
    215212                                        } 
    216  
    217                                         delete sqlresult; 
     213                                        result.push_back(foo); 
     214 
    218215                                } 
    219216                        } 
    220  
    221                         PQclear(res); 
    222  
    223                         delete m_Queries.front(); 
    224                         m_Queries.pop_front(); 
    225  
    226                         if (m_Queries.size() > 0) 
    227                         { 
    228                                 logInfo("sending query %s\n",m_Queries.front()->getQuery().c_str()); 
    229                                 int ret = PQsendQuery(m_PGConnection, m_Queries.front()->getQuery().c_str()); 
    230                                 if (ret != 1) 
    231                                         logCrit("ERROR %i %s\n",ret,PQerrorMessage(m_PGConnection)); 
    232                         } 
    233  
    234  
    235  
     217                        break; 
     218 
     219                default: 
     220                        logCrit("Query failure. Query'%s' Error '%s' ('%s')\n", 
     221                                        sqlquery->getQuery().c_str(), 
     222                                        PQresStatus(PQresultStatus(res)), 
     223                                        PQresultErrorMessage(res)); 
     224                        return 1; 
    236225                } 
     226 
     227                PQclear(res); 
     228 
     229        } 
     230        if ( sqlquery->getCallback() != NULL ) 
     231        { 
     232                m_LockSend = true; 
     233                sqlresult = new PGSQLResult(&result,sqlquery->getQuery(),sqlquery->getObject()); 
     234                sqlquery->getCallback()->sqlSuccess(sqlresult); 
     235                delete sqlresult; 
     236                m_LockSend = false; 
     237 
     238        } 
     239 
     240        delete sqlquery; 
     241 
     242 
     243 
     244        if ( m_Queries.size() > 0 ) 
     245        { 
     246                logInfo("sending query %s\n",m_Queries.front()->getQuery().c_str()); 
     247                int ret = PQsendQuery(m_PGConnection, m_Queries.front()->getQuery().c_str()); 
     248                if ( ret != 1 ) 
     249                        logCrit("ERROR %i %s\n",ret,PQerrorMessage(m_PGConnection)); 
    237250        } 
    238251        return 1; 
  • library/trunk/modules/sqlhandler-postgres/sqlhandler-postgres.hpp

    r488 r489  
    7070                PGconn *m_PGConnection; 
    7171                Library *m_Library; 
     72 
     73                bool    m_LockSend; 
     74 
    7275                list <SQLQuery *>       m_Queries; 
    7376 
     
    99102                        } 
    100103                } 
     104 
     105                PGSQLResult(vector< map<string,string> > *result, string query, void *obj) : SQLResult(query,obj) 
     106                { 
     107                        m_Result = *result; 
     108                } 
     109 
    101110        }; 
    102111