summaryrefslogtreecommitdiff
authoreilers <eilers>2003-12-22 11:41:39 (UTC)
committer eilers <eilers>2003-12-22 11:41:39 (UTC)
commit5be4ab495ca232d64305b2634e3bca074f542539 (patch) (side-by-side diff)
tree6255155e18ed63b52505aaa794ed45332bac8cec
parent8d91c030bd4cb8ef296eb25fee9394ca4a8319f8 (diff)
downloadopie-5be4ab495ca232d64305b2634e3bca074f542539.zip
opie-5be4ab495ca232d64305b2634e3bca074f542539.tar.gz
opie-5be4ab495ca232d64305b2634e3bca074f542539.tar.bz2
Fixing stupid bug, found by sourcode review..
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie/pim/odatebookaccessbackend_sql.cpp11
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp11
2 files changed, 22 insertions, 0 deletions
diff --git a/libopie/pim/odatebookaccessbackend_sql.cpp b/libopie/pim/odatebookaccessbackend_sql.cpp
index e893b38..756f405 100644
--- a/libopie/pim/odatebookaccessbackend_sql.cpp
+++ b/libopie/pim/odatebookaccessbackend_sql.cpp
@@ -1,40 +1,43 @@
/*
* SQL Backend for the OPIE-Calender Database.
*
* Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2003/12/22 11:41:39 eilers
+ * Fixing stupid bug, found by sourcode review..
+ *
* Revision 1.2 2003/12/22 10:19:26 eilers
* Finishing implementation of sql-backend for datebook. But I have to
* port the PIM datebook application to use it, before I could debug the
* whole stuff.
* Thus, PIM-Database backend is finished, but highly experimental. And some
* parts are still generic. For instance, the "queryByExample()" methods are
* not (or not fully) implemented. Todo: custom-entries not stored.
* The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
* expression search in the database, which is not supported by sqlite !
* Therefore we need either an extended sqlite or a workaround which would
* be very slow and memory consuming..
*
* Revision 1.1 2003/12/08 15:18:12 eilers
* Committing unfinished sql implementation before merging to libopie2 starts..
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <qarray.h>
#include <qstringlist.h>
@@ -185,103 +188,111 @@ OEvent ODateBookAccessBackend_SQL::find( int uid ) const{
QString qu = "select *";
qu += "from datebook where uid = " + QString::number(uid);
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
OSQLResultItem resItem = res.first();
// Create Map for date event and insert UID
QMap<int,QString> dateEventMap;
dateEventMap.insert( OEvent::FUid, QString::number( uid ) );
// Now insert the data out of the columns into the map.
QMapConstIterator<int, QString> it;
for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
}
// Last step: Put map into date event and return it
OEvent retDate( dateEventMap );
return retDate;
}
+// FIXME: Speed up update of uid's..
bool ODateBookAccessBackend_SQL::add( const OEvent& ev )
{
QMap<int,QString> eventMap = ev.toMap();
QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
QMap<int, QString>::Iterator it;
for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
if ( !eventMap[it.key()].isEmpty() )
qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
else
qu += QString( ",\"\"" );
}
qu += " );";
// Add custom entries
int id = 0;
QMap<QString, QString> customMap = ev.toExtraMap();
for( QMap<QString, QString>::Iterator it = customMap.begin();
it != customMap.end(); ++it ){
qu += "insert into custom_data VALUES("
+ QString::number( ev.uid() )
+ ","
+ QString::number( id++ )
+ ",'"
+ it.key() //.latin1()
+ "',"
+ "0" // Priority for future enhancements
+ ",'"
+ it.data() //.latin1()
+ "');";
}
qWarning("add %s", qu.latin1() );
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
return false;
}
+ // Update list of uid's
+ update();
+
return true;
}
+// FIXME: Speed up update of uid's..
bool ODateBookAccessBackend_SQL::remove( int uid )
{
QString qu = "DELETE from datebook where uid = "
+ QString::number( uid ) + ";";
qu += "DELETE from custom_data where uid = "
+ QString::number( uid ) + ";";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
return false;
}
+ // Update list of uid's
+ update();
+
return true;
}
bool ODateBookAccessBackend_SQL::replace( const OEvent& ev )
{
remove( ev.uid() );
return add( ev );
}
QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
{
return allRecords();
}
QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
{
QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
QArray<int> nix;
return nix;
}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index e893b38..756f405 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -1,40 +1,43 @@
/*
* SQL Backend for the OPIE-Calender Database.
*
* Copyright (c) 2003 by Stefan Eilers (Eilers.Stefan@epost.de)
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
* =====================================================================
* =====================================================================
* Version: $Id$
* =====================================================================
* History:
* $Log$
+ * Revision 1.3 2003/12/22 11:41:39 eilers
+ * Fixing stupid bug, found by sourcode review..
+ *
* Revision 1.2 2003/12/22 10:19:26 eilers
* Finishing implementation of sql-backend for datebook. But I have to
* port the PIM datebook application to use it, before I could debug the
* whole stuff.
* Thus, PIM-Database backend is finished, but highly experimental. And some
* parts are still generic. For instance, the "queryByExample()" methods are
* not (or not fully) implemented. Todo: custom-entries not stored.
* The big show stopper: matchRegExp() (needed by OpieSearch) needs regular
* expression search in the database, which is not supported by sqlite !
* Therefore we need either an extended sqlite or a workaround which would
* be very slow and memory consuming..
*
* Revision 1.1 2003/12/08 15:18:12 eilers
* Committing unfinished sql implementation before merging to libopie2 starts..
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <qarray.h>
#include <qstringlist.h>
@@ -185,103 +188,111 @@ OEvent ODateBookAccessBackend_SQL::find( int uid ) const{
QString qu = "select *";
qu += "from datebook where uid = " + QString::number(uid);
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
OSQLResultItem resItem = res.first();
// Create Map for date event and insert UID
QMap<int,QString> dateEventMap;
dateEventMap.insert( OEvent::FUid, QString::number( uid ) );
// Now insert the data out of the columns into the map.
QMapConstIterator<int, QString> it;
for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
dateEventMap.insert( m_reverseFieldMap[*it], resItem.data( *it ) );
}
// Last step: Put map into date event and return it
OEvent retDate( dateEventMap );
return retDate;
}
+// FIXME: Speed up update of uid's..
bool ODateBookAccessBackend_SQL::add( const OEvent& ev )
{
QMap<int,QString> eventMap = ev.toMap();
QString qu = "insert into datebook VALUES( " + QString::number( ev.uid() );
QMap<int, QString>::Iterator it;
for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
if ( !eventMap[it.key()].isEmpty() )
qu += QString( ",\"%1\"" ).arg( eventMap[it.key()] );
else
qu += QString( ",\"\"" );
}
qu += " );";
// Add custom entries
int id = 0;
QMap<QString, QString> customMap = ev.toExtraMap();
for( QMap<QString, QString>::Iterator it = customMap.begin();
it != customMap.end(); ++it ){
qu += "insert into custom_data VALUES("
+ QString::number( ev.uid() )
+ ","
+ QString::number( id++ )
+ ",'"
+ it.key() //.latin1()
+ "',"
+ "0" // Priority for future enhancements
+ ",'"
+ it.data() //.latin1()
+ "');";
}
qWarning("add %s", qu.latin1() );
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
return false;
}
+ // Update list of uid's
+ update();
+
return true;
}
+// FIXME: Speed up update of uid's..
bool ODateBookAccessBackend_SQL::remove( int uid )
{
QString qu = "DELETE from datebook where uid = "
+ QString::number( uid ) + ";";
qu += "DELETE from custom_data where uid = "
+ QString::number( uid ) + ";";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
return false;
}
+ // Update list of uid's
+ update();
+
return true;
}
bool ODateBookAccessBackend_SQL::replace( const OEvent& ev )
{
remove( ev.uid() );
return add( ev );
}
QArray<int> ODateBookAccessBackend_SQL::rawEvents()const
{
return allRecords();
}
QArray<int> ODateBookAccessBackend_SQL::rawRepeats()const
{
QString qu = "select uid from datebook where RType!=\"\" AND RType!=\"NoRepeat\"";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
QArray<int> nix;
return nix;
}