summaryrefslogtreecommitdiff
authorzecke <zecke>2004-05-22 10:17:20 (UTC)
committer zecke <zecke>2004-05-22 10:17:20 (UTC)
commit77f189ec4b959a2874942b00b070ea60c091a7fa (patch) (side-by-side diff)
tree57e36d30a275db1b139ccc5995080b553f33b0f0
parent35b6ab7a844145378a6e427c4666fa65b63d3cfd (diff)
downloadopie-77f189ec4b959a2874942b00b070ea60c091a7fa.zip
opie-77f189ec4b959a2874942b00b070ea60c091a7fa.tar.gz
opie-77f189ec4b959a2874942b00b070ea60c091a7fa.tar.bz2
Fix inserting data with custom tables
Also I don't like the string comparsions. Are they really needed?
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/otodoaccesssql.cpp54
1 files changed, 27 insertions, 27 deletions
diff --git a/libopie2/opiepim/backend/otodoaccesssql.cpp b/libopie2/opiepim/backend/otodoaccesssql.cpp
index ef036d5..132b5a6 100644
--- a/libopie2/opiepim/backend/otodoaccesssql.cpp
+++ b/libopie2/opiepim/backend/otodoaccesssql.cpp
@@ -161,27 +161,27 @@ namespace {
~FindCustomQuery();
QString query()const;
private:
QString single()const;
QString multi()const;
QArray<int> m_uids;
int m_uid;
};
-
+
CreateQuery::CreateQuery() : OSQLQuery() {}
CreateQuery::~CreateQuery() {}
QString CreateQuery::query()const {
QString qu;
qu += "create table todolist( uid PRIMARY KEY, categories, completed, ";
qu += "description, summary, priority, DueDate, progress , state, ";
// This is the recurrance-stuff .. Exceptions are currently not supported (see OPimRecurrence.cpp) ! (eilers)
- qu += "RType, RWeekdays, RPosition, RFreq, RHasEndDate, EndDate, Created, Exceptions, ";
+ 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), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
return qu;
}
LoadQuery::LoadQuery() : OSQLQuery() {}
LoadQuery::~LoadQuery() {}
QString LoadQuery::query()const {
@@ -215,86 +215,86 @@ namespace {
day = date.day();
}
int sYear = 0, sMonth = 0, sDay = 0;
if( m_todo.hasStartDate() ){
QDate sDate = m_todo.startDate();
sYear = sDate.year();
sMonth= sDate.month();
sDay = sDate.day();
- }
+ }
int eYear = 0, eMonth = 0, eDay = 0;
if( m_todo.hasCompletedDate() ){
QDate eDate = m_todo.completedDate();
eYear = eDate.year();
eMonth= eDate.month();
eDay = eDate.day();
- }
+ }
QString qu;
QMap<int, QString> recMap = m_todo.recurrence().toMap();
- qu = "insert into todolist VALUES("
- + QString::number( m_todo.uid() ) + ","
+ qu = "insert into todolist VALUES("
+ + QString::number( m_todo.uid() ) + ","
+ "'" + m_todo.idsToString( m_todo.categories() ) + "'" + ","
- + QString::number( m_todo.isCompleted() ) + ","
+ + QString::number( m_todo.isCompleted() ) + ","
+ "'" + m_todo.description() + "'" + ","
- + "'" + m_todo.summary() + "'" + ","
+ + "'" + m_todo.summary() + "'" + ","
+ QString::number(m_todo.priority() ) + ","
- + "'" + QString::number(year).rightJustify( 4, '0' ) + "-"
+ + "'" + 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() ) + ","
+ "'" + recMap[ OPimRecurrence::RType ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::RWeekdays ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::RPosition ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::RFreq ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::RHasEndDate ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::EndDate ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::Created ] + "'" + ","
+ "'" + recMap[ OPimRecurrence::Exceptions ] + "'" + ",";
-
+
if ( m_todo.hasNotifiers() ) {
OPimNotifyManager manager = m_todo.notifiers();
- qu += "'" + manager.remindersToString() + "'" + ","
+ qu += "'" + manager.remindersToString() + "'" + ","
+ "'" + manager.alarmsToString() + "'" + ",";
}
else{
qu += QString( "''" ) + ","
+ "''" + ",";
}
qu += QString( "''" ) + QString( "," ) // Maintainers (cur. not supported !)
- + "'" + QString::number(sYear).rightJustify( 4, '0' ) + "-"
+ + "'" + 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' ) + "'"
- + ")";
+ + "); ";
// Save custom Entries:
int id = 0;
id = 0;
QMap<QString, QString> customMap = m_todo.toExtraMap();
- for( QMap<QString, QString>::Iterator it = customMap.begin();
+ for( QMap<QString, QString>::Iterator it = customMap.begin();
it != customMap.end(); ++it ){
- qu += "insert into custom_data VALUES("
+ qu += "insert into custom_data VALUES("
+ QString::number( m_todo.uid() )
+ ","
- + QString::number( id++ )
- + ",'"
+ + QString::number( id++ )
+ + ",'"
+ it.key()
+ "',"
+ "0" // Priority for future enhancements
- + ",'"
+ + ",'"
+ it.data()
+ "');";
- }
-
+ }
+
qDebug("add %s", qu.latin1() );
return qu;
}
RemoveQuery::RemoveQuery(int uid )
: OSQLQuery(), m_uid( uid ) {}
RemoveQuery::~RemoveQuery() {}
@@ -639,17 +639,17 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
cache( todo( (*it) ) );
}
return to;
}
OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
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") );
qDebug("Item is completed: %d", item.data("completed").toInt() );
OPimTodo to( (bool)item.data("completed").toInt(), item.data("priority").toInt(),
cats, item.data("summary"), item.data("description"),
@@ -665,17 +665,17 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
hasStartDate = date( startDate, item.data("startdate") );
bool hasCompletedDate = false; QDate completedDate = QDate::currentDate();
hasCompletedDate = date( completedDate, item.data("completeddate") );
if ( hasStartDate )
to.setStartDate( startDate );
if ( hasCompletedDate )
to.setCompletedDate( completedDate );
-
+
OPimNotifyManager& manager = to.notifiers();
manager.alarmsFromString( item.data("alarms") );
manager.remindersFromString( item.data("reminders") );
OPimState pimState;
pimState.setState( QString( item.data("state") ).toInt() );
to.setState( pimState );
@@ -683,17 +683,17 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
recMap.insert( OPimRecurrence::RType , item.data("RType") );
recMap.insert( OPimRecurrence::RWeekdays , item.data("RWeekdays") );
recMap.insert( OPimRecurrence::RPosition , item.data("RPosition") );
recMap.insert( OPimRecurrence::RFreq , item.data("RFreq") );
recMap.insert( OPimRecurrence::RHasEndDate, item.data("RHasEndDate") );
recMap.insert( OPimRecurrence::EndDate , item.data("EndDate") );
recMap.insert( OPimRecurrence::Created , item.data("Created") );
recMap.insert( OPimRecurrence::Exceptions , item.data("Exceptions") );
-
+
OPimRecurrence recur;
recur.fromMap( recMap );
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;
@@ -768,17 +768,17 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
return empty;
#else
QString qu = "SELECT uid FROM todolist WHERE (";
// Do it make sense to search other fields, too ?
qu += " rlike(\""+ r.pattern() + "\",\"description\") OR";
qu += " rlike(\""+ r.pattern() + "\",\"summary\")";
-
+
qu += ")";
qDebug( "query: %s", qu.latin1() );
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
return uids( res );
@@ -796,22 +796,22 @@ QBitArray OPimTodoAccessBackendSQL::sup() const{
QBitArray ar( OPimTodo::CompletedDate + 1 );
ar.fill( true );
ar[OPimTodo::CrossReference] = false;
ar[OPimTodo::State ] = false;
ar[OPimTodo::Reminders] = false;
ar[OPimTodo::Notifiers] = false;
ar[OPimTodo::Maintainer] = false;
-
+
return ar;
}
void OPimTodoAccessBackendSQL::removeAllCompleted(){
- // First we need the uids from all entries which are
+ // First we need the uids from all entries which are
// completed. Then, we just have to remove them...
QString qu = "SELECT uid FROM todolist WHERE completed = 1";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
QArray<int> completed_uids = uids( res );
@@ -850,17 +850,17 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
qWarning("OPimTodoAccessBackendSQL::removeAllCompleted():Failure in query: %s", qu.latin1() );
}
}
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;
}