forked from anak10thn/ignsdk-qt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ignsql.cpp
47 lines (44 loc) · 1.26 KB
/
ignsql.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
#include "ignsql.h"
ignsql::ignsql(QObject *parent) :
QObject(parent)
{
}
void ignsql::driver(const QString &drv, QString connect){
if(drv == "mysql"){
QStringList con = connect.split(":");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(con.value(0));
db.setUserName(con.value(1));
db.setPassword(con.value(2));
db.setDatabaseName(con.value(3));
if(!db.open()){
qDebug() << db.lastError();
qFatal("Gagal melakukan koneksi.");
}
else {
qDebug() << "database connect";
}
}
else if (drv == "sqlite"){
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(connect);
if(!db.open()){
qDebug() << db.lastError();
qFatal("Gagal melakukan koneksi.");
}
else {
qDebug() << "database connect";
}
}
else if (drv == "sqlite3"){
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE3");
db.setDatabaseName(connect);
if(!db.open()){
qDebug() << db.lastError();
qFatal("Gagal melakukan koneksi.");
}
else {
qDebug() << "database connect";
}
}
}