summaryrefslogtreecommitdiffstats
path: root/admin/Sources/Services/ogAdmServer/sources/dbi.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-11-26 18:59:32 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-03-05 23:45:48 +0100
commitab71ca861917c851cab23e5527dc7baca968e273 (patch)
tree737ef72c4658db67a1b942c5f5d70dbbcc3e1adc /admin/Sources/Services/ogAdmServer/sources/dbi.c
parent8aa0c08b30c7630cb43252d00d8e8b3193a5258e (diff)
#967 rename .cpp to .c
This actually is C code, use the gcc compiler instead.
Diffstat (limited to 'admin/Sources/Services/ogAdmServer/sources/dbi.c')
-rw-r--r--admin/Sources/Services/ogAdmServer/sources/dbi.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/dbi.c b/admin/Sources/Services/ogAdmServer/sources/dbi.c
new file mode 100644
index 00000000..cc5c5b59
--- /dev/null
+++ b/admin/Sources/Services/ogAdmServer/sources/dbi.c
@@ -0,0 +1,37 @@
+#include "dbi.h"
+
+struct og_dbi *og_dbi_open(struct og_dbi_config *config)
+{
+ struct og_dbi *dbi;
+
+ dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi));
+ if (!dbi)
+ return NULL;
+
+ dbi_initialize_r(NULL, &dbi->inst);
+ dbi->conn = dbi_conn_new_r("mysql", dbi->inst);
+ if (!dbi->conn) {
+ free(dbi);
+ return NULL;
+ }
+
+ dbi_conn_set_option(dbi->conn, "host", config->host);
+ dbi_conn_set_option(dbi->conn, "username", config->user);
+ dbi_conn_set_option(dbi->conn, "password", config->passwd);
+ dbi_conn_set_option(dbi->conn, "dbname", config->database);
+ dbi_conn_set_option(dbi->conn, "encoding", "UTF-8");
+
+ if (dbi_conn_connect(dbi->conn) < 0) {
+ free(dbi);
+ return NULL;
+ }
+
+ return dbi;
+}
+
+void og_dbi_close(struct og_dbi *dbi)
+{
+ dbi_conn_close(dbi->conn);
+ dbi_shutdown_r(dbi->inst);
+ free(dbi);
+}