summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3c87699)
raw | patch | inline | side by side (parent: 3c87699)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 20 Feb 2013 21:50:15 +0000 (22:50 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 20 Feb 2013 21:50:15 +0000 (22:50 +0100) |
This functions checks the database connection and tries to reconnect if there
was a problem. The return code determines if the connection was usable
afterwards.
was a problem. The return code determines if the connection was usable
afterwards.
src/include/utils/dbi.h | patch | blob | history | |
src/utils/dbi.c | patch | blob | history |
index 77d004296d333acaefc7460677a246765e182423..c2490410de8b5a38cd66b8c89db85f0e1b9bd1df 100644 (file)
--- a/src/include/utils/dbi.h
+++ b/src/include/utils/dbi.h
int
sdb_dbi_client_connect(sdb_dbi_client_t *client);
+/*
+ * sdb_dbi_client_check_conn:
+ * Check the database-connection and try to reconnect if that fails.
+ *
+ * Returns:
+ * - 0 on success (the connection is connected after the call)
+ * - a negative value else (failed to reconnect)
+ */
+int
+sdb_dbi_client_check_conn(sdb_dbi_client_t *client);
+
/*
* sdb_dbi_exec_query:
* Execute an SQL query on the database. The specified 'callback' will be
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index ea846b0006c545e1a3e25b4196cd1bc23f5b5904..380a841321a1c6507f0c6f07a7f322e2d3e8ba6b 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
return 0;
} /* sdb_dbi_client_connect */
+int
+sdb_dbi_client_check_conn(sdb_dbi_client_t *client)
+{
+ if (! client)
+ return -1;
+
+ if (! client->conn)
+ return sdb_dbi_client_connect(client);
+
+ if (dbi_conn_ping(client->conn))
+ return 0;
+ return sdb_dbi_client_connect(client);
+} /* sdb_dbi_client_check_conn */
+
int
sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
sdb_dbi_data_cb callback, sdb_object_t *user_data, int n, ...)