Diffstat (limited to 'libopie2/opiepim/backend/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/otodoaccesssql.cpp | 173 |
1 files changed, 142 insertions, 31 deletions
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 @@ -3,2 +3,3 @@ Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) + Copyright (C) Holger Freyther (zecke@handhelds.org) =. Copyright (C) The Opie Team <opie-devel@handhelds.org> @@ -30,2 +31,4 @@ #include <qdatetime.h> +#include <qmap.h> +#include <qstring.h> @@ -150,2 +153,20 @@ 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() {} @@ -159,3 +180,3 @@ namespace { 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; @@ -181,3 +202,5 @@ 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) */ @@ -217,5 +240,5 @@ namespace { + 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() ) + "," @@ -242,11 +265,31 @@ 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; @@ -302,3 +345,6 @@ namespace { 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' ) ); @@ -317,4 +363,8 @@ namespace { 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; @@ -324,4 +374,8 @@ namespace { 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' ) ); @@ -329,2 +383,20 @@ namespace { } + + 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; + } + }; @@ -334,3 +406,3 @@ 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) { @@ -385,3 +457,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint CACHE = readAhead(); - qWarning("searching for %d", uid ); + qDebug("searching for %d", uid ); QArray<int> search( CACHE ); @@ -395,3 +467,3 @@ OPimTodo OPimTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, 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]; @@ -470,3 +542,3 @@ 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; @@ -491,3 +563,6 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, 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"; @@ -500,3 +575,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, } - /* srtip the end */ + /* strip the end */ query = query.remove( query.length()-3, 3 ); @@ -526,3 +601,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, if ( !asc ) { - qWarning("not ascending!"); + qDebug("not ascending!"); query += " DESC"; @@ -530,3 +605,3 @@ QArray<int> OPimTodoAccessBackendSQL::sorted( bool asc, int sortOrder, - qWarning( query ); + qDebug( query ); OSQLRawQuery raw(query ); @@ -547,3 +622,3 @@ bool OPimTodoAccessBackendSQL::date( QDate& da, const QString& str ) const{ } -OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ +OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{ if ( res.state() == OSQLResult::Failure ) { @@ -555,3 +630,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ OSQLResultItem::ValueList::Iterator it = list.begin(); - qWarning("todo1"); + qDebug("todo1"); OPimTodo to = todo( (*it) ); @@ -561,3 +636,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res) const{ for ( ; it != list.end(); ++it ) { - qWarning("caching"); + qDebug("caching"); cache( todo( (*it) ) ); @@ -567,3 +642,6 @@ 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(); @@ -572,3 +650,3 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { - qWarning("Item is completed: %d", item.data("completed").toInt() ); + qDebug("Item is completed: %d", item.data("completed").toInt() ); @@ -616,2 +694,5 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const { + // Finally load the custom-entries for this UID and put it into the created object + to.setExtraMap( requestCustom( to.uid() ) ); + return to; @@ -626,2 +707,4 @@ OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const { void OPimTodoAccessBackendSQL::fillDict() { + +#if 0 /* initialize dict */ @@ -647,2 +730,4 @@ void OPimTodoAccessBackendSQL::fillDict() { // m_dict.insert("AlarmDateTime", new int(OPimTodo::AlarmDateTime) ); // old stuff (eilers) + +#endif } @@ -666,3 +751,3 @@ QArray<int> OPimTodoAccessBackendSQL::uids( const OSQLResult& res) const{ QArray<int> ints(list.count() ); - qWarning(" count = %d", list.count() ); + qDebug(" count = %d", list.count() ); @@ -727,2 +812,28 @@ 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; +} + + + + } |