qtinternetradio/irdb/src/imgwrapper.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 "imgwrapper.h"
       
    19 #include "irdb.h"
       
    20 
       
    21 imgWrapper::imgWrapper()
       
    22 {     
       
    23 }
       
    24 
       
    25 imgWrapper::~imgWrapper()
       
    26 {
       
    27 } 
       
    28 
       
    29 
       
    30 bool imgWrapper::updateImg(const columnMap* const RowData,
       
    31                            const uint& channelId,
       
    32                            const logoMap* const logoData)
       
    33 {
       
    34     QString insSqlStr;
       
    35     QString updSqlStr;
       
    36     QList<QByteArray>* pImgList = NULL;
       
    37     bool ret = true;
       
    38     
       
    39     if(!channelId)
       
    40     {
       
    41         return false;	
       
    42     }
       
    43 
       
    44     if( NULL == RowData )
       
    45     {
       
    46         return false;
       
    47     }
       
    48 
       
    49     if(RowData->isEmpty())
       
    50     {
       
    51         return false;
       
    52     }
       
    53 
       
    54     if( true != (RowData->value(channelId)).isEmpty() )
       
    55     {
       
    56         return false;
       
    57     }
       
    58 
       
    59     updSqlStr = "update img set ";
       
    60     if(NULL != logoData)
       
    61      {
       
    62          pImgList = new QList<QByteArray>();
       
    63          combinePutStr(RowData, colNameView, insSqlStr, updSqlStr, logoData, pImgList); 
       
    64      
       
    65      }
       
    66      else
       
    67      {
       
    68          combinePutStr(RowData, colNameView, insSqlStr, updSqlStr);
       
    69      }  
       
    70     
       
    71     //create insSqlstr and updSqlStr in advance;
       
    72     updSqlStr = updSqlStr + "where channelId = " + QString::number(channelId);
       
    73     
       
    74     m_pIRDB->updRowImg(channelId, updSqlStr, pImgList)? ret = false:true;
       
    75     if(pImgList)
       
    76     {
       
    77         delete pImgList;
       
    78         pImgList = NULL;
       
    79     }
       
    80     
       
    81     return ret;     
       
    82 }
       
    83 
       
    84 QList<QVariant*>* imgWrapper::getImg(const columnMap* const condAND,  
       
    85                                    const columnMap* const condOR)
       
    86 {
       
    87     QString sltSqlStr = "select * from IRVIEW_channelinfo ";
       
    88     QList<QVariant*>* pDataSet = NULL;
       
    89     
       
    90     if( (NULL != condAND)&&(NULL != condOR) )
       
    91     {
       
    92         return NULL;
       
    93     }
       
    94 
       
    95     if(condAND)
       
    96     {
       
    97         if(condAND->isEmpty())
       
    98         {
       
    99             return NULL;
       
   100         }
       
   101     }
       
   102 
       
   103     if(condOR)
       
   104     {
       
   105         if(condOR->isEmpty())
       
   106         {
       
   107             return NULL;
       
   108         }
       
   109     }
       
   110 
       
   111     combineGetStr(condAND, condOR, colNameView, sltSqlStr);
       
   112     pDataSet = new  QList<QVariant*>();
       
   113     
       
   114     if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
       
   115     {
       
   116         delete pDataSet;
       
   117         pDataSet = NULL;
       
   118     }
       
   119     
       
   120     return pDataSet;
       
   121 }
       
   122 
       
   123 bool imgWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pDataSet)
       
   124 {
       
   125 
       
   126     while (aIRDataSet.next()) 
       
   127     {
       
   128         QVariant* const p = new QVariant[IRDB_CHANNELINFO_COLUMN];
       
   129         *pDataSet<<p;
       
   130 
       
   131         for(int i = 0; i < IRDB_CHANNELINFO_COLUMN; i++)
       
   132         {
       
   133             *(p+i) = aIRDataSet.value(i);
       
   134         }
       
   135     }
       
   136 
       
   137     return true;
       
   138 }
       
   139 
       
   140