summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
authormickeyl <mickeyl>2004-02-24 12:46:23 (UTC)
committer mickeyl <mickeyl>2004-02-24 12:46:23 (UTC)
commit911473db35a9fce5f3589f03c27210456faaba86 (patch) (side-by-side diff)
tree7d55b6117b24de6ab18747b00a4641d38001c0ed /libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
parenta2ead23c3614fe581261455cb4c3f31cee2098f3 (diff)
downloadopie-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.cpp136
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
@@ -36,14 +36,14 @@
#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>
@@ -102,21 +102,21 @@ namespace Opie {
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
*/
@@ -173,13 +173,13 @@ namespace Opie {
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) );";
@@ -220,35 +220,35 @@ namespace Opie {
#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:{
@@ -292,13 +292,13 @@ namespace Opie {
// 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
@@ -456,17 +456,17 @@ 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" );
@@ -477,22 +477,22 @@ OContactAccessBackend_SQL::OContactAccessBackend_SQL ( const QString& /* appname
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
@@ -503,48 +503,48 @@ bool OContactAccessBackend_SQL::load ()
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;
@@ -554,56 +554,56 @@ bool OContactAccessBackend_SQL::add ( const OContact &newcontact )
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];
@@ -611,13 +611,13 @@ QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, i
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 ";
@@ -640,73 +640,73 @@ QArray<int> OContactAccessBackend_SQL::queryByExample ( const OContact &query, i
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 ";
@@ -732,13 +732,13 @@ QArray<int> OContactAccessBackend_SQL::sorted( bool asc, int , int , int )
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
@@ -753,13 +753,13 @@ void OContactAccessBackend_SQL::update()
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;
@@ -775,13 +775,13 @@ QArray<int> OContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
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;
@@ -795,14 +795,14 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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) );
@@ -817,13 +817,13 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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:
@@ -840,13 +840,13 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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;
@@ -863,13 +863,13 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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" )];
@@ -884,13 +884,13 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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" ) );
}
@@ -903,13 +903,13 @@ QMap<int, QString> OContactAccessBackend_SQL::requestNonCustom( int uid ) const
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;