author | eilers <eilers> | 2003-09-22 14:31:15 (UTC) |
---|---|---|
committer | eilers <eilers> | 2003-09-22 14:31:15 (UTC) |
commit | 34e86ddf4f9b1045a5b730beab2d8d72e2dd4d56 (patch) (side-by-side diff) | |
tree | cee19bfcf7c8d6a24cd4aaf578bd64b38b2d0ee4 /libopie/pim/otodoaccesssql.cpp | |
parent | fd500184450e37c239e573adf1c12a6ff62b65f6 (diff) | |
download | opie-34e86ddf4f9b1045a5b730beab2d8d72e2dd4d56.zip opie-34e86ddf4f9b1045a5b730beab2d8d72e2dd4d56.tar.gz opie-34e86ddf4f9b1045a5b730beab2d8d72e2dd4d56.tar.bz2 |
Added first experimental incarnation of sql-backend for addressbook.
Some modifications to be able to compile the todo sql-backend.
A lot of changes fill follow...
Diffstat (limited to 'libopie/pim/otodoaccesssql.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccesssql.cpp | 73 |
1 files changed, 63 insertions, 10 deletions
diff --git a/libopie/pim/otodoaccesssql.cpp b/libopie/pim/otodoaccesssql.cpp index ec9c14c..23e0c3e 100644 --- a/libopie/pim/otodoaccesssql.cpp +++ b/libopie/pim/otodoaccesssql.cpp @@ -1,25 +1,25 @@ #include <qdatetime.h> #include <qpe/global.h> -#include <opie/osqldriver.h> -#include <opie/osqlresult.h> -#include <opie/osqlmanager.h> -#include <opie/osqlquery.h> +#include <opie2/osqldriver.h> +#include <opie2/osqlresult.h> +#include <opie2/osqlmanager.h> +#include <opie2/osqlquery.h> #include "otodoaccesssql.h" /* * first some query * CREATE query * LOAD query * INSERT * REMOVE * CLEAR */ namespace { /** * CreateQuery for the Todolist Table */ class CreateQuery : public OSQLQuery { @@ -236,33 +236,33 @@ namespace { .arg(m_start.year() ).arg(m_start.month() ).arg( m_start.day() ) .arg(m_end. year() ).arg(m_end. month() ).arg(m_end.day() ); return str; } }; OTodoAccessBackendSQL::OTodoAccessBackendSQL( const QString& file ) : OTodoAccessBackend(), m_dict(15), m_dirty(true) { QString fi = file; if ( fi.isEmpty() ) fi = Global::applicationFileName( "todolist", "todolist.db" ); OSQLManager man; m_driver = man.standard(); m_driver->setUrl(fi); - fillDict(); + // fillDict(); } OTodoAccessBackendSQL::~OTodoAccessBackendSQL(){ } bool OTodoAccessBackendSQL::load(){ if (!m_driver->open() ) return false; CreateQuery creat; OSQLResult res = m_driver->query(&creat ); m_dirty = true; return true; } bool OTodoAccessBackendSQL::reload(){ return load(); @@ -284,41 +284,41 @@ QArray<int> OTodoAccessBackendSQL::queryByExample( const OTodo& , int, const QDa OTodo OTodoAccessBackendSQL::find(int uid ) const{ FindQuery query( uid ); return todo( m_driver->query(&query) ); } OTodo OTodoAccessBackendSQL::find( int uid, const QArray<int>& ints, uint cur, Frontend::CacheDirection dir ) const{ int CACHE = readAhead(); qWarning("searching for %d", uid ); QArray<int> search( CACHE ); uint size =0; OTodo to; // we try to cache CACHE items switch( dir ) { /* forward */ - case 0: + 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] ); search[size] = ints[i]; size++; } break; /* reverse */ - case 1: + case 1: // FIXME: Not a good style to use magic numbers here (eilers) for (uint i = cur; i != 0 && size < CACHE; i-- ) { search[size] = ints[i]; size++; } break; } search.resize( size ); FindQuery query( search ); OSQLResult res = m_driver->query( &query ); if ( res.state() != OSQLResult::Success ) return to; return todo( res ); } void OTodoAccessBackendSQL::clear() { ClearQuery cle; @@ -368,32 +368,33 @@ QArray<int> OTodoAccessBackendSQL::effectiveToDos( const QDate& s, bool u) { EffQuery ef(s, t, u ); return uids (m_driver->query(&ef) ); } /* * */ QArray<int> OTodoAccessBackendSQL::sorted( bool asc, int sortOrder, int sortFilter, int cat ) { qWarning("sorted %d, %d", asc, sortOrder ); QString query; query = "select uid from todolist WHERE "; /* * Sort Filter stuff * not that straight forward + * FIXME: Replace magic numbers * */ /* Category */ if ( sortFilter & 1 ) { QString str; if (cat != 0 ) str = QString::number( cat ); query += " categories like '%" +str+"%' AND"; } /* Show only overdue */ if ( sortFilter & 2 ) { QDate date = QDate::currentDate(); QString due; QString base; base = QString("DueDate <= '%1-%2-%3' AND completed = 0").arg( date.year() ).arg( date.month() ).arg( date.day() ); query += " " + base + " AND"; } @@ -479,62 +480,114 @@ OTodo OTodoAccessBackendSQL::todo( OSQLResultItem& item )const { cats, item.data("summary"), item.data("description"), item.data("progress").toUShort(), has, da, item.data("uid").toInt() ); return to; } OTodo OTodoAccessBackendSQL::todo( int uid )const { FindQuery find( uid ); return todo( m_driver->query(&find) ); } /* * update the dict */ void OTodoAccessBackendSQL::fillDict() { /* initialize dict */ /* * UPDATE dict if you change anything!!! + * FIXME: Isn't this dict obsolete ? (eilers) */ m_dict.setAutoDelete( TRUE ); m_dict.insert("Categories" , new int(OTodo::Category) ); m_dict.insert("Uid" , new int(OTodo::Uid) ); m_dict.insert("HasDate" , new int(OTodo::HasDate) ); m_dict.insert("Completed" , new int(OTodo::Completed) ); m_dict.insert("Description" , new int(OTodo::Description) ); m_dict.insert("Summary" , new int(OTodo::Summary) ); m_dict.insert("Priority" , new int(OTodo::Priority) ); m_dict.insert("DateDay" , new int(OTodo::DateDay) ); m_dict.insert("DateMonth" , new int(OTodo::DateMonth) ); m_dict.insert("DateYear" , new int(OTodo::DateYear) ); m_dict.insert("Progress" , new int(OTodo::Progress) ); - m_dict.insert("Completed", new int(OTodo::Completed) ); + m_dict.insert("Completed", new int(OTodo::Completed) ); // Why twice ? (eilers) m_dict.insert("CrossReference", new int(OTodo::CrossReference) ); - m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); - m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); +// m_dict.insert("HasAlarmDateTime",new int(OTodo::HasAlarmDateTime) ); // old stuff (eilers) +// m_dict.insert("AlarmDateTime", new int(OTodo::AlarmDateTime) ); // old stuff (eilers) } /* * need to be const so let's fool the * compiler :( */ void OTodoAccessBackendSQL::update()const { ((OTodoAccessBackendSQL*)this)->m_dirty = false; LoadQuery lo; OSQLResult res = m_driver->query(&lo); if ( res.state() != OSQLResult::Success ) return; ((OTodoAccessBackendSQL*)this)->m_uids = uids( res ); } QArray<int> OTodoAccessBackendSQL::uids( const OSQLResult& res) const{ OSQLResultItem::ValueList list = res.results(); OSQLResultItem::ValueList::Iterator it; QArray<int> ints(list.count() ); qWarning(" count = %d", list.count() ); int i = 0; for (it = list.begin(); it != list.end(); ++it ) { ints[i] = (*it).data("uid").toInt(); i++; } return ints; } +QArray<int> OTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const +{ + +#warning OTodoAccessBackendSQL::matchRegexp() not implemented !! + +#if 0 + + Copied from xml-backend by not adapted to sql (eilers) + + QArray<int> m_currentQuery( m_events.count() ); + uint arraycounter = 0; + + + + QMap<int, OTodo>::ConstIterator it; + for (it = m_events.begin(); it != m_events.end(); ++it ) { + if ( it.data().match( r ) ) + m_currentQuery[arraycounter++] = it.data().uid(); + + } + // Shrink to fit.. + m_currentQuery.resize(arraycounter); + + return m_currentQuery; +#endif + QArray<int> empty; + return empty; +} +QBitArray OTodoAccessBackendSQL::supports()const { + + static QBitArray ar = sup(); + return ar; +} + +QBitArray OTodoAccessBackendSQL::sup() { + + QBitArray ar( OTodo::CompletedDate + 1 ); + ar.fill( true ); + ar[OTodo::CrossReference] = false; + ar[OTodo::State ] = false; + ar[OTodo::Reminders] = false; + ar[OTodo::Notifiers] = false; + ar[OTodo::Maintainer] = false; + + return ar; +} + +void OTodoAccessBackendSQL::removeAllCompleted(){ +#warning OTodoAccessBackendSQL::removeAllCompleted() not implemented !! + +} |