qtinternetradio/irdb/src/imgwrapper.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 17 Sep 2010 08:27:59 +0300
changeset 16 5723da102db1
child 17 38bbf2dcd608
permissions -rw-r--r--
Revision: 201035 Kit: 201037

/*
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Description: 
*
*/

#include <QSqlQuery>
#include <QVariant>
#include "imgwrapper.h"
#include "irdb.h"

imgWrapper::imgWrapper()
{     
}

imgWrapper::~imgWrapper()
{
} 


bool imgWrapper::updateImg(const columnMap* const RowData,
                           const uint& channelId,
                           const logoMap* const logoData)
{
    QString insSqlStr;
    QString updSqlStr;
    QList<QByteArray>* pImgList = NULL;
    bool ret = true;
    
    if(!channelId)
    {
        return false;	
    }

    if( NULL == RowData )
    {
        return false;
    }

    if(RowData->isEmpty())
    {
        return false;
    }

    if( true != (RowData->value(channelId)).isEmpty() )
    {
        return false;
    }

    updSqlStr = "update img set ";
    if(NULL != logoData)
     {
         pImgList = new QList<QByteArray>();
         combinePutStr(RowData, colNameView, insSqlStr, updSqlStr, logoData, pImgList); 
     
     }
     else
     {
         combinePutStr(RowData, colNameView, insSqlStr, updSqlStr);
     }  
    
    //create insSqlstr and updSqlStr in advance;
    updSqlStr = updSqlStr + "where channelId = " + QString::number(channelId);
    
    m_pIRDB->updRowImg(channelId, updSqlStr, pImgList)? ret = false:true;
    if(pImgList)
    {
        delete pImgList;
        pImgList = NULL;
    }
    
    return ret;     
}

QList<QVariant*>* imgWrapper::getImg(const columnMap* const condAND,  
                                   const columnMap* const condOR)
{
    QString sltSqlStr = "select * from IRVIEW_channelinfo ";
    QList<QVariant*>* pDataSet = NULL;
    
    if( (NULL != condAND)&&(NULL != condOR) )
    {
        return NULL;
    }

    if(condAND)
    {
        if(condAND->isEmpty())
        {
            return NULL;
        }
    }

    if(condOR)
    {
        if(condOR->isEmpty())
        {
            return NULL;
        }
    }

    combineGetStr(condAND, condOR, colNameView, sltSqlStr);
    pDataSet = new  QList<QVariant*>();
    
    if( m_pIRDB->selectRow(this, sltSqlStr, pDataSet) )
    {
        delete pDataSet;
        pDataSet = NULL;
    }
    
    return pDataSet;
}

bool imgWrapper::getIRTableCB(QSqlQuery& aIRDataSet, QList<QVariant*>* pDataSet)
{

    while (aIRDataSet.next()) 
    {
        QVariant* const p = new QVariant[IRDB_CHANNELINFO_COLUMN];
        *pDataSet<<p;

        for(int i = 0; i < IRDB_CHANNELINFO_COLUMN; i++)
        {
            *(p+i) = aIRDataSet.value(i);
        }
    }

    return true;
}