qtinternetradio/irdb/src/channelhistorywrapper.cpp
changeset 17 38bbf2dcd608
parent 16 5723da102db1
equal deleted inserted replaced
16:5723da102db1 17:38bbf2dcd608
    73     }
    73     }
    74 
    74 
    75     return true;
    75     return true;
    76 }
    76 }
    77 
    77 
    78 uint channelHistoryWrapper::srhChannelId(QString& condUserCidStr,
    78 uint channelHistoryWrapper::srhChannelId(const columnMap* const condAND,
    79                                          const columnMap* const condAND,
       
    80                                          const columnMap* const condOR)
    79                                          const columnMap* const condOR)
    81 {
    80 {
    82     uint srhCID = 0;
    81     uint srhCID = 0;
    83 
    82 
    84     //if condAND or condOR has channeld,
    83     //if condAND or condOR has channeld,
    88     } 
    87     } 
    89     else if(condOR != NULL)
    88     else if(condOR != NULL)
    90     {
    89     {
    91         srhCID = (condOR->value(channelId)).toUInt();         
    90         srhCID = (condOR->value(channelId)).toUInt();         
    92     }
    91     }
    93 
    92 #if 0 
    94     if(srhCID)
    93     if(srhCID)
    95     {
    94     {
    96         return srhCID ;
    95         return srhCID ;
    97     }
    96     }
    98 
    97 
       
    98    
    99     //channelId column is false
    99     //channelId column is false
   100     //only one case, go to station view, channelUrl and channelNickName
   100     //only one case, go to station view, channelUrl and channelNickName
   101     //search channelId according to urlinof and channelNickName;
   101     //search channelId according to urlinof and channelNickName;
   102     QString srhStr;
   102     QString srhStr;
   103     if(condAND != NULL)
   103     if(condAND != NULL)
   104     {
   104     {
   105         if( ( !(condAND->value(channelUrl).isEmpty())  )&&( !(condAND->value(channelNickName).isEmpty()) ) )
   105         if( ( !(condAND->value(channelUrl).isEmpty())  )&&( !(condAND->value(channelNickName).isEmpty()) ) )
   106         {
   106         {
       
   107             QString escStr;
       
   108         
   107             srhStr = "where "+ colNameView[channelUrl] + " = ";
   109             srhStr = "where "+ colNameView[channelUrl] + " = ";
   108             srhStr = srhStr + "'" + condAND->value(channelUrl) + "' AND " ;
   110             escStr = condAND->value(channelUrl);
       
   111             escStr.replace('\'', "\'\'");
       
   112             srhStr = srhStr + "'" + escStr + "' AND " ;
       
   113 
   109             srhStr = srhStr + colNameView[channelNickName] + " = ";
   114             srhStr = srhStr + colNameView[channelNickName] + " = ";
   110             srhStr = srhStr + "'" + condAND->value(channelNickName) + "'";
   115             escStr = condAND->value(channelNickName);
       
   116             escStr.replace('\'', "\'\'");
       
   117             srhStr = srhStr + "'" + escStr + "'";
   111         }
   118         }
   112         condUserCidStr = srhStr;
   119         condUserCidStr = srhStr;
   113     }
   120     }
   114           
   121 #endif
       
   122     
   115     return srhCID;
   123     return srhCID;
   116 }
   124 }
   117 
   125 
   118 /*
   126 /*
   119 * this fuction don't suport "update" operation for mutliple records ;
   127 * this fuction don't suport "update" operation for mutliple records ;
   134     QString condSqlStr;       
   142     QString condSqlStr;       
   135     QString condUserCidStr;
   143     QString condUserCidStr;
   136     columnMap* const RowDataAppend = const_cast<columnMap*>(RowData);
   144     columnMap* const RowDataAppend = const_cast<columnMap*>(RowData);
   137     QList<QByteArray>* pImgList = NULL;
   145     QList<QByteArray>* pImgList = NULL;
   138     bool ret = true;
   146     bool ret = true;
   139 
   147     int logoType = 0;
   140 
   148 
   141     if( NULL == RowData )
   149 
       
   150     if( ( NULL == RowData )&&(NULL == logoData) )
   142     {
   151     {
   143         return false;
   152         return false;
   144     }
   153     }
   145 
   154     
   146     if(RowData->isEmpty())
   155     if(RowData)
       
   156     {
       
   157         if(RowData->isEmpty())
       
   158         {
       
   159             return false;
       
   160         }
       
   161     }
       
   162 
       
   163     if(logoData)
       
   164     {
       
   165         if(logoData->isEmpty())
       
   166         {
       
   167             return false;
       
   168         }      
       
   169     }
       
   170     if( (NULL != condAND)&&(NULL != condOR) )
   147     {
   171     {
   148         return false;
   172         return false;
   149     }
   173     }
   150 
   174 
   151 
       
   152     if( (NULL != condAND)&&(NULL != condOR) )
       
   153     {
       
   154         return false;
       
   155     }
       
   156 
       
   157     if(condAND)
   175     if(condAND)
   158     {
   176     {
   159         if(condAND->isEmpty())
   177         if(condAND->isEmpty())
   160         {
   178         {
   161             return false;
   179             return false;
   166     {
   184     {
   167         if(condOR->isEmpty())
   185         if(condOR->isEmpty())
   168         {
   186         {
   169             return false;
   187             return false;
   170         }
   188         }
   171     }
       
   172     
       
   173     if(cidUserDefined)
       
   174     {
       
   175         *cidUserDefined = 0;	
       
   176     }
   189     }
   177     
   190     
   178     insSqlStr = "insert into IRBuff ";   
   191     insSqlStr = "insert into IRBuff ";   
   179     updSqlStr = "update IRBuff set ";
   192     updSqlStr = "update IRBuff set ";
   180     RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT));    
   193     RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT));    
   181     RowDataAppend->insert(dataSource, QString::number(DATA_OF_CHANNELHISTORY));
   194     RowDataAppend->insert(dataSource, QString::number(DATA_OF_CHANNELHISTORY));
   182     
   195     
   183     if(NULL != logoData)
   196     if(NULL != logoData)
   184     {
   197     {
   185         pImgList = new QList<QByteArray>();
   198         pImgList = new QList<QByteArray>();
   186         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList); 
   199         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList, &logoType); 
   187         *pImgList=logoData->values();
   200         //*pImgList=logoData->values();
   188     
   201     
   189     }
   202     }
   190     else
   203     else
   191     {
   204     {
   192         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr);
   205         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr);
   193     }    
   206     }    
   194                                         
   207                                         
   195     if( (NULL == condAND)&&(NULL == condOR) )
   208     if( (NULL == condAND)&&(NULL == condOR) )
   196     {
   209     {
   197         uCid = srhChannelId(condUserCidStr,RowData);
   210         uCid = srhChannelId(RowData);
   198     }
   211     }
   199     else //here it must be "update" operation; condition string 
   212     else //here it must be "update" operation; condition string 
   200     {
   213     {
   201         uCid = srhChannelId(condUserCidStr,condAND, condOR);
   214         uCid = srhChannelId(condAND, condOR);
   202         combineCondStr(condAND, condOR, colNameView, condSqlStr);
   215         combineCondStr(condAND, condOR, colNameView, condSqlStr);
   203     }
   216     }
   204 
   217 
   205     if(uCid)
   218     if(uCid)
   206     {
   219     {
   207         //updSqlStr += condSqlStr;
   220         //updSqlStr += condSqlStr;
   208         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList)? ret = false:true;
   221         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList, logoType)? ret = false:true;
   209     }
   222     }
   210     else //here deliver the updSqlstr and condSqlStr seperately.
   223     else //here deliver the updSqlstr and condSqlStr seperately.
   211     {
   224     {
   212         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, cidUserDefined, condSqlStr, condUserCidStr, pImgList)?ret = false:true;
   225         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, cidUserDefined, condSqlStr, condUserCidStr, pImgList, logoType)?ret = false:true;
   213     }  
   226     }  
   214     
   227     
   215     if(pImgList)
   228     if(pImgList)
   216     {
   229     {
   217         delete pImgList;
   230         delete pImgList;
   246         {
   259         {
   247             return NULL;
   260             return NULL;
   248         }
   261         }
   249     }
   262     }
   250 
   263 
   251     sltSqlStr = "select * from IRView_channelinfo ";
   264     sltSqlStr = "select * from IRVIEW_CHANNELHISTORY ";
   252     combineGetStr(condAND, condOR, colNameView,sltSqlStr);
   265     combineGetStr(condAND, condOR, colNameView,sltSqlStr);
   253     pDataSet = new QList<QVariant*>();
   266     pDataSet = new QList<QVariant*>();
   254     if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
   267     if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
   255     {
   268     {
   256         delete pDataSet;
   269         delete pDataSet;