qtinternetradio/irdb/src/searchrltwrapper.cpp
changeset 17 38bbf2dcd608
parent 16 5723da102db1
equal deleted inserted replaced
16:5723da102db1 17:38bbf2dcd608
    13 *
    13 *
    14 */
    14 */
    15 
    15 
    16 #include <QSqlQuery>
    16 #include <QSqlQuery>
    17 #include <QVariant>
    17 #include <QVariant>
       
    18 #include <QStringList>
    18 #include "searchrltwrapper.h"
    19 #include "searchrltwrapper.h"
    19 #include "irdb.h"
    20 #include "irdb.h"
    20 
    21 
    21 searchRltWrapper::searchRltWrapper()
    22 searchRltWrapper::searchRltWrapper()
    22 {     
    23 {     
    23 }
    24 }
    24 
    25 
    25 searchRltWrapper::~searchRltWrapper()
    26 searchRltWrapper::~searchRltWrapper()
    26 {
    27 {
    27 } 
    28 } 
       
    29 
       
    30 void searchRltWrapper::combineSqlStr(const uint &cid,
       
    31                                      const columnMap* const RowData, 
       
    32                                      QStringList &sqlList)
       
    33 {
       
    34     columnMap::const_iterator it;
       
    35     QString insSqlstrCnlInfo = "insert into channelInfo( ";
       
    36     QString insSqlstrImg     = "insert into img( ";
       
    37     QString insSqlstrSrhRlt  = "insert into searchrlt( "; 
       
    38     QString escStr;
       
    39     QString condStr = " where channelId ='" + QString::number(cid) + "' ";
       
    40 
       
    41     bool FstOfStatementCnl = true;
       
    42     bool FstOfStatementImg = true;
       
    43 
       
    44     it = RowData->begin();
       
    45     while(it != RowData->end())
       
    46     {
       
    47         if(channelId == it.key()) 
       
    48         {
       
    49             if(false == FstOfStatementCnl)
       
    50             {
       
    51                 insSqlstrCnlInfo += ", ";                
       
    52             }
       
    53         
       
    54             if(false == FstOfStatementImg)
       
    55             {
       
    56                 insSqlstrImg += ", ";                
       
    57             } 
       
    58             
       
    59             insSqlstrCnlInfo += colNameView[it.key()];
       
    60             insSqlstrImg += colNameView[it.key()];
       
    61             insSqlstrSrhRlt += colNameView[it.key()];
       
    62             FstOfStatementCnl = false;
       
    63             FstOfStatementImg = false;
       
    64         }
       
    65         
       
    66         if( (channelName == it.key()) ||(shortDesc == it.key()) )
       
    67         {
       
    68             if(false == FstOfStatementCnl)
       
    69             {
       
    70                 insSqlstrCnlInfo += ", ";                
       
    71             }
       
    72             
       
    73             insSqlstrCnlInfo += colNameView[it.key()];
       
    74             FstOfStatementCnl = false;
       
    75         }
       
    76         
       
    77         if(imgUrl == it.key())
       
    78         {
       
    79             if(false == FstOfStatementImg)
       
    80             {
       
    81                 insSqlstrImg += ", ";                
       
    82             }
       
    83             
       
    84             insSqlstrImg += colNameView[it.key()];
       
    85             FstOfStatementImg = false;
       
    86         }
       
    87 
       
    88         ++it;
       
    89     }
       
    90     
       
    91     insSqlstrCnlInfo += ") values(";
       
    92     insSqlstrImg += ") values(";
       
    93     insSqlstrSrhRlt += ") values(";
       
    94     FstOfStatementCnl = true;
       
    95     FstOfStatementImg = true;
       
    96         
       
    97     it = RowData->begin();
       
    98     while(it != RowData->end())
       
    99     {
       
   100         //here for escape char,
       
   101         escStr = it.value();
       
   102         escStr.replace('\'', "\'\'");
       
   103 
       
   104         if(channelId == it.key()) 
       
   105         {
       
   106             if(false == FstOfStatementCnl)
       
   107             {
       
   108                 insSqlstrCnlInfo += ", ";                
       
   109             }
       
   110             
       
   111             if(false == FstOfStatementImg)
       
   112             {
       
   113                 insSqlstrImg += ", ";                
       
   114             }
       
   115             
       
   116             insSqlstrCnlInfo  = insSqlstrCnlInfo + "'"+ escStr+ "'";
       
   117             insSqlstrImg      = insSqlstrImg + "'"+ escStr+ "'";
       
   118             insSqlstrSrhRlt   = insSqlstrSrhRlt + "'"+ escStr+ "'";
       
   119             FstOfStatementCnl = false;
       
   120             FstOfStatementImg = false;
       
   121         }
       
   122         
       
   123         if( (channelName == it.key()) ||(shortDesc == it.key()) )
       
   124         {
       
   125             if(false == FstOfStatementCnl)
       
   126             {
       
   127                 insSqlstrCnlInfo += ", ";                
       
   128             }
       
   129         
       
   130             insSqlstrCnlInfo = insSqlstrCnlInfo + "'"+ escStr+ "'";
       
   131             FstOfStatementCnl = false;                
       
   132         }
       
   133 
       
   134         if(imgUrl == it.key())
       
   135         {
       
   136             if(false == FstOfStatementImg)
       
   137             {
       
   138                 insSqlstrImg += ", ";                
       
   139             }
       
   140         
       
   141             insSqlstrImg = insSqlstrImg + "'"+ escStr+ "'";
       
   142             FstOfStatementImg = false;                  
       
   143         }            
       
   144           
       
   145         ++it;
       
   146     
       
   147     }    
       
   148     
       
   149     insSqlstrImg += ") ";
       
   150     insSqlstrCnlInfo += ") ";
       
   151     insSqlstrSrhRlt += ") ";
       
   152     
       
   153     QString updSqlStrCnlInfo = "update channelInfo set ";
       
   154     QString updSqlStrCnlImg = "update img set ";
       
   155     //part two, create update string;
       
   156     FstOfStatementCnl = true;
       
   157     FstOfStatementImg = true;
       
   158     
       
   159     it = RowData->begin();
       
   160      
       
   161     while( it != RowData->end())
       
   162     {
       
   163             //here for escape char,
       
   164         escStr = it.value();
       
   165         escStr.replace('\'', "\'\'");
       
   166         if( (channelName == it.key()) ||(shortDesc == it.key()) )
       
   167         {
       
   168             if(false == FstOfStatementCnl)
       
   169             {
       
   170                 updSqlStrCnlInfo += ", ";
       
   171             }
       
   172             updSqlStrCnlInfo = updSqlStrCnlInfo + colNameView[it.key()] + "=" + "'" + escStr + "'";
       
   173             FstOfStatementCnl = false;
       
   174         }
       
   175         if(imgUrl == it.key())
       
   176         {
       
   177             updSqlStrCnlImg = updSqlStrCnlImg + colNameView[it.key()] + "=" + "'" + escStr + "'";
       
   178         }  
       
   179 
       
   180         ++it;
       
   181     }
       
   182     updSqlStrCnlInfo += condStr;
       
   183     updSqlStrCnlImg  += condStr;
       
   184     sqlList<<insSqlstrCnlInfo<<insSqlstrImg<<insSqlstrSrhRlt<<updSqlStrCnlInfo<<updSqlStrCnlImg ;
       
   185     
       
   186     return;
       
   187 }
       
   188 
       
   189 
       
   190 bool searchRltWrapper::addSearchRlt(const columnMap* const RowData, bool bOpt)
       
   191 {
       
   192     uint uCid = 0;
       
   193     QStringList sqlStrList;
       
   194     
       
   195     if( NULL == RowData )
       
   196     {
       
   197         return false;
       
   198     }
       
   199 
       
   200     if(RowData->isEmpty())
       
   201     {
       
   202         return false;
       
   203     }
       
   204     uCid = srhChannelId(RowData);
       
   205     
       
   206     if(0 == uCid)
       
   207     {
       
   208         return false;
       
   209     }
       
   210     
       
   211     combineSqlStr(uCid, RowData, sqlStrList);
       
   212     
       
   213     return m_pIRDB->handleRstFromSrhView(uCid, sqlStrList, bOpt)? false:true;
       
   214           
       
   215 }
       
   216 
       
   217 void searchRltWrapper::addSearchRltFinished()
       
   218 {
       
   219     m_pIRDB->closeIRDBConnection();
       
   220     return;
       
   221 }
    28 
   222 
    29 /*
   223 /*
    30 * this fuction don't suport "update" operation for mutliple records ;
   224 * this fuction don't suport "update" operation for mutliple records ;
    31 * if condAND != NULL AND condOR != NULL, illegal operation;
   225 * if condAND != NULL AND condOR != NULL, illegal operation;
    32 * if condAND != NULL or condOR != NULL, it must be "update" operation.
   226 * if condAND != NULL or condOR != NULL, it must be "update" operation.
    44     QString condSqlStr;       
   238     QString condSqlStr;       
    45     QString condUserCidStr;
   239     QString condUserCidStr;
    46     columnMap* const RowDataAppend = const_cast<columnMap*>(RowData);
   240     columnMap* const RowDataAppend = const_cast<columnMap*>(RowData);
    47     QList<QByteArray>* pImgList = NULL;
   241     QList<QByteArray>* pImgList = NULL;
    48     bool ret = true;
   242     bool ret = true;
       
   243     int logoType = 0;
    49     
   244     
    50     if( NULL == RowData )
   245     if( NULL == RowData )
    51     {
   246     {
    52         return false;
   247         return false;
    53     }
   248     }
    85     RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT));    
   280     RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT));    
    86  
   281  
    87     if(NULL != logoData)
   282     if(NULL != logoData)
    88     {
   283     {
    89         pImgList = new QList<QByteArray>();
   284         pImgList = new QList<QByteArray>();
    90         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList); 
   285         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList, &logoType); 
    91     
   286     
    92     }
   287     }
    93     else
   288     else
    94     {
   289     {
    95         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr);
   290         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr);
    96     }      
   291     }      
    97     
   292     
    98     if( (NULL == condAND)&&(NULL == condOR) )
   293     if( (NULL == condAND)&&(NULL == condOR) )
    99     {
   294     {
   100         uCid = srhChannelId(condUserCidStr,RowData);
   295         uCid = srhChannelId(RowData);
   101     }
   296     }
   102     else //here it must be "update" operation; condition string 
   297     else //here it must be "update" operation; condition string 
   103     {
   298     {
   104         uCid = srhChannelId(condUserCidStr,condAND, condOR);
   299         uCid = srhChannelId(condAND, condOR);
   105         combineCondStr(condAND, condOR, colNameView,condSqlStr);
   300         combineCondStr(condAND, condOR, colNameView,condSqlStr);
   106     }
   301     }
   107 
   302 
   108     if(uCid)
   303     if(uCid)
   109     {
   304     {
   110         //updSqlStr += condSqlStr;
   305         //updSqlStr += condSqlStr;
   111         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList)? ret = false:true;
   306         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList, logoType)? ret = false:true;
   112     }
   307     }
   113     else //here deliver the updSqlstr and condSqlStr seperately.
   308     else //here deliver the updSqlstr and condSqlStr seperately.
   114     {
   309     {
   115         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, NULL, condSqlStr, condUserCidStr, pImgList)?ret = false:true;
   310         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, NULL, condSqlStr, condUserCidStr, pImgList, logoType)?ret = false:true;
   116     }    
   311     }    
   117 
   312 
   118     if(pImgList)
   313     if(pImgList)
   119     {
   314     {
   120         delete pImgList;
   315         delete pImgList;
   210     }
   405     }
   211 
   406 
   212     return true;
   407     return true;
   213 }
   408 }
   214 
   409 
   215 uint searchRltWrapper::srhChannelId(QString& condUserCidStr,
   410 uint searchRltWrapper::srhChannelId(const columnMap* const condAND,
   216                                     const columnMap* const condAND,
       
   217                                     const columnMap* const condOR)
   411                                     const columnMap* const condOR)
   218 {
   412 {
   219     uint srhCID = 0;
   413     uint srhCID = 0;
   220 
   414 
   221     //if condAND or condOR has channeld,
   415     //if condAND or condOR has channeld,
   225     } 
   419     } 
   226     else if(condOR != NULL)
   420     else if(condOR != NULL)
   227     {
   421     {
   228         srhCID = (condOR->value(channelId)).toUInt();         
   422         srhCID = (condOR->value(channelId)).toUInt();         
   229     }
   423     }
   230 
   424 #if 0
   231     if(srhCID)
   425     if(srhCID)
   232     {
   426     {
   233         return srhCID ;
   427         return srhCID ;
   234     }
   428     }
   235 
   429 
   246             srhStr = srhStr + colNameView[channelNickName] + " = ";
   440             srhStr = srhStr + colNameView[channelNickName] + " = ";
   247             srhStr = srhStr + "'" + condAND->value(channelNickName) + "'";
   441             srhStr = srhStr + "'" + condAND->value(channelNickName) + "'";
   248         }
   442         }
   249         condUserCidStr = srhStr;
   443         condUserCidStr = srhStr;
   250     }
   444     }
   251           
   445 #endif          
   252     return srhCID;
   446     return srhCID;
   253 }
   447 }
   254 
   448