summaryrefslogtreecommitdiff
authoreilers <eilers>2004-04-05 07:03:09 (UTC)
committer eilers <eilers>2004-04-05 07:03:09 (UTC)
commite6e31e93aa55bb967a044fe3660201000a6e59b0 (patch) (side-by-side diff)
tree1071fa4b22698fd56dde283bbb7375478b7e1ddf
parent6be3d148fc1d610ebfa193012657b3b77d9368e3 (diff)
downloadopie-e6e31e93aa55bb967a044fe3660201000a6e59b0.zip
opie-e6e31e93aa55bb967a044fe3660201000a6e59b0.tar.gz
opie-e6e31e93aa55bb967a044fe3660201000a6e59b0.tar.bz2
SQL-Backends are almost finished !
Works: Loading/Storing data, Most important search queries for Address/todo Unfinished: Search-Queries for Datebook, regexp search
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp180
-rw-r--r--libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp1
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp70
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.h2
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp171
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.h5
-rw-r--r--libopie2/opiepim/core/opimcontact.h2
7 files changed, 338 insertions, 93 deletions
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
index 1ea35a8..3142f75 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp
@@ -40,4 +40,5 @@
#include <qpe/recordfields.h>
+#include <opie2/opimcontact.h>
#include <opie2/opimcontactfields.h>
#include <opie2/opimdateconversion.h>
@@ -47,10 +48,10 @@
#include <opie2/osqlquery.h>
+using namespace Opie;
using namespace Opie::DB;
/*
- * Implementation of used query types
- * CREATE query
+ * Implementation of used query types * CREATE query
* LOAD query
* INSERT
@@ -58,5 +59,5 @@ using namespace Opie::DB;
* CLEAR
*/
-namespace Opie {
+namespace {
/**
* CreateQuery for the Todolist Table
@@ -151,5 +152,5 @@ namespace Opie {
- // We using three tables to store the information:
+ // We using two tables to store the information:
// 1. addressbook : It contains General information about the contact (non custom)
// 2. custom_data : Not official supported entries
@@ -169,5 +170,5 @@ namespace Opie {
qu += " );";
- qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );";
+ qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
return qu;
@@ -222,27 +223,19 @@ namespace Opie {
int id = translate[*it];
switch ( id ){
- case Qtopia::Birthday:{
- // These entries should stored in a special format
- // year-month-day
- QDate day = m_contact.birthday();
- if ( day.isValid() ){
- qu += QString(",\"%1-%2-%3\"")
- .arg( day.year() )
- .arg( day.month() )
- .arg( day.day() );
+ case Qtopia::Birthday:
+ case Qtopia::Anniversary:{
+ QDate day;
+ if ( id == Qtopia::Birthday ){
+ day = m_contact.birthday();
} else {
- qu += ",\"\"";
+ day = m_contact.anniversary();
}
- }
- break;
- case Qtopia::Anniversary:{
// These entries should stored in a special format
// year-month-day
- QDate day = m_contact.anniversary();
if ( day.isValid() ){
qu += QString(",\"%1-%2-%3\"")
- .arg( day.year() )
- .arg( day.month() )
- .arg( day.day() );
+ .arg( QString::number( day.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( day.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( day.day() ).rightJustify( 2, '0' ) );
} else {
qu += ",\"\"";
@@ -250,5 +243,4 @@ namespace Opie {
}
break;
-
default:
qu += QString( ",\"%1\"" ).arg( contactMap[id] );
@@ -269,13 +261,13 @@ namespace Opie {
+ QString::number( id++ )
+ ",'"
- + it.key() //.latin1()
+ + it.key()
+ "',"
+ "0" // Priority for future enhancements
+ ",'"
- + it.data() //.latin1()
+ + it.data()
+ "');";
}
// qu += "commit;";
- qWarning("add %s", qu.latin1() );
+ qDebug("add %s", qu.latin1() );
return qu;
}
@@ -359,5 +351,5 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a
OPimContactAccessBackend(), m_changed(false), m_driver( NULL )
{
- qWarning("C'tor OPimContactAccessBackend_SQL starts");
+ qDebug("C'tor OPimContactAccessBackend_SQL starts");
QTime t;
t.start();
@@ -376,5 +368,5 @@ OPimContactAccessBackend_SQL::OPimContactAccessBackend_SQL ( const QString& /* a
load();
- qWarning("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() );
+ qDebug("C'tor OPimContactAccessBackend_SQL ends: %d ms", t.elapsed() );
}
@@ -477,5 +469,5 @@ bool OPimContactAccessBackend_SQL::replace ( const OPimContact &contact )
OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
{
- qWarning("OPimContactAccessBackend_SQL::find()");
+ qDebug("OPimContactAccessBackend_SQL::find()");
QTime t;
t.start();
@@ -484,5 +476,5 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
retContact.setExtraMap( requestCustom( uid ) );
- qWarning("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() );
+ qDebug("OPimContactAccessBackend_SQL::find() needed: %d ms", t.elapsed() );
return retContact;
}
@@ -490,7 +482,16 @@ OPimContact OPimContactAccessBackend_SQL::find ( int uid ) const
-QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& d = QDateTime() )
+QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &query, int settings, const QDateTime& qd )
{
QString qu = "SELECT uid FROM addressbook WHERE";
+ QString searchQuery ="";
+
+ QDate startDate;
+
+ if ( qd.isValid() )
+ startDate = qd.date();
+ else
+ startDate = QDate::currentDate();
+
QMap<int, QString> queryFields = query.toMap();
@@ -499,11 +500,69 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
// Convert every filled field to a SQL-Query
- bool isAnyFieldSelected = false;
+// bool isAnyFieldSelected = false;
for ( QStringList::Iterator it = ++fieldList.begin(); it != fieldList.end(); ++it ){
+
int id = translate[*it];
QString queryStr = queryFields[id];
+ QDate* endDate = 0l;
+
if ( !queryStr.isEmpty() ){
- isAnyFieldSelected = true;
+ // If something is alredy stored in the query, add an "AND"
+ // to the end of the string to prepare for the next ..
+ if ( !searchQuery.isEmpty() )
+ searchQuery += " AND";
+
+// isAnyFieldSelected = true;
switch( id ){
+ case Qtopia::Birthday:
+ endDate = new QDate( query.birthday() );
+ // Fall through !
+ case Qtopia::Anniversary:
+ if ( endDate == 0l )
+ endDate = new QDate( query.anniversary() );
+
+ if ( settings & OPimContactAccess::DateDiff ) {
+ searchQuery += QString( " (\"%1\" <= '%2-%3-%4\' AND \"%5\" >= '%6-%7-%8')" )
+ .arg( *it )
+ .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) )
+ .arg( *it )
+ .arg( QString::number( startDate.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( startDate.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( startDate.day() ).rightJustify( 2, '0' ) ) ;
+ }
+
+ if ( settings & OPimContactAccess::DateYear ){
+ if ( settings & OPimContactAccess::DateDiff )
+ searchQuery += " AND";
+
+ searchQuery += QString( " (\"%1\" LIKE '%2-%')" )
+ .arg( *it )
+ .arg( QString::number( endDate->year() ).rightJustify( 4, '0' ) );
+ }
+
+ if ( settings & OPimContactAccess::DateMonth ){
+ if ( ( settings & OPimContactAccess::DateDiff )
+ || ( settings & OPimContactAccess::DateYear ) )
+ searchQuery += " AND";
+
+ searchQuery += QString( " (\"%1\" LIKE '%-%2-%')" )
+ .arg( *it )
+ .arg( QString::number( endDate->month() ).rightJustify( 2, '0' ) );
+ }
+
+ if ( settings & OPimContactAccess::DateDay ){
+ if ( ( settings & OPimContactAccess::DateDiff )
+ || ( settings & OPimContactAccess::DateYear )
+ || ( settings & OPimContactAccess::DateMonth ) )
+ searchQuery += " AND";
+
+ searchQuery += QString( " (\"%1\" LIKE '%-%-%2')" )
+ .arg( *it )
+ .arg( QString::number( endDate->day() ).rightJustify( 2, '0' ) );
+ }
+
+ break;
default:
// Switching between case sensitive and insensitive...
@@ -511,9 +570,9 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
// Do exist a better solution to switch this ?
if ( settings & OPimContactAccess::IgnoreCase )
- qu += "(\"" + *it + "\"" + " LIKE " + "'"
- + queryStr.replace(QRegExp("\\*"),"%") + "'" + ") AND ";
+ searchQuery += "(\"" + *it + "\"" + " LIKE " + "'"
+ + queryStr.replace(QRegExp("\\*"),"%") + "'" + ")";
else
- qu += "(\"" + *it + "\"" + " GLOB " + "'"
- + queryStr + "'" + ") AND ";
+ searchQuery += "(\"" + *it + "\"" + " GLOB " + "'"
+ + queryStr + "'" + ")";
}
@@ -521,8 +580,10 @@ QArray<int> OPimContactAccessBackend_SQL::queryByExample ( const OPimContact &qu
}
// Skip trailing "AND"
- if ( isAnyFieldSelected )
- qu = qu.left( qu.length() - 4 );
+// if ( isAnyFieldSelected )
+// qu = qu.left( qu.length() - 4 );
+
+ qu += searchQuery;
- qWarning( "queryByExample query: %s", qu.latin1() );
+ qDebug( "queryByExample query: %s", qu.latin1() );
// Execute query and return the received uid's
@@ -548,5 +609,10 @@ const uint OPimContactAccessBackend_SQL::querySettings()
{
return OPimContactAccess::IgnoreCase
- || OPimContactAccess::WildCards;
+ || OPimContactAccess::WildCards
+ || OPimContactAccess::DateDiff
+ || OPimContactAccess::DateYear
+ || OPimContactAccess::DateMonth
+ || OPimContactAccess::DateDay
+ ;
}
@@ -562,8 +628,8 @@ bool OPimContactAccessBackend_SQL::hasQuerySettings (uint querySettings) const
OPimContactAccess::IgnoreCase
| OPimContactAccess::WildCards
-// | OPimContactAccess::DateDiff
-// | OPimContactAccess::DateYear
-// | OPimContactAccess::DateMonth
-// | OPimContactAccess::DateDay
+ | OPimContactAccess::DateDiff
+ | OPimContactAccess::DateYear
+ | OPimContactAccess::DateMonth
+ | OPimContactAccess::DateDay
// | OPimContactAccess::RegExp
// | OPimContactAccess::ExactMatch
@@ -610,5 +676,5 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
query += "DESC";
- // qWarning("sorted query is: %s", query.latin1() );
+ // qDebug("sorted query is: %s", query.latin1() );
OSQLRawQuery raw( query );
@@ -621,5 +687,5 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
QArray<int> list = extractUids( res );
- qWarning("sorted needed %d ms!", t.elapsed() );
+ qDebug("sorted needed %d ms!", t.elapsed() );
return list;
}
@@ -628,5 +694,5 @@ QArray<int> OPimContactAccessBackend_SQL::sorted( bool asc, int , int , int )
void OPimContactAccessBackend_SQL::update()
{
- qWarning("Update starts");
+ qDebug("Update starts");
QTime t;
t.start();
@@ -644,10 +710,10 @@ void OPimContactAccessBackend_SQL::update()
m_changed = false;
- qWarning("Update ends %d ms", t.elapsed() );
+ qDebug("Update ends %d ms", t.elapsed() );
}
QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
{
- qWarning("extractUids");
+ qDebug("extractUids");
QTime t;
t.start();
@@ -655,5 +721,5 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- qWarning(" count = %d", list.count() );
+ qDebug(" count = %d", list.count() );
int i = 0;
@@ -662,5 +728,5 @@ QArray<int> OPimContactAccessBackend_SQL::extractUids( OSQLResult& res ) const
i++;
}
- qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
+ qDebug("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
return ints;
@@ -697,5 +763,5 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
QString value = resItem.data( (*it) );
- // qWarning("Reading %s... found: %s", (*it).latin1(), value.latin1() );
+ // qDebug("Reading %s... found: %s", (*it).latin1(), value.latin1() );
switch( id ){
@@ -715,5 +781,5 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
break;
case Qtopia::AddressCategory:
- qWarning("Category is: %s", value.latin1() );
+ qDebug("Category is: %s", value.latin1() );
default:
nonCustomMap.insert( id, value );
@@ -725,6 +791,6 @@ QMap<int, QString> OPimContactAccessBackend_SQL::requestNonCustom( int uid ) co
t3needed = t3.elapsed();
- // qWarning("Adding UID: %s", resItem.data( "uid" ).latin1() );
- qWarning("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms",
+ // qDebug("Adding UID: %s", resItem.data( "uid" ).latin1() );
+ qDebug("RequestNonCustom needed: insg.:%d ms, query: %d ms, mapping: %d ms",
t.elapsed(), t2needed, t3needed );
@@ -754,5 +820,5 @@ QMap<QString, QString> OPimContactAccessBackend_SQL::requestCustom( int uid ) c
}
- qWarning("RequestCustom needed: %d ms", t.elapsed() );
+ qDebug("RequestCustom needed: %d ms", t.elapsed() );
return customMap;
}
diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
index 2b467c3..7b4d81f 100644
--- a/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
+++ b/libopie2/opiepim/backend/ocontactaccessbackend_xml.cpp
@@ -231,4 +231,5 @@ QArray<int> OPimContactAccessBackend_XML::queryByExample ( const OPimContact &qu
queryDate = new QDate( query.birthday() );
checkDate = new QDate( (*it)->birthday() );
+ // fall through
case Qtopia::Anniversary:
if ( queryDate == 0l ){
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index a779dc1..8a8cb0b 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -49,4 +49,41 @@
using namespace Opie::DB;
+namespace {
+ /**
+ * a find query for custom elements
+ */
+ class FindCustomQuery : public OSQLQuery {
+ public:
+ FindCustomQuery(int uid);
+ FindCustomQuery(const QArray<int>& );
+ ~FindCustomQuery();
+ QString query()const;
+ private:
+ QString single()const;
+ QString multi()const;
+ QArray<int> m_uids;
+ int m_uid;
+ };
+
+ FindCustomQuery::FindCustomQuery(int uid)
+ : OSQLQuery(), m_uid( uid ) {
+ }
+ FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
+ : OSQLQuery(), m_uids( ints ){
+ }
+ FindCustomQuery::~FindCustomQuery() {
+ }
+ QString FindCustomQuery::query()const{
+// if ( m_uids.count() == 0 )
+ return single();
+ }
+ QString FindCustomQuery::single()const{
+ QString qu = "select uid, type, value from custom_data where uid = ";
+ qu += QString::number(m_uid);
+ return qu;
+ }
+}
+
+
namespace Opie {
@@ -124,5 +161,5 @@ bool ODateBookAccessBackend_SQL::load()
qu += " );";
- qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR, priority INTEGER, value VARCHAR, PRIMARY KEY /* identifier */ (uid, id) );";
+ qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
qWarning( "command: %s", qu.latin1() );
@@ -203,7 +240,7 @@ OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
}
- // Last step: Put map into date event and return it
+ // Last step: Put map into date event, add custom map and return it
OPimEvent retDate( dateEventMap );
-
+ retDate.setExtraMap( requestCustom( uid ) );
return retDate;
}
@@ -366,3 +403,30 @@ QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
}
+QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
+{
+ QTime t;
+ t.start();
+
+ 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 !!");
+ 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() );
+ return customMap;
+}
+
+
}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
index 60d7f21..b624159 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.h
@@ -89,5 +89,7 @@ private:
void initFields();
void update();
+
QArray<int> extractUids( Opie::DB::OSQLResult& res ) const;
+ QMap<QString, QString> requestCustom( int uid ) const;
};
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index d218090..b4170fc 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -2,4 +2,5 @@
This file is part of the Opie Project
Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de)
+ Copyright (C) Holger Freyther (zecke@handhelds.org)
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
@@ -29,4 +30,6 @@
#include <qdatetime.h>
+#include <qmap.h>
+#include <qstring.h>
#include <qpe/global.h>
@@ -149,4 +152,22 @@ namespace {
+ /**
+ * a find query for custom elements
+ */
+ class FindCustomQuery : public OSQLQuery {
+ public:
+ FindCustomQuery(int uid);
+ FindCustomQuery(const QArray<int>& );
+ ~FindCustomQuery();
+ QString query()const;
+ private:
+ QString single()const;
+ QString multi()const;
+ QArray<int> m_uids;
+ int m_uid;
+ };
+
+
+
CreateQuery::CreateQuery() : OSQLQuery() {}
CreateQuery::~CreateQuery() {}
@@ -158,5 +179,5 @@ namespace {
qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
qu += "reminders, alarms, maintainer, startdate, completeddate);";
- qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
+ qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
return qu;
}
@@ -180,5 +201,7 @@ namespace {
/*
* converts from a OPimTodo to a query
- * we leave out X-Ref + Alarms
+ * we leave out X-Ref + Maintainer
+ * FIXME: Implement/Finish toMap()/fromMap() into OpimTodo to move the encoding
+ * decoding stuff there.. (eilers)
*/
QString InsertQuery::query()const{
@@ -216,7 +239,7 @@ namespace {
+ "'" + m_todo.summary() + "'" + ","
+ QString::number(m_todo.priority() ) + ","
- + "'" + QString::number(year) + "-"
- + QString::number(month)
- + "-" + QString::number( day ) + "'" + ","
+ + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
+ + QString::number(month).rightJustify( 2, '0' )
+ + "-" + QString::number( day ).rightJustify( 2, '0' )+ "'" + ","
+ QString::number( m_todo.progress() ) + ","
+ QString::number( m_todo.state().state() ) + ","
@@ -241,13 +264,33 @@ namespace {
qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
- + "'" + QString::number(sYear) + "-"
- + QString::number(sMonth)
- + "-" + QString::number(sDay) + "'" + ","
- + "'" + QString::number(eYear) + "-"
- + QString::number(eMonth)
- + "-"+QString::number(eDay) + "'"
+ + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
+ + QString::number(sMonth).rightJustify( 2, '0' )
+ + "-" + QString::number(sDay).rightJustify( 2, '0' )+ "'" + ","
+ + "'" + QString::number(eYear).rightJustify( 4, '0' ) + "-"
+ + QString::number(eMonth).rightJustify( 2, '0' )
+ + "-"+QString::number(eDay).rightJustify( 2, '0' ) + "'"
+ ")";
- qWarning("add %s", qu.latin1() );
+ // Save custom Entries:
+ int id = 0;
+ id = 0;
+ QMap<QString, QString> customMap = m_todo.toExtraMap();
+ for( QMap<QString, QString>::Iterator it = customMap.begin();
+ it != customMap.end(); ++it ){
+ qu += "insert into custom_data VALUES("
+ + QString::number( m_todo.uid() )
+ + ","
+ + QString::number( id++ )
+ + ",'"
+ + it.key()
+ + "',"
+ + "0" // Priority for future enhancements
+ + ",'"
+ + it.data()
+ + "');";
+ }
+
+
+ qDebug("add %s", qu.latin1() );
return qu;
}
@@ -301,5 +344,8 @@ namespace {
QDate date = QDate::currentDate();
QString str;
- str = QString("select uid from todolist where DueDate ='%1-%2-%3'").arg(date.year() ).arg(date.month() ).arg(date.day() );
+ str = QString("select uid from todolist where DueDate ='%1-%2-%3'")
+ .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( date.day() ) .rightJustify( 2, '0' ) );
return str;
@@ -316,6 +362,10 @@ namespace {
QString str;
str = QString("select uid from todolist where ( DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6' ) OR DueDate = '0-0-0' ")
- .arg( m_start.year() ).arg( m_start.month() ).arg( m_start.day() )
- .arg( m_end .year() ).arg( m_end .month() ).arg( m_end .day() );
+ .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
return str;
}
@@ -323,9 +373,31 @@ namespace {
QString str;
str = QString("select uid from todolist where DueDate >= '%1-%2-%3' AND DueDate <= '%4-%5-%6'")
- .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() )
- .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() );
+ .arg( QString::number( m_start.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( m_start.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_start.day() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_end.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( m_end.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( m_end.day() ).rightJustify( 2, '0' ) );
return str;
}
+
+ FindCustomQuery::FindCustomQuery(int uid)
+ : OSQLQuery(), m_uid( uid ) {
+ }
+ FindCustomQuery::FindCustomQuery(const QArray<int>& ints)
+ : OSQLQuery(), m_uids( ints ){
+ }
+ FindCustomQuery::~FindCustomQuery() {
+ }
+ QString FindCustomQuery::query()const{
+ return single(); // Multiple requests not supported !
+ }
+ QString FindCustomQuery::single()const{
+ QString qu = "select uid, type, value from custom_data where uid = ";
+ qu += QString::number(m_uid);
+ return qu;
+ }
+
};
@@ -333,5 +405,5 @@ namespace {
namespace Opie {
OPimTodoAccessBackendSQL::OPimTodoAccessBackendSQL( const QString& file )
- : OPimTodoAccessBackend(), m_dict(15), m_driver(NULL), m_dirty(true)
+ : OPimTodoAccessBackend(),/* m_dict(15),*/ m_driver(NULL), m_dirty(true)
{
QString fi = file;
@@ -384,5 +456,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
uint cur, Frontend::CacheDirection dir ) const{
uint CACHE = readAhead();
- qWarning("searching for %d", uid );
+ qDebug("searching for %d", uid );
QArray<int> search( CACHE );
uint size =0;
@@ -394,5 +466,5 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints,
case 0: // FIXME: Not a good style to use magic numbers here (eilers)
for (uint i = cur; i < ints.count() && size < CACHE; i++ ) {
- qWarning("size %d %d", size, ints[i] );
+ qDebug("size %d %d", size, ints[i] );
search[size] = ints[i];
size++;
@@ -469,5 +541,5 @@ QArray<int> OPimTodoAccessBackendSQL::effectiveToDos( const QDate& s,
QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
int sortFilter, int cat ) {
- qWarning("sorted %d, %d", asc, sortOrder );
+ qDebug("sorted %d, %d", asc, sortOrder );
QString query;
query = "select uid from todolist WHERE ";
@@ -490,5 +562,8 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
QString due;
QString base;
- base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() );
+ base = QString("DueDate <= '%1-%2-%3' AND completed = 0")
+ .arg( QString::number( date.year() ).rightJustify( 4, '0' ) )
+ .arg( QString::number( date.month() ).rightJustify( 2, '0' ) )
+ .arg( QString::number( date.day() ).rightJustify( 2, '0' ) );
query += " " + base + " AND";
}
@@ -499,5 +574,5 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
query += " ( completed = 1 OR completed = 0) AND";
}
- /* srtip the end */
+ /* strip the end */
query = query.remove( query.length()-3, 3 );
@@ -525,9 +600,9 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder,
if ( !asc ) {
- qWarning("not ascending!");
+ qDebug("not ascending!");
query += " DESC";
}
- qWarning( query );
+ qDebug( query );
OSQLRawQuery raw(query );
return uids( m_driver->query(&raw) );
@@ -554,5 +629,5 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
- qWarning("todo1");
+ qDebug("todo1");
OPimTodo to = todo( (*it) );
cache( to );
@@ -560,5 +635,5 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
for ( ; it != list.end(); ++it ) {
- qWarning("caching");
+ qDebug("caching");
cache( todo( (*it) ) );
}
@@ -566,10 +641,13 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{
}
OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
- qWarning("todo");
+ qDebug("todo(ResultItem)");
+
+ // Request information from addressbook table and create the OPimTodo-object.
+
bool hasDueDate = false; QDate dueDate = QDate::currentDate();
hasDueDate = date( dueDate, item.data("DueDate") );
QStringList cats = QStringList::split(";", item.data("categories") );
- qWarning("Item is completed: %d", item.data("completed").toInt() );
+ qDebug("Item is completed: %d", item.data("completed").toInt() );
OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
@@ -615,4 +693,7 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
to.setRecurrence( recur );
+ // Finally load the custom-entries for this UID and put it into the created object
+ to.setExtraMap( requestCustom( to.uid() ) );
+
return to;
}
@@ -625,4 +706,6 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
*/
void OPimTodoAccessBackendSQL::fillDict() {
+
+#if 0
/* initialize dict */
/*
@@ -646,4 +729,6 @@ void OPimTodoAccessBackendSQL::fillDict() {
// m_dict.insert("HasAlarmDateTime",new int(OPimTodo::HasAlarmDateTime) ); // old stuff (eilers)
// m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers)
+
+#endif
}
/*
@@ -665,5 +750,5 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- qWarning(" count = %d", list.count() );
+ qDebug(" count = %d", list.count() );
int i = 0;
@@ -726,3 +811,29 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
}
+
+QMap<QString, QString> OPimTodoAccessBackendSQL::requestCustom( int uid ) const
+{
+ 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 !!");
+ 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" ) );
+ }
+
+ return customMap;
+}
+
+
+
+
}
diff --git a/libopie2/opiepim/backend/otodoaccesssql.h b/libopie2/opiepim/backend/otodoaccesssql.h
index 0ae2591..0cc7722 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.h
+++ b/libopie2/opiepim/backend/otodoaccesssql.h
@@ -30,5 +30,5 @@
#define OPIE_PIM_ACCESS_SQL_H
-#include <qasciidict.h>
+/* #include <qasciidict.h> */
#include <opie2/otodoaccessbackend.h>
@@ -81,6 +81,7 @@ private:
OPimTodo todo( int uid )const;
QBitArray sup() const;
+ QMap<QString, QString> requestCustom( int uid ) const;
- QAsciiDict<int> m_dict;
+ // QAsciiDict<int> m_dict;
Opie::DB::OSQLDriver* m_driver;
QArray<int> m_uids;
diff --git a/libopie2/opiepim/core/opimcontact.h b/libopie2/opiepim/core/opimcontact.h
index c08f7ed..9d3cacc 100644
--- a/libopie2/opiepim/core/opimcontact.h
+++ b/libopie2/opiepim/core/opimcontact.h
@@ -1,5 +1,5 @@
/*
This file is part of the Opie Project
- Copyright (C) The Main Author <main-author@whereever.org>
+ Copyright (C) Stefan Eilers <eilers.stefan@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.