diff options
-rw-r--r-- | client/client.pro | 2 | ||||
-rw-r--r-- | client/csv_import.cpp | 32 | ||||
-rw-r--r-- | client/csv_import.h | 12 | ||||
-rw-r--r-- | client/main.cpp | 18 |
4 files changed, 63 insertions, 1 deletions
diff --git a/client/client.pro b/client/client.pro index d680fba..71ab6d5 100644 --- a/client/client.pro +++ b/client/client.pro @@ -1,6 +1,7 @@ QT += core gui sql charts network HEADERS += \ + csv_import.h \ dbconnector.h \ main.h \ mainwindow.h \ @@ -8,6 +9,7 @@ HEADERS += \ timetest.h SOURCES += \ + csv_import.cpp \ dbconnector.cpp \ main.cpp \ mainwindow.cpp \ diff --git a/client/csv_import.cpp b/client/csv_import.cpp new file mode 100644 index 0000000..5507754 --- /dev/null +++ b/client/csv_import.cpp @@ -0,0 +1,32 @@ +#include "csv_import.h" + +CSV_Import::CSV_Import() +{ + +} + + +#include <QString> +#include <QVector> + +QString CSV_Import::csvToSql(QString input){ + + QVector<QString> data; + QString output = "("; + + data = input.split(","); + + for (int i = 1; i < data.size(); ++i) { + + bool valid; + output.append(QString::number(data[i].toInt(&valid, 16))); + + if (i <= data[i].size()) { + output.append(","); + } + + } + output.append(")"); + + return output; +} diff --git a/client/csv_import.h b/client/csv_import.h new file mode 100644 index 0000000..6998417 --- /dev/null +++ b/client/csv_import.h @@ -0,0 +1,12 @@ +#include <QString> +#pragma once + + +class CSV_Import +{ +public: + CSV_Import(); + + virtual QString csvToSql(QString input); +}; + diff --git a/client/main.cpp b/client/main.cpp index 8561786..0a1c4e4 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -16,6 +16,8 @@ #include "ui_mainwindow.h" #include "mytcpsocket.h" #include "timetest.h" +#include "csv_import.h" +#include <QDebug> QSqlDatabase dbRef = QSqlDatabase(); @@ -29,7 +31,21 @@ int main(int argc, char *argv[]) dbRef = QSqlDatabase::addDatabase("QMYSQL"); - w.show(); + QString input = "000e,1d,2f,28\n000d,1d,2f,28\n000c,1d,2f,29\n000b,1d,2f,28\n000a,1d,2f,2a"; + CSV_Import import; + + + QString output = "INSERT INTO `WSdb`.`tblMain` () VALUES "; + QVector<QString> list = input.split("\n"); + for (int i = 0; i < list.size(); ++i) { + output.append(import.csvToSql(list[i])); + if (i+1 < list.size()){ + output.append(","); + } + } + qDebug() << output; + + w.show(); return a.exec(); } |