918-git-images-111dconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacion
Last change
on this file since 8aa0c08 was
5c30724,
checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago
|
#941 add basic database-independent abstraction (dbi)
Add basic infrastructure to support for the independent database layer.
|
-
Property mode set to
100644
|
File size:
807 bytes
|
Rev | Line | |
---|
[5c30724] | 1 | #include "dbi.h" |
---|
| 2 | |
---|
| 3 | struct og_dbi *og_dbi_open(struct og_dbi_config *config) |
---|
| 4 | { |
---|
| 5 | struct og_dbi *dbi; |
---|
| 6 | |
---|
| 7 | dbi = (struct og_dbi *)malloc(sizeof(struct og_dbi)); |
---|
| 8 | if (!dbi) |
---|
| 9 | return NULL; |
---|
| 10 | |
---|
| 11 | dbi_initialize_r(NULL, &dbi->inst); |
---|
| 12 | dbi->conn = dbi_conn_new_r("mysql", dbi->inst); |
---|
| 13 | if (!dbi->conn) { |
---|
| 14 | free(dbi); |
---|
| 15 | return NULL; |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | dbi_conn_set_option(dbi->conn, "host", config->host); |
---|
| 19 | dbi_conn_set_option(dbi->conn, "username", config->user); |
---|
| 20 | dbi_conn_set_option(dbi->conn, "password", config->passwd); |
---|
| 21 | dbi_conn_set_option(dbi->conn, "dbname", config->database); |
---|
| 22 | dbi_conn_set_option(dbi->conn, "encoding", "UTF-8"); |
---|
| 23 | |
---|
| 24 | if (dbi_conn_connect(dbi->conn) < 0) { |
---|
| 25 | free(dbi); |
---|
| 26 | return NULL; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | return dbi; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | void og_dbi_close(struct og_dbi *dbi) |
---|
| 33 | { |
---|
| 34 | dbi_conn_close(dbi->conn); |
---|
| 35 | dbi_shutdown_r(dbi->inst); |
---|
| 36 | free(dbi); |
---|
| 37 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.