summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
index f4f3c94..105c106 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend_sql.cpp
@@ -22,38 +22,43 @@
-. .:....=;==+<; You should have received a copy of the GNU
-_. . . )=. = Library General Public License along with
-- :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
* SQL Backend for the OPIE-Calender Database.
*
*/
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <qarray.h>
-#include <qstringlist.h>
-
-#include <qpe/global.h>
-
+/* OPIE */
#include <opie2/osqldriver.h>
#include <opie2/osqlmanager.h>
#include <opie2/osqlquery.h>
#include <opie2/opimrecurrence.h>
#include <opie2/odatebookaccessbackend_sql.h>
+#include <opie2/odebug.h>
+
+#include <qpe/global.h>
+
+/* QT */
+#include <qarray.h>
+#include <qstringlist.h>
+
+/* STD */
+#include <stdio.h>
+#include <stdlib.h>
+
using namespace Opie::DB;
namespace {
/**
* a find query for custom elements
*/
class FindCustomQuery : public OSQLQuery {
public:
FindCustomQuery(int uid);
FindCustomQuery(const QArray<int>& );
~FindCustomQuery();
@@ -153,25 +158,25 @@ bool ODateBookAccessBackend_SQL::load()
// It is save here to create the table, even if it
// do exist. ( Is that correct for all databases ?? )
QString qu = "create table datebook( uid INTEGER PRIMARY KEY ";
QMap<int, QString>::Iterator it;
for ( it = ++m_fieldMap.begin(); it != m_fieldMap.end(); ++it ){
qu += QString( ",%1 VARCHAR(10)" ).arg( it.data() );
}
qu += " );";
qu += "create table custom_data( uid INTEGER, id INTEGER, type VARCHAR(10), priority INTEGER, value VARCHAR(10), PRIMARY KEY /* identifier */ (uid, id) );";
- qWarning( "command: %s", qu.latin1() );
+ owarn << "command: " << qu << "" << oendl;
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success )
return false;
update();
return true;
}
void ODateBookAccessBackend_SQL::update()
@@ -212,51 +217,51 @@ void ODateBookAccessBackend_SQL::clear()
{
QString qu = "drop table datebook;";
qu += "drop table custom_data;";
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
reload();
}
OPimEvent ODateBookAccessBackend_SQL::find( int uid ) const{
- qDebug( "ODateBookAccessBackend_SQL::find( %d )", uid );
+ odebug << "ODateBookAccessBackend_SQL::find( " << uid << " )" << oendl;
QString qu = "select *";
qu += "from datebook where uid = " + QString::number(uid);
- qDebug( "Query: %s", qu.latin1() );
+ odebug << "Query: " << qu << "" << oendl;
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( OPimEvent::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, add custom map and return it
OPimEvent retDate( dateEventMap );
retDate.setExtraMap( requestCustom( uid ) );
- qDebug( "ODateBookAccessBackend_SQL::find( %d ) end", uid );
+ odebug << "ODateBookAccessBackend_SQL::find( " << uid << " ) end" << oendl;
return retDate;
}
// FIXME: Speed up update of uid's..
bool ODateBookAccessBackend_SQL::add( const OPimEvent& 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() )
@@ -274,25 +279,25 @@ bool ODateBookAccessBackend_SQL::add( const OPimEvent& ev )
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() );
+ owarn << "add " << qu << "" << oendl;
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
if ( res.state() != OSQLResult::Success ){
return false;
}
// Update list of uid's
update();
return true;
}
@@ -381,74 +386,74 @@ OPimEvent::ValueList ODateBookAccessBackend_SQL::directRawRepeats()
QArray<int> ODateBookAccessBackend_SQL::matchRegexp( const QRegExp &r ) const
{
QString qu = "SELECT uid FROM datebook WHERE (";
// Do it make sense to search other fields, too ?
qu += " rlike(\""+ r.pattern() + "\", Location ) OR";
qu += " rlike(\""+ r.pattern() + "\", Note )";
qu += " )";
- qDebug( "query: %s", qu.latin1() );
+ odebug << "query: " << qu << "" << oendl;
OSQLRawQuery raw( qu );
OSQLResult res = m_driver->query( &raw );
return extractUids( res );
}
/* ===== Private Functions ========================================== */
QArray<int> ODateBookAccessBackend_SQL::extractUids( OSQLResult& res ) const
{
- qWarning("extractUids");
+ owarn << "extractUids" << oendl;
QTime t;
t.start();
OSQLResultItem::ValueList list = res.results();
OSQLResultItem::ValueList::Iterator it;
QArray<int> ints(list.count() );
- qWarning(" count = %d", list.count() );
+ owarn << " count = " << list.count() << "" << oendl;
int i = 0;
for (it = list.begin(); it != list.end(); ++it ) {
ints[i] = (*it).data("uid").toInt();
i++;
}
- qWarning("extractUids ready: count2 = %d needs %d ms", i, t.elapsed() );
+ owarn << "extractUids ready: count2 = " << i << " needs " << t.elapsed() << " ms" << oendl;
return ints;
}
QMap<QString, QString> ODateBookAccessBackend_SQL::requestCustom( int uid ) const
{
QTime t;
t.start();
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 !!");
+ owarn << "OSQLResult::Failure in find query !!" << oendl;
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" ) );
}
- qDebug("RequestCustom needed: %d ms", t.elapsed() );
+ odebug << "RequestCustom needed: " << t.elapsed() << " ms" << oendl;
return customMap;
}
}