# HG changeset patch # User Sebastian Brannstrom # Date 1281361051 -3600 # Node ID a7451a8eb5dc67983d4a386307d93459f376e737 # Parent e4b6ee3295018029ef14cc29ede3c4c0e4446517 Added DB framework for CSV import - doesn't work yet though diff -r e4b6ee329501 -r a7451a8eb5dc contactengine/contactengine.pro --- a/contactengine/contactengine.pro Thu Aug 05 16:40:47 2010 -0700 +++ b/contactengine/contactengine.pro Mon Aug 09 14:37:31 2010 +0100 @@ -4,7 +4,7 @@ # #------------------------------------------------- -QT += core gui webkit +QT += core gui webkit sql TARGET = contactengine TEMPLATE = app @@ -13,10 +13,13 @@ SOURCES += main.cpp\ mainwindow.cpp \ - contactsengine.cpp + contactsengine.cpp \ + dbtools.cpp HEADERS += mainwindow.h \ - contactsengine.h + contactsengine.h \ + database.h \ + dbtools.h FORMS += mainwindow.ui diff -r e4b6ee329501 -r a7451a8eb5dc contactengine/contactengine.pro.user --- a/contactengine/contactengine.pro.user Thu Aug 05 16:40:47 2010 -0700 +++ b/contactengine/contactengine.pro.user Mon Aug 09 14:37:31 2010 +0100 @@ -2,7 +2,7 @@ ProjectExplorer.Project.ActiveTarget - 0 + 1 ProjectExplorer.Project.EditorSettings @@ -13,6 +13,98 @@ ProjectExplorer.Project.Target.0 + Desktop + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + C:/workspace/QtExamples/contactengine-build-desktop + 33 + 2 + true + + + + qmake + QtProjectManager.QMakeBuildStep + + + + Make + Qt4ProjectManager.MakeStep + false + + + + 2 + + Make + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + C:/workspace/QtExamples/contactengine-build-desktop + 33 + 2 + true + + 2 + + contactengine + Qt4ProjectManager.Qt4RunConfiguration + 2 + + contactengine.pro + false + false + + false + false + + + 1 + + + + ProjectExplorer.Project.Target.1 + Qt Simulator Qt4ProjectManager.Target.QtSimulatorTarget 0 @@ -47,7 +139,7 @@ Qt4ProjectManager.Qt4BuildConfiguration 2 C:/workspace/QtExamples/contactengine-build-simulator - 28 + 3 2 true @@ -81,7 +173,7 @@ Qt4ProjectManager.Qt4BuildConfiguration 0 C:/workspace/QtExamples/contactengine-build-simulator - 28 + 3 2 true @@ -103,290 +195,129 @@ - ProjectExplorer.Project.Target.1 + ProjectExplorer.Project.Target.2 - Symbian Device - Qt4ProjectManager.Target.S60DeviceTarget + Remote compiler + Qt4ProjectManager.Target.WccCompilerTarget 0 0 - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - + + Qt4ProjectManager.WccBuildStep + + + + 2 - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 1 + 0 false - 4.6.3 Debug + Maemo 5 Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/workspace/QtExamples/contactengine - 34 - 6 - false + 0 + C:/workspace/QtExamples/contactengine-build-wcc + 12 + 12 + true - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - + + Qt4ProjectManager.WccBuildStep + + + + 2 - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 1 + 0 false - 4.6.3 Release + S60 3rd Edition Feature Pack 1 Qt4ProjectManager.Qt4BuildConfiguration 0 - C:/workspace/QtExamples/contactengine - 34 - 6 - false + C:/workspace/QtExamples/contactengine-build-wcc + 13 + 12 + true - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - + + Qt4ProjectManager.WccBuildStep + + + + 2 - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 1 + 0 false - S60_5th_Edition_SDK_v1.0 (Qt 4.6.3) Debug + S60 3rd Edition Feature Pack 2 Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/workspace/QtExamples/contactengine - 42 - 6 - false + 0 + C:/workspace/QtExamples/contactengine-build-wcc + 14 + 12 + true - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - + + Qt4ProjectManager.WccBuildStep + + + + 2 - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 1 + 0 false - S60_5th_Edition_SDK_v1.0 (Qt 4.6.3) Release + S60 5th Edition Qt4ProjectManager.Qt4BuildConfiguration 0 - C:/workspace/QtExamples/contactengine - 42 - 6 - false + C:/workspace/QtExamples/contactengine-build-wcc + 15 + 12 + true - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - + + Qt4ProjectManager.WccBuildStep + + + + 2 - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 + 1 + 0 false - S60_3rd_FP2_SDK_v1.1 (Qt 4.6.3) Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - C:/workspace/QtExamples/contactengine - 44 - 6 - false - - - - qmake - QtProjectManager.QMakeBuildStep - - - - Make - Qt4ProjectManager.MakeStep - false - - - - - Create SIS Package - Qt4ProjectManager.S60SignBuildStep - false - - - - - 0 - - 3 - - Make - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - S60_3rd_FP2_SDK_v1.1 (Qt 4.6.3) Release + S60 5th Edition (N97 SDK) Qt4ProjectManager.Qt4BuildConfiguration 0 - C:/workspace/QtExamples/contactengine - 44 - 6 - false + C:/workspace/QtExamples/contactengine-build-wcc + 16 + 12 + true - 6 + 5 - contactengine on Symbian Device - Qt4ProjectManager.S60DeviceRunConfiguration - - contactengine.pro - COM5 + Remote compiler - empty run configuration + Qt4ProjectManager.WccRunConfiguration + contactengine.pro 1 ProjectExplorer.Project.TargetCount - 2 + 3 ProjectExplorer.Project.Updater.FileVersion diff -r e4b6ee329501 -r a7451a8eb5dc contactengine/dbtools.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/dbtools.cpp Mon Aug 09 14:37:31 2010 +0100 @@ -0,0 +1,116 @@ +#include +#include + +#include "database.h" +#include "dbtools.h" + +bool DBTools::createTable(QString sqlStmt) +{ + QSqlQuery query; + return query.exec(sqlStmt); +} + +int DBTools::getLastInsertRowId() +{ + int rc = -1; + QSqlQuery query; + query.exec("select last_insert_rowid()"); + if (!query.exec()) { + QString errCode = "last rowid query Failed: " + query.lastError().text(); + qWarning(errCode.toStdString().c_str()); + + } else { + query.next(); + rc = query.value(0).toInt(); + } + return rc; +} + +void DBTools::insertContact( QString name, QString mobile, QString deskphone, + int xtn, QString email, QString skype, + QString twitter, QString title, int site, + int department, int floor) +{ + QSqlQuery query; + + query.prepare("INSERT INTO contacts ( name, mobile, deskphone, xtn, " + "email, skype, twitter, title, site, department, floor) " + "VALUES (:name,:mobile,:deskphone,:xtn,:email,:skype, " + ":twitter, :title, :site, :department, :floor)"); + + query.bindValue(":name", name); + query.bindValue(":mobile", mobile); + query.bindValue(":deskphone", deskphone); + query.bindValue(":xtn", xtn); + query.bindValue(":twitter", twitter); + query.bindValue(":skype", skype); + query.bindValue(":email", email); + query.bindValue(":title", title); + query.bindValue(":site", site); + query.bindValue(":department", department); + query.bindValue(":floor", floor); + + if (!query.exec()) + { + qDebug() << query.lastError(); + qFatal("Failed to add fish."); + } +} + + +bool DBTools::createDB() +{ + QSqlDatabase db; + + // Find QSLite driver + db = QSqlDatabase::addDatabase("QSQLITE"); + + db.setDatabaseName("C:\\workspace\\QtExamples\\contactengine\\contactengine.db"); + + // Open databasee + if(!db.open()) + { + qDebug() << "DB: failed to open" << endl; + exit (1); + } + + qDebug() << "DB: database opened " << endl; + + bool rc = createTable("create table contacts " + "(cid integer primary key, " + "name varchar(128)," + "mobile varchar(128)," + "deskphone varchar(128)," + "xtn int," + "email varchar(128)," + "skype varchar(128)," + "twitter varchar(128)," + "title varchar(128)," + "site int," + "department int," + "floor int"); + + return rc; +} + +void DBTools::testDB() +{ + createDB(); + insertContact("Tom", "12345", "45678", 22, "tom@symbian.org", "thetom", "tomtom", + "Senior Tom", SITE_LONDON, DEPT_TDM, 0); +} + +void DBTools::importCSV(QString fileName) +{ + +} + +DBTools::DBTools(QObject *parent) +{ + QObject(); +} + +DBTools::~DBTools() +{ + +} diff -r e4b6ee329501 -r a7451a8eb5dc contactengine/dbtools.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/contactengine/dbtools.h Mon Aug 09 14:37:31 2010 +0100 @@ -0,0 +1,32 @@ +#ifndef DBTOOLS_H +#define DBTOOLS_H + +#include + +class DBTools : QObject +{ + Q_OBJECT +public: + explicit DBTools(QObject *parent = 0); + ~DBTools(); + +public: + void importCSV(QString fileName); + void testDB(); + +signals: + +public slots: + +private: + bool createDB(); + void insertContact( QString name, QString mobile, QString deskphone, + int xtn, QString email, QString skype, + QString twitter, QString title, int site, + int department, int floor); + int getLastInsertRowId(); + bool createTable(QString sqlStmt); + +}; + +#endif // DBTOOLS_H