Last change
on this file since ca545d3 was
0631b0e,
checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago
|
#988 Add DB port option to ogserver.json config file
This patch provides functionality to select a database port. It also adds a
default IP for the database.
|
-
Property mode set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | /* |
---|
2 | * Copyright (C) 2020 Soleta Networks <info@soleta.eu> |
---|
3 | * |
---|
4 | * This program is free software: you can redistribute it and/or modify it under |
---|
5 | * the terms of the GNU Affero General Public License as published by the |
---|
6 | * Free Software Foundation, version 3. |
---|
7 | */ |
---|
8 | |
---|
9 | #include "dbi.h" |
---|
10 | |
---|
11 | struct og_dbi *og_dbi_open(struct og_dbi_config *config) |
---|
12 | { |
---|
13 | struct og_dbi *dbi; |
---|
14 | |
---|
15 | dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi)); |
---|
16 | if (!dbi) |
---|
17 | return NULL; |
---|
18 | |
---|
19 | dbi_initialize_r(NULL, &dbi->inst); |
---|
20 | dbi->conn = dbi_conn_new_r("mysql", dbi->inst); |
---|
21 | if (!dbi->conn) { |
---|
22 | free(dbi); |
---|
23 | return NULL; |
---|
24 | } |
---|
25 | |
---|
26 | dbi_conn_set_option(dbi->conn, "host", config->host); |
---|
27 | dbi_conn_set_option(dbi->conn, "port", config->port); |
---|
28 | dbi_conn_set_option(dbi->conn, "username", config->user); |
---|
29 | dbi_conn_set_option(dbi->conn, "password", config->passwd); |
---|
30 | dbi_conn_set_option(dbi->conn, "dbname", config->database); |
---|
31 | dbi_conn_set_option(dbi->conn, "encoding", "UTF-8"); |
---|
32 | |
---|
33 | if (dbi_conn_connect(dbi->conn) < 0) { |
---|
34 | free(dbi); |
---|
35 | return NULL; |
---|
36 | } |
---|
37 | |
---|
38 | return dbi; |
---|
39 | } |
---|
40 | |
---|
41 | void og_dbi_close(struct og_dbi *dbi) |
---|
42 | { |
---|
43 | dbi_conn_close(dbi->conn); |
---|
44 | dbi_shutdown_r(dbi->inst); |
---|
45 | free(dbi); |
---|
46 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.