-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdrequest.cpp
60 lines (53 loc) · 1.78 KB
/
wdrequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "wdrequest.h"
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#include <QDebug>
#include <QApplication>
WDRequest::WDRequest(const QString& wddFilename, QObject *parent) :
QObject(parent)
{
_wddFilename = wddFilename;
connect(&_process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
}
void WDRequest::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
qDebug() << "WDRequest: process finished";
// if error, retun empty string list
if (exitCode>0) {
emit wdRequestResult(QStringList());
return;
}
QFile file("output.csv");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
emit wdRequestResult(QStringList());
return;
}
QTextStream stream(&file);
QString string;
QStringList list;
while (true) {
string = stream.readLine().trimmed();
if (string.isNull()) break;
if (string.isEmpty()) continue;
list << string;
}
file.close();
emit wdRequestResult(list);
}
bool WDRequest::sqlExec(const QString& request) {
qDebug() << "Requesting " << request << " on " << _wddFilename;
QFileInfo info(_wddFilename);
if (!info.exists()) {
qDebug() << "Cannot find wdd file";
return false;
}
QString path = info.absolutePath();
QStringList argList;
argList << _wddFilename << request << QDir::currentPath()+"/output.csv";
QString execPath = QApplication::applicationDirPath()+"/SQLSelect/SQLSelect.exe";
qDebug() << "Working directory: " << path;
qDebug() << execPath << argList;
_process.setWorkingDirectory(path);
_process.start(execPath, argList);
_pid = _process.pid();
}