1 #include "connection.h"
3 pthread_mutex_t nodejs_db::Connection::staticConnectionLock = PTHREAD_MUTEX_INITIALIZER;
5 nodejs_db::Connection::Connection() :
10 this->connectionLock = &(this->staticConnectionLock);
13 nodejs_db::Connection::~Connection() { }
15 std::string nodejs_db::Connection::getHostname()
const {
16 return this->hostname;
19 void nodejs_db::Connection::setHostname(
const std::string& h) {
23 std::string nodejs_db::Connection::getUser()
const {
27 void nodejs_db::Connection::setUser(
const std::string& u) {
31 std::string nodejs_db::Connection::getPassword()
const {
32 return this->password;
35 void nodejs_db::Connection::setPassword(
const std::string& pw) {
39 std::string nodejs_db::Connection::getDatabase()
const {
40 return this->database;
43 void nodejs_db::Connection::setDatabase(
const std::string& db) {
47 uint32_t nodejs_db::Connection::getPort()
const {
51 void nodejs_db::Connection::setPort(uint32_t p) {
55 bool nodejs_db::Connection::isAlive(
bool ping) {
69 if (
string.find_first_of(
'.') !=
string.npos) {
70 char* original =
reinterpret_cast<char*
>(
const_cast<char*
>(
string.c_str()));
75 while ((token = strtok_r(original,
".", &rest))) {
81 if (token[0] !=
'*') {
82 escaped += this->quoteName;
84 escaped += this->quoteName;
91 escaped = this->quoteName +
string + this->quoteName;
96 void nodejs_db::Connection::lock() {
97 pthread_mutex_lock(this->connectionLock);
100 void nodejs_db::Connection::unlock() {
101 pthread_mutex_unlock(this->connectionLock);