Module: sip-router
Branch: janakj/mysql
Commit: 205f28ce7929d6a43e4c649b9db25bcd70b9d19b
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=205f28c…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Fri Oct 17 08:01:23 2008 +0000
- docs extension: explain fetch_result functionality better to prevent errors
because of wrong usage, found from Juha Heinanen
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5088 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_dbase.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/modules/db_mysql/km_dbase.c b/modules/db_mysql/km_dbase.c
index 726a881..ecc3106 100644
--- a/modules/db_mysql/km_dbase.c
+++ b/modules/db_mysql/km_dbase.c
@@ -251,7 +251,15 @@ int db_mysql_query(const db_con_t* _h, const db_key_t* _k, const db_op_t* _op,
}
/**
- * Gets a partial result set.
+ * \brief Gets a partial result set, fetch rows from a result
+ *
+ * Gets a partial result set, fetch a number of rows from a database result.
+ * This function initialize the given result structure on the first run, and
+ * fetches the nrows number of rows. On subsequenting runs, it uses the
+ * existing result and fetches more rows, until it reaches the end of the
+ * result set. Because of this the result needs to be null in the first
+ * invocation of the function. If the number of wanted rows is zero, the
+ * function returns anything with a result of zero.
* \param _h structure representing the database connection
* \param _r pointer to a structure representing the result
* \param nrows number of fetched rows
Module: sip-router
Branch: janakj/mysql
Commit: c56b4491a617caa82be13a8ed95949f04b7980f0
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c56b449…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Thu Nov 13 16:14:34 2008 +0000
- add a comment about the NULL value behaviour of libmysql
- add some doxygen documentation
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5197 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_val.c | 26 ++++++++++++++++++++------
modules/db_mysql/km_val.h | 26 ++++++++++++++++++++------
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/modules/db_mysql/km_val.c b/modules/db_mysql/km_val.c
index 8cb485f..3af1e65 100644
--- a/modules/db_mysql/km_val.c
+++ b/modules/db_mysql/km_val.c
@@ -22,7 +22,7 @@
*/
/*! \file
- * \brief DB_MYSQL :: Data conversion
+ * \brief DB_MYSQL :: Data conversions
* \ingroup db_mysql
* Module: \ref db_mysql
*/
@@ -36,8 +36,15 @@
#include <stdio.h>
-/*! \brief
- * Convert str to db value, does not copy strings
+/*!
+ * \brief Convert a str to a db value, does not copy strings
+ *
+ * Convert a str to a db value, does not copy strings.
+ * \param _t destination value type
+ * \param _v destination value
+ * \param _s source string
+ * \param _l string length
+ * \return 0 on success, negative on error
*/
int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l)
{
@@ -47,7 +54,7 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
LM_ERR("invalid parameter value\n");
return -1;
}
-
+ /* A NULL string is a NULL value in mysql, otherwise its an empty value */
if (!_s) {
memset(_v, 0, sizeof(db_val_t));
/* Initialize the string pointers to a dummy empty
@@ -143,8 +150,15 @@ int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int
}
-/*! \brief
- * Used when converting result from a query
+/*!
+ * \brief Converting a value to a string
+ *
+ * Converting a value to a string, used when converting result from a query
+ * \param _c database connection
+ * \param _v source value
+ * \param _s target string
+ * \param _len target string length
+ * \return 0 on success, negative on error
*/
int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
{
diff --git a/modules/db_mysql/km_val.h b/modules/db_mysql/km_val.h
index 4f034cc..f9cb609 100644
--- a/modules/db_mysql/km_val.h
+++ b/modules/db_mysql/km_val.h
@@ -22,7 +22,7 @@
*/
/*! \file
- * \brief DB_MYSQL :: Conversions
+ * \brief DB_MYSQL :: Data conversions
* \ref val.c
* \ingroup db_mysql
* Module: \ref db_mysql
@@ -37,15 +37,29 @@
#include "../../db/db.h"
-/**
- * Does not copy strings
+/*!
+ * \brief Convert a str to a db value, does not copy strings
+ *
+ * Convert a str to a db value, does not copy strings.
+ * \param _t destination value type
+ * \param _v destination value
+ * \param _s source string
+ * \param _l string length
+ * \return 0 on success, negative on error
*/
int db_mysql_str2val(const db_type_t _t, db_val_t* _v, const char* _s, const int _l);
-/**
- * Used when converting result from a query
+/*!
+ * \brief Converting a value to a string
+ *
+ * Converting a value to a string, used when converting result from a query
+ * \param _c database connection
+ * \param _v source value
+ * \param _s target string
+ * \param _len target string length
+ * \return 0 on success, negative on error
*/
int db_mysql_val2str(const db_con_t* _con, const db_val_t* _v, char* _s, int* _len);
-#endif /* VAL_H */
+#endif
Module: sip-router
Branch: janakj/mysql
Commit: 5ffb6c9ef29a1d02401e0986a0aff058d339338d
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=5ffb6c9…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Tue Nov 25 09:34:15 2008 +0000
- fix a few errors in doxygen documentation
- sync one function definitions variables with declaration
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5254 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_res.c | 24 ++++++++++++++++++------
modules/db_mysql/km_res.h | 16 +++++++++++++---
modules/db_mysql/km_row.c | 8 ++++++--
modules/db_mysql/km_row.h | 10 +++++++---
4 files changed, 44 insertions(+), 14 deletions(-)
diff --git a/modules/db_mysql/km_res.c b/modules/db_mysql/km_res.c
index cf1e261..13a5c9b 100644
--- a/modules/db_mysql/km_res.c
+++ b/modules/db_mysql/km_res.c
@@ -41,8 +41,14 @@
#include "res.h"
-/*! \brief
- * Get and convert columns from a result
+/*!
+ * \brief Get and convert columns from a result
+ *
+ * Get and convert columns from a result, fills the result structure
+ * with data from the database.
+ * \param _h database connection
+ * \param _r database result set
+ * \return 0 on success, negative on failure
*/
int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
{
@@ -143,8 +149,11 @@ int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r)
}
-/*! \brief
- * Convert rows from mysql to db API representation
+/*!
+ * \brief Convert rows from mysql to db API representation
+ * \param _h database connection
+ * \param _r database result set
+ * \return 0 on success, negative on failure
*/
static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
{
@@ -190,8 +199,11 @@ static inline int db_mysql_convert_rows(const db_con_t* _h, db_res_t* _r)
}
-/*! \brief
- * Fill the structure with data from database
+/*!
+ * \brief Fill the result structure with data from database
+ * \param _h database connection
+ * \param _r database result
+ * \return 0 on success, negative on failure
*/
int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r)
{
diff --git a/modules/db_mysql/km_res.h b/modules/db_mysql/km_res.h
index 051c037..4bded19 100644
--- a/modules/db_mysql/km_res.h
+++ b/modules/db_mysql/km_res.h
@@ -38,11 +38,21 @@
#include "../../db/db_con.h"
-/*
- * Fill the structure with data from database
+/*!
+ * \brief Fill the result structure with data from database
+ * \param _h database connection
+ * \param _r database result
+ * \return 0 on success, negative on failure
*/
int db_mysql_convert_result(const db_con_t* _h, db_res_t* _r);
+
+/*!
+ * \brief Get and convert columns from a result
+ * \param _h database connection
+ * \param _r database result set
+ * \return 0 on success, negative on failure
+ */
int db_mysql_get_columns(const db_con_t* _h, db_res_t* _r);
-#endif /* RES_H */
+#endif
diff --git a/modules/db_mysql/km_row.c b/modules/db_mysql/km_row.c
index 62b9ae8..c623198 100644
--- a/modules/db_mysql/km_row.c
+++ b/modules/db_mysql/km_row.c
@@ -37,8 +37,12 @@
#include "val.h"
#include "row.h"
-/*! \brief
- * Convert a row from result into db API representation
+/*!
+ * \brief Convert a row from result into DB API representation
+ * \param _h database connection
+ * \param _res database result in the DB API representation
+ * \param _r database result row
+ * \return 0 on success, -1 on failure
*/
int db_mysql_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r)
{
diff --git a/modules/db_mysql/km_row.h b/modules/db_mysql/km_row.h
index 52fd489..068f05e 100644
--- a/modules/db_mysql/km_row.h
+++ b/modules/db_mysql/km_row.h
@@ -39,9 +39,13 @@
#include "../../db/db_row.h"
-/**
- * Convert a row from result into db API representation
+/*!
+ * \brief Convert a row from result into DB API representation
+ * \param _h database connection
+ * \param _res database result in the DB API representation
+ * \param _r database result row
+ * \return 0 on success, -1 on failure
*/
int db_mysql_convert_row(const db_con_t* _h, db_res_t* _res, db_row_t* _r);
-#endif /* ROW_H */
+#endif
Module: sip-router
Branch: janakj/mysql
Commit: b32ac21f17c46f6d3d6c60f3a02ddb66ae9061fe
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b32ac21…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Mon Dec 15 15:07:12 2008 +0000
- change behaviour of db_str2val, this now copy strings
- this change was necessary because in some circumstances the memory that is
returned from the database driver is used by some other means too fast,
causes crashed or wrong results later on, this bug is timing related
- this means for mysql and unixodbc that the performance will be decreased a
bit, postgres already copied the string, so here nothing change
- add a new function to DB core API, db_val2str that, usable to convert
numerical values to a string, and common things like NULL values conversion,
parameter checks
- convert mysql, postgres and unixodbc module to use this new function
- convert postgres function to use the core db_str2val function, the copying
is now done at a different place, cleanup the code somewhat
- remove unnecessary assignment if a NULL value is encountered in postgres
- TODO: fix NULL handling and double copying that is done now for unixodbc
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5359 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_val.c | 66 +++------------------------------------------
1 files changed, 4 insertions(+), 62 deletions(-)
diff --git a/modules/db_mysql/km_val.c b/modules/db_mysql/km_val.c
index 12f6ac5..338e48f 100644
--- a/modules/db_mysql/km_val.c
+++ b/modules/db_mysql/km_val.c
@@ -32,9 +32,6 @@
#include "val.h"
#include "my_con.h"
-#include <string.h>
-#include <stdio.h>
-
/*!
* \brief Converting a value to a string
@@ -48,60 +45,14 @@
*/
int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len)
{
- int l;
+ int l, tmp;
char* old_s;
- if (!_c || !_v || !_s || !_len || !*_len) {
- LM_ERR("invalid parameter value\n");
- return -1;
- }
+ tmp = db_val2str(_c, _v, _s, _len);
+ if (tmp < 1)
+ return tmp;
- if (VAL_NULL(_v)) {
- if (*_len < sizeof("NULL")) {
- LM_ERR("buffer too small\n");
- return -1;
- }
- *_len = snprintf(_s, *_len, "NULL");
- return 0;
- }
-
switch(VAL_TYPE(_v)) {
- case DB_INT:
- if (db_int2str(VAL_INT(_v), _s, _len) < 0) {
- LM_ERR("error while converting string to int\n");
- return -2;
- } else {
- return 0;
- }
- break;
-
- case DB_BIGINT:
- if (db_longlong2str(VAL_BIGINT(_v), _s, _len) < 0) {
- LM_ERR("error while converting string to big int\n");
- return -3;
- } else {
- return 0;
- }
- break;
-
- case DB_BITMAP:
- if (db_int2str(VAL_BITMAP(_v), _s, _len) < 0) {
- LM_ERR("error while converting string to int\n");
- return -4;
- } else {
- return 0;
- }
- break;
-
- case DB_DOUBLE:
- if (db_double2str(VAL_DOUBLE(_v), _s, _len) < 0) {
- LM_ERR("error while converting string to double\n");
- return -5;
- } else {
- return 0;
- }
- break;
-
case DB_STRING:
l = strlen(VAL_STRING(_v));
if (*_len < (l * 2 + 3)) {
@@ -133,15 +84,6 @@ int db_mysql_val2str(const db_con_t* _c, const db_val_t* _v, char* _s, int* _len
}
break;
- case DB_DATETIME:
- if (db_time2str(VAL_TIME(_v), _s, _len) < 0) {
- LM_ERR("error while converting string to time_t\n");
- return -8;
- } else {
- return 0;
- }
- break;
-
case DB_BLOB:
l = VAL_BLOB(_v).len;
if (*_len < (l * 2 + 3)) {
Module: sip-router
Branch: janakj/mysql
Commit: 89215f17a700df083e99f16e58becb3d2ab28f0b
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=89215f1…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Mon Jan 5 12:27:49 2009 +0000
- add group functionality to read content from specified sections
of the mysql config to the db_mysql module, db_url examples:
* mysql://user:pass@[group]host:port/db or
* mysql://user:pass@[group]/db or
* mysql://[group]/db
- existing functionality is not changed, this is backward compatible
- check usernames for NULL before comparing in DB API, otherwise
it would segfault when only a group name is specified
- patch from Andreas Granig, agranig at sipwise dot com, closes #1815631
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5413 689a6050-402a-0410-94f2-e92a70836424
---
modules/db_mysql/km_README | 51 ++++++++++++++++++++++++++
modules/db_mysql/km_doc/db_mysql_admin.xml | 54 ++++++++++++++++++++++++++++
modules/db_mysql/km_my_con.c | 28 ++++++++++++--
3 files changed, 129 insertions(+), 4 deletions(-)
diff --git a/modules/db_mysql/km_README b/modules/db_mysql/km_README
index 54951d1..eb7693c 100644
--- a/modules/db_mysql/km_README
+++ b/modules/db_mysql/km_README
@@ -34,12 +34,16 @@ Daniel-Constantin Mierla
1.4. Exported Functions
1.5. Installation
+ 1.6. Reading configuration from my.cnf
List of Examples
1.1. Set ping_interval parameter
1.2. Set timeout_interval parameter
1.3. Set auto_reconnect parameter
+ 1.4. Set a my.cnf group in db_url parameter
+ 1.5. Adding a kamailio group to my.cnf
+ 1.6. Using [client] and specific group
Chapter 1. Admin Guide
@@ -121,3 +125,50 @@ modparam("auto_reconnect", "auto_reconnect", 0)
* - from command line use: 'make all
include_modules="db_mysql"; make install
include_modules="db_mysql"'.
+
+1.6. Reading configuration from my.cnf
+
+ In order to take into account specific mysql client options, a
+ my.cnf config group can be passed using the db_url module
+ parameter. This is done by setting [group] in front of or
+ instead of the host part. The following examples are valid
+ db_url definitions, which include a my.cnf group:
+ * mysql://user:pass@[group]host:port/db
+ * mysql://user:pass@[group]:port/db
+ * mysql://user:pass@[group]/db
+ * mysql://[group]/db
+
+ Example 1.4. Set a my.cnf group in db_url parameter
+...
+modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
+...
+
+ Example 1.5. Adding a kamailio group to my.cnf
+...
+[kamailio]
+socket = /path/to/mysql.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+
+ In addition to the given group, also the [client] section is
+ read, in the order given in my.cnf. So if you for example
+ specify a socket in both your specific group and the client
+ group, then the value is taken from the last one.
+
+ Example 1.6. Using [client] and specific group
+...
+[client]
+socket = /var/run/mysql/mysqld.sock
+
+[kamailio]
+socket = /path/to/mysqld.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+
+ In the example given above, the socket /path/to/mysqld.sock is
+ used by Kamailio because both [kamailio] and [client] define
+ this option, and the latter overwrites the first.
diff --git a/modules/db_mysql/km_doc/db_mysql_admin.xml b/modules/db_mysql/km_doc/db_mysql_admin.xml
index 31079e0..a484d02 100644
--- a/modules/db_mysql/km_doc/db_mysql_admin.xml
+++ b/modules/db_mysql/km_doc/db_mysql_admin.xml
@@ -140,5 +140,59 @@ modparam("auto_reconnect", "auto_reconnect", 0)
</listitem>
</itemizedlist>
</section>
+ <section>
+ <title>Reading configuration from my.cnf</title>
+ <para>
+ In order to take into account specific mysql client options, a my.cnf config group can be passed using the <emphasis>db_url</emphasis> module parameter. This is done by setting <emphasis>[group]</emphasis> in front of or instead of the host part. The following examples are valid <emphasis>db_url</emphasis> definitions, which include a my.cnf group:
+ </para>
+
+ <itemizedlist>
+ <listitem>mysql://user:pass@[group]host:port/db</listitem>
+ <listitem>mysql://user:pass@[group]:port/db</listitem>
+ <listitem>mysql://user:pass@[group]/db</listitem>
+ <listitem>mysql://[group]/db</listitem>
+ </itemizedlist>
+ <example>
+ <title>Set a my.cnf group in <varname>db_url</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("usrloc", "db_url", "mysql://[kamailio]/kamailio)
+...
+</programlisting>
+ </example>
+ <example>
+ <title>Adding a kamailio group to my.cnf</title>
+ <programlisting format="linespecific">
+...
+[kamailio]
+socket = /path/to/mysql.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+</programlisting>
+ </example>
+ <para>
+ In addition to the given group, also the <emphasis>[client]</emphasis> section is read, in the order given in my.cnf. So if you for example specify a <emphasis>socket</emphasis> in both your specific group and the client group, then the value is taken from the last one.
+ </para>
+ <example>
+ <title>Using [client] and specific group</title>
+ <programlisting format="linespecific">
+...
+[client]
+socket = /var/run/mysql/mysqld.sock
+
+[kamailio]
+socket = /path/to/mysqld.sock
+user = kamailiouser
+password = kamailiopass
+default-character-set = utf8
+...
+</programlisting>
+ </example>
+ <para>
+ In the example given above, the socket <emphasis>/path/to/mysqld.sock</emphasis> is used by &kamailio; because both <emphasis>[kamailio]</emphasis> and <emphasis>[client]</emphasis> define this option, and the latter overwrites the first.
+ </para>
+ </section>
</chapter>
diff --git a/modules/db_mysql/km_my_con.c b/modules/db_mysql/km_my_con.c
index 1a907b9..b5ec56a 100644
--- a/modules/db_mysql/km_my_con.c
+++ b/modules/db_mysql/km_my_con.c
@@ -43,6 +43,7 @@
struct my_con* db_mysql_new_connection(const struct db_id* id)
{
struct my_con* ptr;
+ char *host, *grp;
if (!id) {
LM_ERR("invalid parameter value\n");
@@ -66,11 +67,30 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
mysql_init(ptr->con);
+ if (id->host[0] == '[' && (host = strchr(id->host, ']')) != NULL) {
+ grp = id->host + 1;
+ *host = '\0';
+ if (host != id->host + strlen(id->host)-1) {
+ host += 1; // host found after closing bracket
+ }
+ else {
+ // let mysql read host info from my.cnf
+ // (defaults to "localhost")
+ host = NULL;
+ }
+ // read [client] and [<grp>] sections in the order
+ // given in my.cnf
+ mysql_options(ptr->con, MYSQL_READ_DEFAULT_GROUP, grp);
+ }
+ else {
+ host = id->host;
+ }
+
if (id->port) {
- LM_DBG("opening connection: mysql://xxxx:xxxx@%s:%d/%s\n", ZSW(id->host),
+ LM_DBG("opening connection: mysql://xxxx:xxxx@%s:%d/%s\n", ZSW(host),
id->port, ZSW(id->database));
} else {
- LM_DBG("opening connection: mysql://xxxx:xxxx@%s/%s\n", ZSW(id->host),
+ LM_DBG("opening connection: mysql://xxxx:xxxx@%s/%s\n", ZSW(host),
ZSW(id->database));
}
@@ -80,10 +100,10 @@ struct my_con* db_mysql_new_connection(const struct db_id* id)
mysql_options(ptr->con, MYSQL_OPT_WRITE_TIMEOUT, (const char *)&db_mysql_timeout_interval);
#if (MYSQL_VERSION_ID >= 40100)
- if (!mysql_real_connect(ptr->con, id->host, id->username, id->password,
+ if (!mysql_real_connect(ptr->con, host, id->username, id->password,
id->database, id->port, 0, CLIENT_MULTI_STATEMENTS)) {
#else
- if (!mysql_real_connect(ptr->con, id->host, id->username, id->password,
+ if (!mysql_real_connect(ptr->con, host, id->username, id->password,
id->database, id->port, 0, 0)) {
#endif
LM_ERR("driver error: %s\n", mysql_error(ptr->con));