Fixed/improved MySQL
This commit is contained in:
+31
-8
@@ -2,6 +2,8 @@
|
||||
#include <src/sql/SqlQuery.h>
|
||||
#include <src/sql/mysql/MySQL.h>
|
||||
#include <src/sql/sqlite/SqliteSQL.h>
|
||||
#include <src/misc/base64.h>
|
||||
#include <src/log/LogUtils.h>
|
||||
|
||||
using namespace sql;
|
||||
using namespace std;
|
||||
@@ -148,18 +150,39 @@ int main() {
|
||||
sql::command((SqlManager*) nullptr, std::string("SELECT *"), {":hello", "world"}, {":numeric", 2});
|
||||
#endif
|
||||
|
||||
sql::mysql::MySQLManager manager;
|
||||
|
||||
if(!manager.connect("mysql://localhost:3306/test?userName=root&password=markus&connections=1")) {
|
||||
sql::mysql::MySQLManager manager;
|
||||
manager.listener_disconnected = [](bool x){
|
||||
cout << "Disconnect: " << x << endl;
|
||||
};
|
||||
|
||||
if(!manager.connect("mysql://localhost:3306/teaspeak?userName=root&password=markus&connections=1")) {
|
||||
cerr << "failed to connect" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
auto result = sql::command(&manager, "SELECT * FROM `level_miner`").query([](int length, std::string* values, std::string* names) {
|
||||
cout << "-- entry" << endl;
|
||||
for(int index = 0; index < length; index++) {
|
||||
cout << " " << names[index] << " => " << values[index] << endl;
|
||||
/*
|
||||
auto result = sql::command(&manager,"INSERT INTO `level_miner` (`username`, `a`) VALUES (:username, :value)", variable{":username", "Hello"}, variable{":value", "TEST!"}).execute();
|
||||
if(!result) cout << result.fmtStr() << endl;
|
||||
|
||||
while(true) {
|
||||
result = sql::command(&manager, "SELECT * FROM `level_miner`").query([](int length, std::string* values, std::string* names) {
|
||||
cout << "-- entry" << endl;
|
||||
for(int index = 0; index < length; index++) {
|
||||
cout << " " << names[index] << " => " << values[index] << endl;
|
||||
}
|
||||
});
|
||||
cout << result.fmtStr() << endl;
|
||||
this_thread::sleep_for(chrono::seconds(1));
|
||||
}
|
||||
*/
|
||||
|
||||
sql::command(&manager, "SELECT `cldbid`,`firstConnect`,`connections` FROM `clients` WHERE `serverId` = :sid AND `clientUid`=:uid LIMIT 1", variable{":sid", 0}, variable{":uid", "serveradmin"}).query([&](void* cl, int length, string* values, string* names){
|
||||
for (int index = 0; index < length; index++) {
|
||||
logTrace(0, "Reading client property from client database table. (Key: " + names[index] + ", Value: " + values[index] + ")");
|
||||
}
|
||||
});
|
||||
cout << result.fmtStr() << endl;
|
||||
return 0;
|
||||
}, (void*) nullptr);
|
||||
|
||||
mysql_library_end();
|
||||
}
|
||||
Reference in New Issue
Block a user