Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 64 |
1 files changed, 34 insertions, 30 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 14207be..dda23cc 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -29,26 +29,30 @@ /* * SQL Backend for the OPIE-Contact Database. */ #include "ocontactaccessbackend_sql.h" -#include <qarray.h> -#include <qdatetime.h> -#include <qstringlist.h> - -#include <qpe/global.h> -#include <qpe/recordfields.h> - +/* OPIE */ #include <opie2/opimcontact.h> #include <opie2/opimcontactfields.h> #include <opie2/opimdateconversion.h> #include <opie2/osqldriver.h> #include <opie2/osqlresult.h> #include <opie2/osqlmanager.h> #include <opie2/osqlquery.h> +#include <opie2/odebug.h> + +#include <qpe/global.h> +#include <qpe/recordfields.h> + +/* QT */ +#include <qarray.h> +#include <qdatetime.h> +#include <qstringlist.h> + using namespace Opie; using namespace Opie::DB; /* @@ -265,13 +269,13 @@ namespace { + "0" // Priority for future enhancements + ",'" + it.data() + "');"; } // qu += "commit;"; - qDebug("add %s", qu.latin1() ); + odebug << "add " << qu << "" << oendl; return qu; } RemoveQuery::RemoveQuery(int uid ) : OSQLQuery(), m_uid( uid ) {} @@ -313,13 +317,13 @@ namespace { } */ QString FindQuery::single()const{ QString qu = "select *"; qu += " from addressbook where uid = " + QString::number(m_uid); - // qWarning("find query: %s", qu.latin1() ); + // owarn << "find query: " << qu << "" << oendl; return qu; } FindCustomQuery::FindCustomQuery(int uid) : OSQLQuery(), m_uid( uid ) { @@ -347,13 +351,13 @@ namespace { namespace Opie { OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, const QString& filename ): OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) { - qDebug("C'tor OPimContactAccessBackend_SQL starts"); + odebug << "C'tor OPimContactAccessBackend_SQL starts" << oendl; QTime t; t.start(); /* Expecting to access the default filename if nothing else is set */ if ( filename.isEmpty() ){ m_fileName = Global::applicationFileName( "addressbook","addressbook.db" ); @@ -364,13 +368,13 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a OSQLManager man; m_driver = man.standard(); m_driver->setUrl( m_fileName ); load(); - qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); + odebug << "C'tor OPimContactAccessBackend_SQL ends: " << t.elapsed() << " ms" << oendl; } OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () { if( m_driver ) delete m_driver; @@ -427,13 +431,13 @@ QArray<int> OPimContactAccessBackend_SQL::allRecords() const return m_uids; } bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) { - qDebug("add in contact SQL-Backend"); + odebug << "add in contact SQL-Backend" << oendl; InsertQuery ins( newcontact ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; @@ -466,20 +470,20 @@ bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) return add( contact ); } OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const { - qDebug("OPimContactAccessBackend_SQL::find()"); + odebug << "OPimContactAccessBackend_SQL::find()" << oendl; QTime t; t.start(); OPimContact retContact( requestNonCustom( uid ) ); retContact.setExtraMap( requestCustom( uid ) ); - qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); + odebug << "OPimContactAccessBackend_SQL::find() needed: " << t.elapsed() << " ms" << oendl; return retContact; } QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd ) @@ -582,13 +586,13 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu // Skip trailing "AND" // if ( isAnyFieldSelected ) // qu = qu.left( qu.length() - 4 ); qu += searchQuery; - qDebug( "queryByExample query: %s", qu.latin1() ); + odebug << "queryByExample query: " << qu << "" << oendl; // Execute query and return the received uid's OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ){ QArray<int> empty; @@ -617,13 +621,13 @@ QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const searchlist += " OR "; searchlist += " rlike(\""+ r.pattern() + "\",\"" + *it + "\") "; } qu = qu + searchlist + ")"; - qDebug( "query: %s", qu.latin1() ); + odebug << "query: " << qu << "" << oendl; OSQLRawQuery raw( qu ); OSQLResult res = m_driver->query( &raw ); return extractUids( res ); @@ -698,31 +702,31 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) QString query = "SELECT uid FROM addressbook "; query += "ORDER BY \"Last Name\" "; if ( !asc ) query += "DESC"; - // qDebug("sorted query is: %s", query.latin1() ); + // odebug << "sorted query is: " << query << "" << oendl; OSQLRawQuery raw( query ); OSQLResult res = m_driver->query( &raw ); if ( res.state() != OSQLResult::Success ){ QArray<int> empty; return empty; } QArray<int> list = extractUids( res ); - qDebug("sorted needed %d ms!", t.elapsed() ); + odebug << "sorted needed " << t.elapsed() << " ms!" << oendl; return list; } void OPimContactAccessBackend_SQL::update() { - qDebug("Update starts"); + odebug << "Update starts" << oendl; QTime t; t.start(); // Now load the database set and extract the uid's // which will be held locally @@ -732,31 +736,31 @@ void OPimContactAccessBackend_SQL::update() return; m_uids = extractUids( res ); m_changed = false; - qDebug("Update ends %d ms", t.elapsed() ); + odebug << "Update ends " << t.elapsed() << " ms" << oendl; } QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const { - qDebug("extractUids"); + odebug << "extractUids" << oendl; QTime t; t.start(); OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); - qDebug(" count = %d", list.count() ); + odebug << " count = " << list.count() << "" << oendl; int i = 0; for (it = list.begin(); it != list.end(); ++it ) { ints[i] = (*it).data("uid").toInt(); i++; } - qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); + odebug << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl; return ints; } QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const @@ -785,13 +789,13 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co // Get data for the selected column and store it with the // corresponding id into the map.. int id = translate[*it]; QString value = resItem.data( (*it) ); - // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() ); + // odebug << "Reading " << (*it) << "... found: " << value << "" << oendl; switch( id ){ case Qtopia::Birthday: case Qtopia::Anniversary:{ // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) QStringList list = QStringList::split( '-', value ); @@ -803,25 +807,25 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co QDate date( year, month, day ); nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); } } break; case Qtopia::AddressCategory: - qDebug("Category is: %s", value.latin1() ); + odebug << "Category is: " << value << "" << oendl; default: nonCustomMap.insert( id, value ); } } // First insert uid nonCustomMap.insert( Qtopia::AddressUid, resItem.data( "uid" ) ); t3needed = t3.elapsed(); - // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() ); - qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", - t.elapsed(), t2needed, t3needed ); + // odebug << "Adding UID: " << resItem.data( "uid" ) << "" << oendl; + odebug << "RequestNonCustom needed: insg.:" << t.elapsed() << " ms, query: " << t2needed + << " ms, mapping: " << t3needed << " ms" << oendl; return nonCustomMap; } QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const { @@ -831,22 +835,22 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c QMap<QString, QString> customMap; FindCustomQuery query( uid ); OSQLResult res_custom = m_driver->query( &query ); if ( res_custom.state() == OSQLResult::Failure ) { - qWarning("OSQLResult::Failure in find query !!"); + owarn << "OSQLResult::Failure in find query !!" << oendl; QMap<QString, QString> empty; return empty; } OSQLResultItem::ValueList list = res_custom.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); for ( ; it != list.end(); ++it ) { customMap.insert( (*it).data( "type" ), (*it).data( "value" ) ); } - qDebug("RequestCustom needed: %d ms", t.elapsed() ); + odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl; return customMap; } } |