author | mickeyl <mickeyl> | 2004-02-24 12:46:23 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-02-24 12:46:23 (UTC) |
commit | 911473db35a9fce5f3589f03c27210456faaba86 (patch) (side-by-side diff) | |
tree | 7d55b6117b24de6ab18747b00a4641d38001c0ed /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | |
parent | a2ead23c3614fe581261455cb4c3f31cee2098f3 (diff) | |
download | opie-911473db35a9fce5f3589f03c27210456faaba86.zip opie-911473db35a9fce5f3589f03c27210456faaba86.tar.gz opie-911473db35a9fce5f3589f03c27210456faaba86.tar.bz2 |
*phew* here is the class and file rename patch. not converted yet: backend,
but that will be not visible to application classes so we can change it later.
Diffstat (limited to 'libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index d0c8052..f121cc2 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -34,18 +34,18 @@ #include <qarray.h> #include <qdatetime.h> #include <qstringlist.h> #include <qpe/global.h> #include <qpe/recordfields.h> -#include <opie2/ocontactfields.h> -#include <opie2/oconversion.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> @@ -100,25 +100,25 @@ namespace Opie { class LoadQuery : public OSQLQuery { public: LoadQuery(); ~LoadQuery(); QString query()const; }; /** - * inserts/adds a OContact to the table + * inserts/adds a OPimContact to the table */ class InsertQuery : public OSQLQuery { public: - InsertQuery(const OContact& ); + InsertQuery(const OPimContact& ); ~InsertQuery(); QString query()const; private: - OContact m_contact; + OPimContact m_contact; }; /** * removes one from the table */ class RemoveQuery : public OSQLQuery { public: @@ -171,17 +171,17 @@ namespace Opie { CreateQuery::CreateQuery() : OSQLQuery() {} CreateQuery::~CreateQuery() {} QString CreateQuery::query()const { QString qu; #ifdef __STORE_HORIZONTAL_ qu += "create table addressbook( uid PRIMARY KEY "; - QStringList fieldList = OContactFields::untrfields( false ); + QStringList fieldList = OPimContactFields::untrfields( false ); for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ qu += QString( ",\"%1\" VARCHAR(10)" ).arg( *it ); } qu += " );"; qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );"; #else @@ -218,39 +218,39 @@ namespace Opie { qu += "select uid from addressbook where type = 'Last Name'"; # endif // __USE_SUPERFAST_LOADQUERY #endif // __STORE_HORIZONTAL_ return qu; } - InsertQuery::InsertQuery( const OContact& contact ) + InsertQuery::InsertQuery( const OPimContact& contact ) : OSQLQuery(), m_contact( contact ) { } InsertQuery::~InsertQuery() { } /* - * converts from a OContact to a query + * converts from a OPimContact to a query */ QString InsertQuery::query()const{ #ifdef __STORE_HORIZONTAL_ QString qu; qu += "insert into addressbook VALUES( " + QString::number( m_contact.uid() ); // Get all information out of the contact-class // Remember: The category is stored in contactMap, too ! QMap<int, QString> contactMap = m_contact.toMap(); - QStringList fieldList = OContactFields::untrfields( false ); - QMap<QString, int> translate = OContactFields::untrFieldsToId(); + QStringList fieldList = OPimContactFields::untrfields( false ); + QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ // Convert Column-String to Id and get value for this id.. // Hmmm.. Maybe not very cute solution.. int id = translate[*it]; switch ( id ){ case Qtopia::Birthday:{ // These entries should stored in a special format // year-month-day @@ -290,17 +290,17 @@ namespace Opie { #else // Get all information out of the contact-class // Remember: The category is stored in contactMap, too ! QMap<int, QString> contactMap = m_contact.toMap(); QMap<QString, QString> addressbook_db; // Get the translation from the ID to the String - QMap<int, QString> transMap = OContactFields::idToUntrFields(); + QMap<int, QString> transMap = OPimContactFields::idToUntrFields(); for( QMap<int, QString>::Iterator it = contactMap.begin(); it != contactMap.end(); ++it ){ switch ( it.key() ){ case Qtopia::Birthday:{ // These entries should stored in a special format // year-month-day QDate day = m_contact.birthday(); @@ -454,172 +454,172 @@ namespace Opie { }; /* --------------------------------------------------------------------------- */ namespace Opie { -OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname */, +OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* appname */, const QString& filename ): - OContactAccessBackend(), m_changed(false), m_driver( NULL ) + OPimContactAccessBackend(), m_changed(false), m_driver( NULL ) { - qWarning("C'tor OContactAccessBackend_SQL starts"); + qWarning("C'tor OPimContactAccessBackend_SQL starts"); 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" ); } else m_fileName = filename; // Get the standart sql-driver from the OSQLManager.. OSQLManager man; m_driver = man.standard(); m_driver->setUrl( m_fileName ); load(); - qWarning("C'tor OContactAccessBackend_SQL ends: %d ms", t.elapsed() ); + qWarning("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() ); } -OContactAccessBackend_SQL::~OContactAccessBackend_SQL () +OPimContactAccessBackend_SQL::~OPimContactAccessBackend_SQL () { if( m_driver ) delete m_driver; } -bool OContactAccessBackend_SQL::load () +bool OPimContactAccessBackend_SQL::load () { if (!m_driver->open() ) return false; // Don't expect that the database exists. // It is save here to create the table, even if it // do exist. ( Is that correct for all databases ?? ) CreateQuery creat; OSQLResult res = m_driver->query( &creat ); update(); return true; } -bool OContactAccessBackend_SQL::reload() +bool OPimContactAccessBackend_SQL::reload() { return load(); } -bool OContactAccessBackend_SQL::save() +bool OPimContactAccessBackend_SQL::save() { return m_driver->close(); // Shouldn't m_driver->sync be better than close ? (eilers) } -void OContactAccessBackend_SQL::clear () +void OPimContactAccessBackend_SQL::clear () { ClearQuery cle; OSQLResult res = m_driver->query( &cle ); reload(); } -bool OContactAccessBackend_SQL::wasChangedExternally() +bool OPimContactAccessBackend_SQL::wasChangedExternally() { return false; } -QArray<int> OContactAccessBackend_SQL::allRecords() const +QArray<int> OPimContactAccessBackend_SQL::allRecords() const { // FIXME: Think about cute handling of changed tables.. // Thus, we don't have to call update here... if ( m_changed ) - ((OContactAccessBackend_SQL*)this)->update(); + ((OPimContactAccessBackend_SQL*)this)->update(); return m_uids; } -bool OContactAccessBackend_SQL::add ( const OContact &newcontact ) +bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) { InsertQuery ins( newcontact ); OSQLResult res = m_driver->query( &ins ); if ( res.state() == OSQLResult::Failure ) return false; int c = m_uids.count(); m_uids.resize( c+1 ); m_uids[c] = newcontact.uid(); return true; } -bool OContactAccessBackend_SQL::remove ( int uid ) +bool OPimContactAccessBackend_SQL::remove ( int uid ) { RemoveQuery rem( uid ); OSQLResult res = m_driver->query(&rem ); if ( res.state() == OSQLResult::Failure ) return false; m_changed = true; return true; } -bool OContactAccessBackend_SQL::replace ( const OContact &contact ) +bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact ) { if ( !remove( contact.uid() ) ) return false; return add( contact ); } -OContact OContactAccessBackend_SQL::find ( int uid ) const +OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const { - qWarning("OContactAccessBackend_SQL::find()"); + qWarning("OPimContactAccessBackend_SQL::find()"); QTime t; t.start(); - OContact retContact( requestNonCustom( uid ) ); + OPimContact retContact( requestNonCustom( uid ) ); retContact.setExtraMap( requestCustom( uid ) ); - qWarning("OContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); + qWarning("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() ); return retContact; } -QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, int settings, const QDateTime& d = QDateTime() ) +QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() ) { QString qu = "SELECT uid FROM addressbook WHERE"; QMap<int, QString> queryFields = query.toMap(); - QStringList fieldList = OContactFields::untrfields( false ); - QMap<QString, int> translate = OContactFields::untrFieldsToId(); + QStringList fieldList = OPimContactFields::untrfields( false ); + QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); // Convert every filled field to a SQL-Query bool isAnyFieldSelected = false; for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ int id = translate[*it]; QString queryStr = queryFields[id]; if ( !queryStr.isEmpty() ){ isAnyFieldSelected = true; switch( id ){ default: // Switching between case sensitive and insensitive... // LIKE is not case sensitive, GLOB is case sensitive // Do exist a better solution to switch this ? - if ( settings & OContactAccess::IgnoreCase ) + if ( settings & OPimContactAccess::IgnoreCase ) qu += "(\"" + *it + "\"" + " LIKE " + "'" + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND "; else qu += "(\"" + *it + "\"" + " GLOB " + "'" + queryStr + "'" + ") AND "; } } @@ -638,77 +638,77 @@ QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, i return empty; } QArray<int> list = extractUids( res ); return list; } -QArray<int> OContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const +QArray<int> OPimContactAccessBackend_SQL::matchRegexp( const QRegExp &r ) const { QArray<int> nix(0); return nix; } -const uint OContactAccessBackend_SQL::querySettings() +const uint OPimContactAccessBackend_SQL::querySettings() { - return OContactAccess::IgnoreCase - || OContactAccess::WildCards; + return OPimContactAccess::IgnoreCase + || OPimContactAccess::WildCards; } -bool OContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const +bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const { - /* OContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay + /* OPimContactAccess::IgnoreCase, DateDiff, DateYear, DateMonth, DateDay * may be added with any of the other settings. IgnoreCase should never used alone. * Wildcards, RegExp, ExactMatch should never used at the same time... */ // Step 1: Check whether the given settings are supported by this backend if ( ( querySettings & ( - OContactAccess::IgnoreCase - | OContactAccess::WildCards -// | OContactAccess::DateDiff -// | OContactAccess::DateYear -// | OContactAccess::DateMonth -// | OContactAccess::DateDay -// | OContactAccess::RegExp -// | OContactAccess::ExactMatch + OPimContactAccess::IgnoreCase + | OPimContactAccess::WildCards +// | OPimContactAccess::DateDiff +// | OPimContactAccess::DateYear +// | OPimContactAccess::DateMonth +// | OPimContactAccess::DateDay +// | OPimContactAccess::RegExp +// | OPimContactAccess::ExactMatch ) ) != querySettings ) return false; // Step 2: Check whether the given combinations are ok.. // IngoreCase alone is invalid - if ( querySettings == OContactAccess::IgnoreCase ) + if ( querySettings == OPimContactAccess::IgnoreCase ) return false; // WildCards, RegExp and ExactMatch should never used at the same time - switch ( querySettings & ~( OContactAccess::IgnoreCase - | OContactAccess::DateDiff - | OContactAccess::DateYear - | OContactAccess::DateMonth - | OContactAccess::DateDay + switch ( querySettings & ~( OPimContactAccess::IgnoreCase + | OPimContactAccess::DateDiff + | OPimContactAccess::DateYear + | OPimContactAccess::DateMonth + | OPimContactAccess::DateDay ) ){ - case OContactAccess::RegExp: + case OPimContactAccess::RegExp: return ( true ); - case OContactAccess::WildCards: + case OPimContactAccess::WildCards: return ( true ); - case OContactAccess::ExactMatch: + case OPimContactAccess::ExactMatch: return ( true ); case 0: // one of the upper removed bits were set.. return ( true ); default: return ( false ); } } -QArray<int> OContactAccessBackend_SQL::sorted( bool asc, int , int , int ) +QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int ) { QTime t; t.start(); #ifdef __STORE_HORIZONTAL_ QString query = "SELECT uid FROM addressbook "; query += "ORDER BY \"Last Name\" "; #else @@ -730,17 +730,17 @@ QArray<int> OContactAccessBackend_SQL::sorted( bool asc, int , int , int ) QArray<int> list = extractUids( res ); qWarning("sorted needed %d ms!", t.elapsed() ); return list; } -void OContactAccessBackend_SQL::update() +void OPimContactAccessBackend_SQL::update() { qWarning("Update starts"); QTime t; t.start(); // Now load the database set and extract the uid's // which will be held locally @@ -751,17 +751,17 @@ void OContactAccessBackend_SQL::update() m_uids = extractUids( res ); m_changed = false; qWarning("Update ends %d ms", t.elapsed() ); } -QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const +QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const { qWarning("extractUids"); QTime t; t.start(); OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); qWarning(" count = %d", list.count() ); @@ -773,17 +773,17 @@ QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const } qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() ); return ints; } #ifdef __STORE_HORIZONTAL_ -QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const +QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const { QTime t; t.start(); QMap<int, QString> nonCustomMap; int t2needed = 0; int t3needed = 0; @@ -793,18 +793,18 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const OSQLResult res_noncustom = m_driver->query( &query ); t2needed = t2.elapsed(); OSQLResultItem resItem = res_noncustom.first(); QTime t3; t3.start(); // Now loop through all columns - QStringList fieldList = OContactFields::untrfields( false ); - QMap<QString, int> translate = OContactFields::untrFieldsToId(); + QStringList fieldList = OPimContactFields::untrfields( false ); + QMap<QString, int> translate = OPimContactFields::untrFieldsToId(); for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){ // 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) ); // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() ); @@ -815,17 +815,17 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const // Birthday and Anniversary are encoded special ( yyyy-mm-dd ) QStringList list = QStringList::split( '-', value ); QStringList::Iterator lit = list.begin(); int year = (*lit).toInt(); int month = (*(++lit)).toInt(); int day = (*(++lit)).toInt(); if ( ( day != 0 ) && ( month != 0 ) && ( year != 0 ) ){ QDate date( year, month, day ); - nonCustomMap.insert( id, OConversion::dateToString( date ) ); + nonCustomMap.insert( id, OPimDateConversion::dateToString( date ) ); } } break; case Qtopia::AddressCategory: qWarning("Category is: %s", value.latin1() ); default: nonCustomMap.insert( id, value ); } @@ -838,17 +838,17 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() ); qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", t.elapsed(), t2needed, t3needed ); return nonCustomMap; } #else -QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const +QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) const { QTime t; t.start(); QMap<int, QString> nonCustomMap; int t2needed = 0; QTime t2; @@ -861,17 +861,17 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const qWarning("OSQLResult::Failure in find query !!"); QMap<int, QString> empty; return empty; } int t3needed = 0; QTime t3; t3.start(); - QMap<QString, int> translateMap = OContactFields::untrFieldsToId(); + QMap<QString, int> translateMap = OPimContactFields::untrFieldsToId(); OSQLResultItem::ValueList list = res_noncustom.results(); OSQLResultItem::ValueList::Iterator it = list.begin(); for ( ; it != list.end(); ++it ) { if ( (*it).data("type") != "" ){ int typeId = translateMap[(*it).data( "type" )]; switch( typeId ){ case Qtopia::Birthday: @@ -882,17 +882,17 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const int year = (*lit).toInt(); qWarning("1. %s", (*lit).latin1()); int month = (*(++lit)).toInt(); qWarning("2. %s", (*lit).latin1()); int day = (*(++lit)).toInt(); qWarning("3. %s", (*lit).latin1()); qWarning( "RequestNonCustom->Converting:%s to Year: %d, Month: %d, Day: %d ", (*it).data( "value" ).latin1(), year, month, day ); QDate date( year, month, day ); - nonCustomMap.insert( typeId, OConversion::dateToString( date ) ); + nonCustomMap.insert( typeId, OPimDateConversion::dateToString( date ) ); } break; default: nonCustomMap.insert( typeId, (*it).data( "value" ) ); } } } @@ -901,17 +901,17 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const t3needed = t3.elapsed(); qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms", t.elapsed(), t2needed, t3needed ); return nonCustomMap; } #endif // __STORE_HORIZONTAL_ -QMap<QString, QString> OContactAccessBackend_SQL::requestCustom( int uid ) const +QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) const { QTime t; t.start(); QMap<QString, QString> customMap; FindCustomQuery query( uid ); OSQLResult res_custom = m_driver->query( &query ); |