qtinternetradio/irdb/src/searchrltwrapper.cpp
changeset 16 5723da102db1
child 17 38bbf2dcd608
equal deleted inserted replaced
15:065198191975 16:5723da102db1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Description: 
       
    13 *
       
    14 */
       
    15 
       
    16 #include <QSqlQuery>
       
    17 #include <QVariant>
       
    18 #include "searchrltwrapper.h"
       
    19 #include "irdb.h"
       
    20 
       
    21 searchRltWrapper::searchRltWrapper()
       
    22 {     
       
    23 }
       
    24 
       
    25 searchRltWrapper::~searchRltWrapper()
       
    26 {
       
    27 } 
       
    28 
       
    29 /*
       
    30 * this fuction don't suport "update" operation for mutliple records ;
       
    31 * if condAND != NULL AND condOR != NULL, illegal operation;
       
    32 * if condAND != NULL or condOR != NULL, it must be "update" operation.
       
    33 * if condAND == NULL AND condOR == NULL, it is "insert" or "update" operation;
       
    34 * 
       
    35 */
       
    36 bool searchRltWrapper::putSearchRlt(const columnMap* const RowData,
       
    37                                     const logoMap*   const logoData,
       
    38                                     const columnMap* const condAND,
       
    39                                     const columnMap* const condOR)
       
    40 {
       
    41     uint uCid = 0;
       
    42     QString insSqlStr;
       
    43     QString updSqlStr;
       
    44     QString condSqlStr;       
       
    45     QString condUserCidStr;
       
    46     columnMap* const RowDataAppend = const_cast<columnMap*>(RowData);
       
    47     QList<QByteArray>* pImgList = NULL;
       
    48     bool ret = true;
       
    49     
       
    50     if( NULL == RowData )
       
    51     {
       
    52         return false;
       
    53     }
       
    54 
       
    55     if(RowData->isEmpty())
       
    56     {
       
    57         return false;
       
    58     }
       
    59 
       
    60 
       
    61     if( (NULL != condAND)&&(NULL != condOR) )
       
    62     {
       
    63         return false;
       
    64     }
       
    65 
       
    66     if(condAND)
       
    67     {
       
    68         if(condAND->isEmpty())
       
    69         {
       
    70             return false;
       
    71         }
       
    72     }
       
    73 
       
    74     if(condOR)
       
    75     {
       
    76         if(condOR->isEmpty())
       
    77         {
       
    78             return false;
       
    79         }
       
    80     }
       
    81     
       
    82     insSqlStr = "insert into IRBuff ";   
       
    83     updSqlStr = "update IRBuff set ";
       
    84     RowDataAppend->insert(dataSource, QString::number(DATA_OF_SEARCHRLT));
       
    85     RowDataAppend->insert(opt, QString::number(IRDB_OPT_INSERT));    
       
    86  
       
    87     if(NULL != logoData)
       
    88     {
       
    89         pImgList = new QList<QByteArray>();
       
    90         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr, logoData, pImgList); 
       
    91     
       
    92     }
       
    93     else
       
    94     {
       
    95         combinePutStr(RowDataAppend, colNameView, insSqlStr, updSqlStr);
       
    96     }      
       
    97     
       
    98     if( (NULL == condAND)&&(NULL == condOR) )
       
    99     {
       
   100         uCid = srhChannelId(condUserCidStr,RowData);
       
   101     }
       
   102     else //here it must be "update" operation; condition string 
       
   103     {
       
   104         uCid = srhChannelId(condUserCidStr,condAND, condOR);
       
   105         combineCondStr(condAND, condOR, colNameView,condSqlStr);
       
   106     }
       
   107 
       
   108     if(uCid)
       
   109     {
       
   110         //updSqlStr += condSqlStr;
       
   111         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, uCid, condSqlStr, pImgList)? ret = false:true;
       
   112     }
       
   113     else //here deliver the updSqlstr and condSqlStr seperately.
       
   114     {
       
   115         m_pIRDB->chgRowIRDB(insSqlStr, updSqlStr, NULL, condSqlStr, condUserCidStr, pImgList)?ret = false:true;
       
   116     }    
       
   117 
       
   118     if(pImgList)
       
   119     {
       
   120         delete pImgList;
       
   121         pImgList = NULL;
       
   122     }
       
   123     
       
   124     return ret;
       
   125 }    
       
   126 
       
   127 QList<QVariant*>*  searchRltWrapper::getSearchRlt(const columnMap* const condAND,  
       
   128                                                   const columnMap* const condOR)
       
   129 {
       
   130     QString sltSqlStr = "select * from IRVIEW_searchRlt ";
       
   131     QList<QVariant*>* pDataSet = NULL;
       
   132     
       
   133     if( (NULL != condAND)&&(NULL != condOR) )
       
   134     {
       
   135         return NULL;
       
   136     }
       
   137 
       
   138     if(condAND)
       
   139     {
       
   140         if(condAND->isEmpty())
       
   141         {
       
   142             return NULL;
       
   143         }
       
   144     }
       
   145 
       
   146     if(condOR)
       
   147     {
       
   148         if(condOR->isEmpty())
       
   149         {
       
   150             return NULL;
       
   151         }
       
   152     }
       
   153 
       
   154     combineGetStr(condAND, condOR, colNameView, sltSqlStr);
       
   155     pDataSet = new QList<QVariant*>();
       
   156     if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
       
   157     {
       
   158         delete pDataSet;
       
   159         pDataSet = NULL;
       
   160     }
       
   161     
       
   162     return pDataSet;
       
   163 }
       
   164 
       
   165 
       
   166 bool searchRltWrapper::deleteSearchRlt(const columnMap* const condAND,
       
   167                                        const columnMap* const condOR)
       
   168 {
       
   169     QString deleteSqlStr = "delete from searchRlt ";
       
   170     
       
   171     if( (NULL != condAND)&&(NULL != condOR) )
       
   172     {
       
   173         return false;
       
   174     }
       
   175 
       
   176     if(condAND)
       
   177     {
       
   178         if(condAND->isEmpty())
       
   179         {
       
   180             return false;
       
   181         }
       
   182     }
       
   183 
       
   184     if(condOR)
       
   185     {
       
   186         if(condOR->isEmpty())
       
   187         {
       
   188             return false;
       
   189         }
       
   190     }
       
   191 
       
   192     combineDeleteStr(condAND, condOR, colNameView, deleteSqlStr);
       
   193     return m_pIRDB->deleteRow(deleteSqlStr)? false:true;
       
   194 }
       
   195 
       
   196 
       
   197 bool searchRltWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pDataSet)
       
   198 {
       
   199 
       
   200     while (aIRDataSet.next()) 
       
   201     {
       
   202         QVariant* const p = new QVariant[IRDB_SEARCHRLT_COLUMN];
       
   203 
       
   204         *pDataSet<<p;
       
   205 
       
   206         for(int i = 0; i < IRDB_SEARCHRLT_COLUMN; i++)
       
   207         {
       
   208             *(p+i) = aIRDataSet.value(i);
       
   209         }
       
   210     }
       
   211 
       
   212     return true;
       
   213 }
       
   214 
       
   215 uint searchRltWrapper::srhChannelId(QString& condUserCidStr,
       
   216                                     const columnMap* const condAND,
       
   217                                     const columnMap* const condOR)
       
   218 {
       
   219     uint srhCID = 0;
       
   220 
       
   221     //if condAND or condOR has channeld,
       
   222     if(condAND != NULL)
       
   223     {
       
   224         srhCID = (condAND->value(channelId)).toUInt();         
       
   225     } 
       
   226     else if(condOR != NULL)
       
   227     {
       
   228         srhCID = (condOR->value(channelId)).toUInt();         
       
   229     }
       
   230 
       
   231     if(srhCID)
       
   232     {
       
   233         return srhCID ;
       
   234     }
       
   235 
       
   236     //channelId column is false
       
   237     //only one case, go to station view, channelUrl and channelNickName
       
   238     //search channelId according to urlinof and channelNickName;
       
   239     QString srhStr;
       
   240     if(condAND != NULL)
       
   241     {
       
   242         if( ( !(condAND->value(channelUrl).isEmpty())  )&&( !(condAND->value(channelNickName).isEmpty()) ) )
       
   243         {
       
   244             srhStr = "where "+ colNameView[channelUrl] + " = ";
       
   245             srhStr = srhStr + "'" + condAND->value(channelUrl) + "' AND " ;
       
   246             srhStr = srhStr + colNameView[channelNickName] + " = ";
       
   247             srhStr = srhStr + "'" + condAND->value(channelNickName) + "'";
       
   248         }
       
   249         condUserCidStr = srhStr;
       
   250     }
       
   251           
       
   252     return srhCID;
       
   253 }
       
   254