--- a/contactengine/dbtools.cpp Mon Aug 09 14:37:31 2010 +0100
+++ b/contactengine/dbtools.cpp Mon Aug 09 17:16:20 2010 +0100
@@ -1,11 +1,14 @@
#include <QtCore/QCoreApplication>
#include <QtSql>
+#include <QFile>
#include "database.h"
#include "dbtools.h"
bool DBTools::createTable(QString sqlStmt)
{
+ qDebug() << "DB: create table statement: " << sqlStmt << endl;
+
QSqlQuery query;
return query.exec(sqlStmt);
}
@@ -65,7 +68,7 @@
// Find QSLite driver
db = QSqlDatabase::addDatabase("QSQLITE");
- db.setDatabaseName("C:\\workspace\\QtExamples\\contactengine\\contactengine.db");
+ db.setDatabaseName("C:\\contactengine.db");
// Open databasee
if(!db.open())
@@ -88,8 +91,9 @@
"title varchar(128),"
"site int,"
"department int,"
- "floor int");
+ "floor int)");
+ qDebug() << "DB: create table rc=" << rc << endl;
return rc;
}
@@ -102,12 +106,77 @@
void DBTools::importCSV(QString fileName)
{
+ QFile file(fileName);
+ QString line;
+ if (file.open(QFile::ReadOnly)) {
+ qDebug() << "importCSV file open OK" << endl;
+ char buf[1024];
+
+ while(!file.atEnd())
+ {
+ file.readLine(buf, sizeof(buf));
+ QString string(buf);
+ //qDebug() << string;
+ QStringList stringList = string.split(",");
+
+ //qDebug() << "count: " << stringList.count() << endl;
+ QStringListIterator iter(stringList);
+
+ QString strName;
+ QString strMobile;
+ QString strDeskphone;
+ QString strXtn;
+ QString strEmail;
+ QString strFloor;
+ QString strSkype;
+ QString strTwitter;
+ QString strTitle;
+ QString strSite;
+ QString strDepartment;
+
+ if (stringList.count() > 0)
+ strName = stringList[0];
+
+ if (stringList.count() > 1)
+ strMobile = stringList[1];
+
+ if (stringList.count() > 2)
+ strDeskphone = stringList[2];
+
+ if (stringList.count() > 3)
+ strXtn = stringList[3];
+
+ if (stringList.count() > 4)
+ strEmail = stringList[4];
+
+ if (stringList.count() > 5)
+ strSkype = stringList[5];
+
+ if (stringList.count() > 6)
+ strTwitter = stringList[6];
+
+ if (stringList.count() > 7)
+ strTitle = stringList[7];
+
+ if (stringList.count() > 8)
+ strSite = stringList[8];
+
+ if (stringList.count() > 9)
+ strDepartment = stringList[9];
+
+ if (stringList.count() > 10)
+ strFloor =stringList[10];
+
+ qDebug() << strName << strTitle << endl;
+ }
+ }
}
DBTools::DBTools(QObject *parent)
{
QObject();
+ createDB();
}
DBTools::~DBTools()