summaryrefslogtreecommitdiff
path: root/libopie2
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 /libopie2
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 (limited to 'libopie2') (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
@@ -157,35 +157,35 @@ namespace {
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() {}
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 {
QString qu;
// We do not need "distinct" here. The primary key is always unique..
//qu += "select distinct uid from todolist";
qu += "select uid from todolist";
@@ -211,94 +211,94 @@ namespace {
if (m_todo.hasDueDate() ) {
QDate date = m_todo.dueDate();
year = date.year();
month = date.month();
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() {}
QString RemoveQuery::query()const {
QString qu = "DELETE FROM todolist WHERE uid = " + QString::number(m_uid) + " ;";
qu += "DELETE FROM custom_data WHERE uid = " + QString::number(m_uid);
return qu;
@@ -635,25 +635,25 @@ OPimTodo OPimTodoAccessBackendSQL::todo( const OSQLResult& res ) const{
++it;
for ( ; it != list.end(); ++it ) {
qDebug("caching");
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"),
item.data("progress").toUShort(), hasDueDate, dueDate,
item.data("uid").toInt() );
bool isOk;
@@ -661,43 +661,43 @@ OPimTodo OPimTodoAccessBackendSQL::todo( OSQLResultItem& item )const {
if ( isOk )
to.setPriority( prioInt );
bool hasStartDate = false; QDate startDate = QDate::currentDate();
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 );
QMap<int, QString> recMap;
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;
}
OPimTodo OPimTodoAccessBackendSQL::todo( int uid )const {
FindQuery find( uid );
return todo( m_driver->query(&find) );
@@ -764,25 +764,25 @@ QArray<int> OPimTodoAccessBackendSQL::matchRegexp( const QRegExp &r ) const
{
#if 0
QArray<int> empty;
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 );
#endif
@@ -792,30 +792,30 @@ QBitArray OPimTodoAccessBackendSQL::supports()const {
return sup();
}
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 );
qDebug( "Number of completed: %d", completed_uids.size() );
if ( completed_uids.size() == 0 )
@@ -846,25 +846,25 @@ void OPimTodoAccessBackendSQL::removeAllCompleted(){
OSQLRawQuery raw2( qu );
res = m_driver->query( &raw2 );
if ( res.state() == OSQLResult::Failure ) {
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;
}
OSQLResultItem::ValueList list = res_custom.results();
OSQLResultItem::ValueList::Iterator it = list.begin();
for ( ; it != list.end(); ++it ) {