qtinternetradio/irdb/src/urlinfowrapper.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 <QStringList>
       
    19 
       
    20 #include "urlinfowrapper.h"
       
    21 #include "irdb.h"
       
    22 
       
    23 urlInfoWrapper::urlInfoWrapper()
       
    24 {     
       
    25 }
       
    26 
       
    27 urlInfoWrapper::~urlInfoWrapper()
       
    28 {
       
    29 } 
       
    30 
       
    31 bool urlInfoWrapper::resetUrlInfo(const columnUrlInfoInsertMap* const RowData,
       
    32                                   const uint& channelId)
       
    33 {
       
    34     QStringList insSqlStrList;
       
    35 
       
    36     if(!channelId)
       
    37     {
       
    38         return false;	
       
    39     }
       
    40 
       
    41     if( NULL == RowData )
       
    42     {
       
    43         return false;
       
    44     }
       
    45 
       
    46     if(RowData->isEmpty())
       
    47     {
       
    48         return false;
       
    49     }
       
    50 
       
    51     combineInsertStr(RowData, channelId, insSqlStrList);
       
    52     return m_pIRDB->resetUrlInfo(insSqlStrList, channelId)? false:true;  
       
    53 }
       
    54 
       
    55 void urlInfoWrapper::combineInsertStr(const columnUrlInfoInsertMap* const RowData,
       
    56                                       const uint& channelId,	    
       
    57                                       QStringList& insSqlStrList)
       
    58 {
       
    59     columnUrlInfoInsertMap::const_iterator it;
       
    60     QString insSqlStr;  
       
    61     it = RowData->begin();
       
    62     while(it != RowData->end())
       
    63     {
       
    64         insSqlStr = "Insert into urlinfo(channelUrl, channelId, bitrate) values(";
       
    65         insSqlStr += "'" +it.key()+ "'" +", ";
       
    66         insSqlStr += QString::number(channelId);
       
    67         insSqlStr += ", ";
       
    68         insSqlStr += QString::number(it.value());  
       
    69         insSqlStr += " )" ;
       
    70         
       
    71         insSqlStrList<<insSqlStr;
       
    72         
       
    73         ++it;
       
    74     }
       
    75     
       
    76     return;        
       
    77 }
       
    78 
       
    79 QList<QVariant*>* urlInfoWrapper::getUrlInfo(const columnMap* const condAND,  
       
    80                                              const columnMap* const condOR)
       
    81 {
       
    82     QString sltSqlStr = "select channelUrl, channelId, bitRate from urlInfo ";
       
    83     QList<QVariant*>* pDataSet = NULL;
       
    84     
       
    85     if( (NULL != condAND)&&(NULL != condOR) )
       
    86     {
       
    87         return NULL;
       
    88     }
       
    89 
       
    90     if(condAND)
       
    91     {
       
    92         if(condAND->isEmpty())
       
    93         {
       
    94             return false;
       
    95         }
       
    96     }
       
    97 
       
    98     if(condOR)
       
    99     {
       
   100         if(condOR->isEmpty())
       
   101         {
       
   102             return false;
       
   103         }
       
   104     }
       
   105 
       
   106     combineGetStr(condAND, condOR, colNameView, sltSqlStr);
       
   107     pDataSet = new QList<QVariant*>(); 
       
   108     if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
       
   109     {
       
   110         delete pDataSet;
       
   111         pDataSet = NULL;
       
   112     }
       
   113     
       
   114     return pDataSet;
       
   115 }
       
   116 
       
   117 bool urlInfoWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pDataSet)
       
   118 {
       
   119     while (aIRDataSet.next()) 
       
   120     {
       
   121         QVariant* const p = new QVariant[IRDB_URLINFO_COLUMN];
       
   122         *pDataSet<<p;
       
   123 
       
   124         for(int i = 0; i < IRDB_URLINFO_COLUMN; i++)
       
   125         {
       
   126             *(p+i) = aIRDataSet.value(i);
       
   127         }
       
   128     }
       
   129 
       
   130     return true;
       
   131 }
       
   132 
       
   133