... | ... |
@@ -22,7 +22,7 @@ |
22 | 22 |
/** @addtogroup mysql |
23 | 23 |
* @{ |
24 | 24 |
*/ |
25 |
- |
|
25 |
+ |
|
26 | 26 |
#include "db_mysql.h" |
27 | 27 |
#include "km_db_mysql.h" |
28 | 28 |
|
... | ... |
@@ -126,9 +126,9 @@ static int mysql_mod_init(void) |
126 | 126 |
{ |
127 | 127 |
#if MYSQL_VERSION_ID >= 40101 |
128 | 128 |
my_client_ver = mysql_get_client_version(); |
129 |
- if ((my_client_ver >= 50025) || |
|
130 |
- ((my_client_ver >= 40122) && |
|
131 |
- (my_client_ver < 50000))) { |
|
129 |
+ if ((my_client_ver >= 50025) || |
|
130 |
+ ((my_client_ver >= 40122) && |
|
131 |
+ (my_client_ver < 50000))) { |
|
132 | 132 |
if (my_send_to == 0) { |
133 | 133 |
my_send_to= DEFAULT_MY_SEND_TO; |
134 | 134 |
} |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module interface |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -15,8 +15,8 @@ |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 | 17 |
* |
18 |
- * You should have received a copy of the GNU General Public License |
|
19 |
- * along with this program; if not, write to the Free Software |
|
18 |
+ * You should have received a copy of the GNU General Public License |
|
19 |
+ * along with this program; if not, write to the Free Software |
|
20 | 20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | 21 |
*/ |
22 | 22 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module interface |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -65,7 +65,7 @@ static param_export_t params[] = { |
65 | 65 |
{0, 0, 0} |
66 | 66 |
}; |
67 | 67 |
|
68 |
-struct kam_module_exports kam_exports = { |
|
68 |
+struct kam_module_exports kam_exports = { |
|
69 | 69 |
"db_mysql", |
70 | 70 |
DEFAULT_DLFLAGS, /* dlopen flags */ |
71 | 71 |
cmds, |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module interface |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
* |
23 | 23 |
*/ |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module core functions |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -68,7 +68,7 @@ static char *mysql_sql_buf; |
68 | 68 |
* \return zero on success, negative value on failure |
69 | 69 |
*/ |
70 | 70 |
static int db_mysql_submit_query(const db1_con_t* _h, const str* _s) |
71 |
-{ |
|
71 |
+{ |
|
72 | 72 |
time_t t; |
73 | 73 |
int i, code; |
74 | 74 |
|
... | ... |
@@ -137,9 +137,9 @@ void db_mysql_async_exec_task(void *param) |
137 | 137 |
{ |
138 | 138 |
str *p; |
139 | 139 |
db1_con_t* dbc; |
140 |
- |
|
140 |
+ |
|
141 | 141 |
p = (str*)param; |
142 |
- |
|
142 |
+ |
|
143 | 143 |
dbc = db_mysql_init(&p[0]); |
144 | 144 |
|
145 | 145 |
if(dbc==NULL) { |
... | ... |
@@ -148,7 +148,7 @@ void db_mysql_async_exec_task(void *param) |
148 | 148 |
} |
149 | 149 |
if(db_mysql_submit_query(dbc, &p[1])<0) { |
150 | 150 |
LM_ERR("failed to execute query [%.*s] on async worker\n", |
151 |
- (p[1].len>100)?100:p[1].len, p[1].s); |
|
151 |
+ (p[1].len>100)?100:p[1].len, p[1].s); |
|
152 | 152 |
} |
153 | 153 |
db_mysql_close(dbc); |
154 | 154 |
} |
... | ... |
@@ -295,20 +295,20 @@ done: |
295 | 295 |
*/ |
296 | 296 |
int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r) |
297 | 297 |
{ |
298 |
- if ((!_h) || (!_r)) { |
|
299 |
- LM_ERR("invalid parameter value\n"); |
|
300 |
- return -1; |
|
301 |
- } |
|
302 |
- |
|
303 |
- mysql_free_result(RES_RESULT(_r)); |
|
304 |
- RES_RESULT(_r) = 0; |
|
305 |
- pkg_free(RES_PTR(_r)); |
|
306 |
- |
|
307 |
- if (db_free_result(_r) < 0) { |
|
308 |
- LM_ERR("unable to free result structure\n"); |
|
309 |
- return -1; |
|
310 |
- } |
|
311 |
- return 0; |
|
298 |
+ if ((!_h) || (!_r)) { |
|
299 |
+ LM_ERR("invalid parameter value\n"); |
|
300 |
+ return -1; |
|
301 |
+ } |
|
302 |
+ |
|
303 |
+ mysql_free_result(RES_RESULT(_r)); |
|
304 |
+ RES_RESULT(_r) = 0; |
|
305 |
+ pkg_free(RES_PTR(_r)); |
|
306 |
+ |
|
307 |
+ if (db_free_result(_r) < 0) { |
|
308 |
+ LM_ERR("unable to free result structure\n"); |
|
309 |
+ return -1; |
|
310 |
+ } |
|
311 |
+ return 0; |
|
312 | 312 |
} |
313 | 313 |
|
314 | 314 |
|
... | ... |
@@ -326,8 +326,8 @@ int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r) |
326 | 326 |
* \return zero on success, negative value on failure |
327 | 327 |
*/ |
328 | 328 |
int db_mysql_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op, |
329 |
- const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, |
|
330 |
- const db_key_t _o, db1_res_t** _r) |
|
329 |
+ const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, |
|
330 |
+ const db_key_t _o, db1_res_t** _r) |
|
331 | 331 |
{ |
332 | 332 |
return db_do_query(_h, _k, _op, _v, _c, _n, _nc, _o, _r, |
333 | 333 |
db_mysql_val2str, db_mysql_submit_query, db_mysql_store_result); |
... | ... |
@@ -526,8 +526,8 @@ int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, |
526 | 526 |
* \param _un number of columns to update |
527 | 527 |
* \return zero on success, negative value on failure |
528 | 528 |
*/ |
529 |
-int db_mysql_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, |
|
530 |
- const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n, |
|
529 |
+int db_mysql_update(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _o, |
|
530 |
+ const db_val_t* _v, const db_key_t* _uk, const db_val_t* _uv, const int _n, |
|
531 | 531 |
const int _un) |
532 | 532 |
{ |
533 | 533 |
return db_do_update(_h, _k, _o, _v, _uk, _uv, _n, _un, db_mysql_val2str, |
... | ... |
@@ -716,8 +716,8 @@ int db_mysql_end_transaction(db1_con_t* _h) |
716 | 716 |
} |
717 | 717 |
|
718 | 718 |
/* Only _end_ the transaction after the raw_query. That way, if the |
719 |
- raw_query fails, and the calling module does an abort_transaction() |
|
720 |
- to clean-up, a ROLLBACK will be sent to the DB. */ |
|
719 |
+ * raw_query fails, and the calling module does an abort_transaction() |
|
720 |
+ * to clean-up, a ROLLBACK will be sent to the DB. */ |
|
721 | 721 |
CON_TRANSACTION(_h) = 0; |
722 | 722 |
|
723 | 723 |
if(db_mysql_unlock_tables(_h)<0) |
... | ... |
@@ -749,7 +749,7 @@ int db_mysql_abort_transaction(db1_con_t* _h) |
749 | 749 |
} |
750 | 750 |
|
751 | 751 |
/* Whether the rollback succeeds or not we need to _end_ the |
752 |
- transaction now or all future starts will fail */ |
|
752 |
+ * transaction now or all future starts will fail */ |
|
753 | 753 |
CON_TRANSACTION(_h) = 0; |
754 | 754 |
|
755 | 755 |
if (db_mysql_raw_query(_h, &rollback_query_str, NULL) < 0) |
... | ... |
@@ -775,23 +775,23 @@ done: |
775 | 775 |
|
776 | 776 |
|
777 | 777 |
/** |
778 |
- * Insert a row into a specified table, update on duplicate key. |
|
779 |
- * \param _h structure representing database connection |
|
780 |
- * \param _k key names |
|
781 |
- * \param _v values of the keys |
|
782 |
- * \param _n number of key=value pairs |
|
778 |
+ * Insert a row into a specified table, update on duplicate key. |
|
779 |
+ * \param _h structure representing database connection |
|
780 |
+ * \param _k key names |
|
781 |
+ * \param _v values of the keys |
|
782 |
+ * \param _n number of key=value pairs |
|
783 | 783 |
*/ |
784 |
- int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, |
|
784 |
+int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, |
|
785 | 785 |
const int _n) |
786 |
- { |
|
786 |
+{ |
|
787 | 787 |
int off, ret; |
788 | 788 |
static str sql_str; |
789 |
- |
|
789 |
+ |
|
790 | 790 |
if ((!_h) || (!_k) || (!_v) || (!_n)) { |
791 | 791 |
LM_ERR("invalid parameter value\n"); |
792 | 792 |
return -1; |
793 | 793 |
} |
794 |
- |
|
794 |
+ |
|
795 | 795 |
ret = snprintf(mysql_sql_buf, sql_buffer_size, "insert into %s%.*s%s (", |
796 | 796 |
CON_TQUOTESZ(_h), CON_TABLE(_h)->len, CON_TABLE(_h)->s, CON_TQUOTESZ(_h)); |
797 | 797 |
if (ret < 0 || ret >= sql_buffer_size) goto error; |
... | ... |
@@ -809,18 +809,18 @@ done: |
809 | 809 |
off += ret; |
810 | 810 |
|
811 | 811 |
*(mysql_sql_buf + off++) = ')'; |
812 |
- |
|
812 |
+ |
|
813 | 813 |
ret = snprintf(mysql_sql_buf + off, sql_buffer_size - off, " on duplicate key update "); |
814 | 814 |
if (ret < 0 || ret >= (sql_buffer_size - off)) goto error; |
815 | 815 |
off += ret; |
816 |
- |
|
816 |
+ |
|
817 | 817 |
ret = db_print_set(_h, mysql_sql_buf + off, sql_buffer_size - off, _k, _v, _n, db_mysql_val2str); |
818 | 818 |
if (ret < 0) return -1; |
819 | 819 |
off += ret; |
820 |
- |
|
820 |
+ |
|
821 | 821 |
sql_str.s = mysql_sql_buf; |
822 | 822 |
sql_str.len = off; |
823 |
- |
|
823 |
+ |
|
824 | 824 |
if (db_mysql_submit_query(_h, &sql_str) < 0) { |
825 | 825 |
LM_ERR("error while submitting query\n"); |
826 | 826 |
return -2; |
... | ... |
@@ -841,7 +841,8 @@ error: |
841 | 841 |
* \param _n number of key=value pairs |
842 | 842 |
* \return zero on success, negative value on failure |
843 | 843 |
*/ |
844 |
-int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n) |
|
844 |
+int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, |
|
845 |
+ const db_val_t* _v, const int _n) |
|
845 | 846 |
{ |
846 | 847 |
return db_do_insert_delayed(_h, _k, _v, _n, db_mysql_val2str, |
847 | 848 |
db_mysql_submit_query); |
... | ... |
@@ -855,7 +856,8 @@ int db_mysql_insert_delayed(const db1_con_t* _h, const db_key_t* _k, const db_va |
855 | 856 |
* \param _n number of key=value pairs |
856 | 857 |
* \return zero on success, negative value on failure |
857 | 858 |
*/ |
858 |
-int db_mysql_insert_async(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n) |
|
859 |
+int db_mysql_insert_async(const db1_con_t* _h, const db_key_t* _k, |
|
860 |
+ const db_val_t* _v, const int _n) |
|
859 | 861 |
{ |
860 | 862 |
return db_do_insert(_h, _k, _v, _n, db_mysql_val2str, |
861 | 863 |
db_mysql_submit_query_async); |
... | ... |
@@ -882,15 +884,15 @@ int db_mysql_use_table(db1_con_t* _h, const str* _t) |
882 | 884 |
*/ |
883 | 885 |
int db_mysql_alloc_buffer(void) |
884 | 886 |
{ |
885 |
- if (db_api_init()) |
|
886 |
- { |
|
887 |
- LM_ERR("Failed to initialise db api\n"); |
|
887 |
+ if (db_api_init()) |
|
888 |
+ { |
|
889 |
+ LM_ERR("Failed to initialise db api\n"); |
|
888 | 890 |
return -1; |
889 |
- } |
|
891 |
+ } |
|
890 | 892 |
|
891 |
- mysql_sql_buf = (char*)malloc(sql_buffer_size); |
|
892 |
- if (mysql_sql_buf == NULL) |
|
893 |
- return -1; |
|
894 |
- else |
|
895 |
- return 0; |
|
893 |
+ mysql_sql_buf = (char*)malloc(sql_buffer_size); |
|
894 |
+ if (mysql_sql_buf == NULL) |
|
895 |
+ return -1; |
|
896 |
+ else |
|
897 |
+ return 0; |
|
896 | 898 |
} |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -63,8 +63,8 @@ int db_mysql_free_result(const db1_con_t* _h, db1_res_t* _r); |
63 | 63 |
* Do a query |
64 | 64 |
*/ |
65 | 65 |
int db_mysql_query(const db1_con_t* _h, const db_key_t* _k, const db_op_t* _op, |
66 |
- const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, |
|
67 |
- const db_key_t _o, db1_res_t** _r); |
|
66 |
+ const db_val_t* _v, const db_key_t* _c, const int _n, const int _nc, |
|
67 |
+ const db_key_t _o, db1_res_t** _r); |
|
68 | 68 |
|
69 | 69 |
|
70 | 70 |
/*! \brief |
... | ... |
@@ -88,13 +88,14 @@ int db_mysql_raw_query_async(const db1_con_t* _h, const str* _s); |
88 | 88 |
/*! \brief |
89 | 89 |
* Insert a row into table |
90 | 90 |
*/ |
91 |
-int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, const int _n); |
|
91 |
+int db_mysql_insert(const db1_con_t* _h, const db_key_t* _k, |
|
92 |
+ const db_val_t* _v, const int _n); |
|
92 | 93 |
|
93 | 94 |
|
94 | 95 |
/*! \brief |
95 | 96 |
* Delete a row from table |
96 | 97 |
*/ |
97 |
-int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const |
|
98 |
+int db_mysql_delete(const db1_con_t* _h, const db_key_t* _k, const |
|
98 | 99 |
db_op_t* _o, const db_val_t* _v, const int _n); |
99 | 100 |
|
100 | 101 |
|
... | ... |
@@ -142,7 +143,8 @@ int db_mysql_abort_transaction(db1_con_t* _h); |
142 | 143 |
/*! \brief |
143 | 144 |
* Insert a row into table, update on duplicate key |
144 | 145 |
*/ |
145 |
-int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, const db_val_t* _v, |
|
146 |
+int db_mysql_insert_update(const db1_con_t* _h, const db_key_t* _k, |
|
147 |
+ const db_val_t* _v, |
|
146 | 148 |
const int _n); |
147 | 149 |
|
148 | 150 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Copyright (C) 2001-2003 FhG Fokus |
3 | 3 |
* Copyright (C) 2008 1&1 Internet AG |
4 | 4 |
* |
... | ... |
@@ -14,8 +14,8 @@ |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
16 | 16 |
* |
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module result related functions |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -65,7 +65,7 @@ int db_mysql_get_columns(const db1_con_t* _h, db1_res_t* _r) |
65 | 65 |
} else { |
66 | 66 |
LM_DBG("%d columns returned from the query\n", RES_COL_N(_r)); |
67 | 67 |
} |
68 |
- |
|
68 |
+ |
|
69 | 69 |
if (db_allocate_columns(_r, RES_COL_N(_r)) != 0) { |
70 | 70 |
RES_COL_N(_r) = 0; |
71 | 71 |
LM_ERR("could not allocate columns\n"); |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module result related functions |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module row related functions |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -57,12 +57,12 @@ int db_mysql_convert_row(const db1_con_t* _h, db1_res_t* _res, db_row_t* _r) |
57 | 57 |
LM_ERR("could not allocate row"); |
58 | 58 |
return -2; |
59 | 59 |
} |
60 |
- |
|
60 |
+ |
|
61 | 61 |
lengths = mysql_fetch_lengths(RES_RESULT(_res)); |
62 | 62 |
|
63 | 63 |
for(i = 0; i < RES_COL_N(_res); i++) { |
64 | 64 |
if (db_str2val(RES_TYPES(_res)[i], &(ROW_VALUES(_r)[i]), |
65 |
- ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) { |
|
65 |
+ ((MYSQL_ROW)RES_ROW(_res))[i], lengths[i], 0) < 0) { |
|
66 | 66 |
LM_ERR("failed to convert value\n"); |
67 | 67 |
LM_DBG("free row at %p\n", _r); |
68 | 68 |
db_free_row(_r); |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* MySQL module row related functions |
3 | 3 |
* |
4 | 4 |
* Copyright (C) 2001-2003 FhG Fokus |
... | ... |
@@ -16,8 +16,8 @@ |
16 | 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | 17 |
* GNU General Public License for more details. |
18 | 18 |
* |
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program; if not, write to the Free Software |
|
19 |
+ * You should have received a copy of the GNU General Public License |
|
20 |
+ * along with this program; if not, write to the Free Software |
|
21 | 21 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 | 22 |
*/ |
23 | 23 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Copyright (C) 2001-2003 FhG Fokus |
3 | 3 |
* Copyright (C) 2008 1&1 Internet AG |
4 | 4 |
* |
... | ... |
@@ -14,8 +14,8 @@ |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
16 | 16 |
* |
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
... | ... |
@@ -81,7 +81,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le |
81 | 81 |
} else { |
82 | 82 |
old_s = _s; |
83 | 83 |
*_s++ = '\''; |
84 |
- _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STRING(_v), l); |
|
84 |
+ _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, |
|
85 |
+ VAL_STRING(_v), l); |
|
85 | 86 |
*_s++ = '\''; |
86 | 87 |
*_s = '\0'; /* FIXME */ |
87 | 88 |
*_len = _s - old_s; |
... | ... |
@@ -96,7 +97,8 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le |
96 | 97 |
} else { |
97 | 98 |
old_s = _s; |
98 | 99 |
*_s++ = '\''; |
99 |
- _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, VAL_STR(_v).s, VAL_STR(_v).len); |
|
100 |
+ _s += mysql_real_escape_string(CON_CONNECTION(_c), _s, |
|
101 |
+ VAL_STR(_v).s, VAL_STR(_v).len); |
|
100 | 102 |
*_s++ = '\''; |
101 | 103 |
*_s = '\0'; |
102 | 104 |
*_len = _s - old_s; |
... | ... |
@@ -117,7 +119,7 @@ int db_mysql_val2str(const db1_con_t* _c, const db_val_t* _v, char* _s, int* _le |
117 | 119 |
*_s = '\0'; |
118 | 120 |
*_len = _s - old_s; |
119 | 121 |
return 0; |
120 |
- } |
|
122 |
+ } |
|
121 | 123 |
break; |
122 | 124 |
|
123 | 125 |
default: |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Copyright (C) 2001-2003 FhG Fokus |
3 | 3 |
* Copyright (C) 2008 1&1 Internet AG |
4 | 4 |
* |
... | ... |
@@ -14,8 +14,8 @@ |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
16 | 16 |
* |
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-/* |
|
1 |
+/* |
|
2 | 2 |
* Copyright (C) 2001-2003 FhG Fokus |
3 | 3 |
* Copyright (C) 2006-2007 iptelorg GmbH |
4 | 4 |
* |
... | ... |
@@ -14,8 +14,8 @@ |
14 | 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 |
* GNU General Public License for more details. |
16 | 16 |
* |
17 |
- * You should have received a copy of the GNU General Public License |
|
18 |
- * along with this program; if not, write to the Free Software |
|
17 |
+ * You should have received a copy of the GNU General Public License |
|
18 |
+ * along with this program; if not, write to the Free Software |
|
19 | 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | 20 |
*/ |
21 | 21 |
|
... | ... |
@@ -25,7 +25,7 @@ |
25 | 25 |
|
26 | 26 |
/* the following macro will break the compile on solaris */ |
27 | 27 |
#if !defined (__SVR4) && !defined (__sun) |
28 |
- #define _XOPEN_SOURCE 4 /* bsd */ |
|
28 |
+#define _XOPEN_SOURCE 4 /* bsd */ |
|
29 | 29 |
#endif |
30 | 30 |
#define _XOPEN_SOURCE_EXTENDED 1 /* solaris */ |
31 | 31 |
#define _SVID_SOURCE 1 /* timegm */ |
... | ... |
@@ -113,7 +113,7 @@ static str strings[] = { |
113 | 113 |
|
114 | 114 |
|
115 | 115 |
#define APPEND_CSTR(p, cstr) do { \ |
116 |
- int _len = strlen(cstr); \ |
|
116 |
+ int _len = strlen(cstr); \ |
|
117 | 117 |
memcpy((p), (cstr), _len); \ |
118 | 118 |
(p) += _len; \ |
119 | 119 |
} while(0) |
... | ... |
@@ -132,8 +132,8 @@ static void my_cmd_free(db_cmd_t* cmd, struct my_cmd* payload) |
132 | 132 |
|
133 | 133 |
|
134 | 134 |
/** Builds a DELETE SQL statement.The function builds DELETE statement where |
135 |
- * cmd->match specify WHERE clause. |
|
136 |
- * @param sql_cmd SQL statement as a result of this function |
|
135 |
+ * cmd->match specify WHERE clause. |
|
136 |
+ * @param sql_cmd SQL statement as a result of this function |
|
137 | 137 |
* @param cmd input for statement creation |
138 | 138 |
* @return -1 on error, 0 on success |
139 | 139 |
*/ |
... | ... |
@@ -153,19 +153,19 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) |
153 | 153 |
sql_cmd->len += strlen(fld[i].name); |
154 | 154 |
|
155 | 155 |
switch(fld[i].op) { |
156 |
- case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; |
|
157 |
- case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; |
|
158 |
- case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; |
|
159 |
- case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; |
|
160 |
- case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; |
|
161 |
- case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; |
|
162 |
- default: |
|
163 |
- ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); |
|
164 |
- return -1; |
|
156 |
+ case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; |
|
157 |
+ case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; |
|
158 |
+ case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; |
|
159 |
+ case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; |
|
160 |
+ case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; |
|
161 |
+ case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; |
|
162 |
+ default: |
|
163 |
+ ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); |
|
164 |
+ return -1; |
|
165 | 165 |
} |
166 | 166 |
|
167 | 167 |
sql_cmd->len += strings[STR_ESC].len; |
168 |
- |
|
168 |
+ |
|
169 | 169 |
if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += strings[STR_AND].len; |
170 | 170 |
} |
171 | 171 |
} |
... | ... |
@@ -176,7 +176,7 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) |
176 | 176 |
return -1; |
177 | 177 |
} |
178 | 178 |
p = sql_cmd->s; |
179 |
- |
|
179 |
+ |
|
180 | 180 |
APPEND_STR(p, strings[STR_DELETE]); |
181 | 181 |
APPEND_STR(p, cmd->table); |
182 | 182 |
|
... | ... |
@@ -187,19 +187,19 @@ static int build_delete_cmd(str* sql_cmd, db_cmd_t* cmd) |
187 | 187 |
APPEND_CSTR(p, fld[i].name); |
188 | 188 |
|
189 | 189 |
switch(fld[i].op) { |
190 |
- case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; |
|
191 |
- case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; |
|
192 |
- case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; |
|
193 |
- case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; |
|
194 |
- case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; |
|
195 |
- case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; |
|
190 |
+ case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; |
|
191 |
+ case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; |
|
192 |
+ case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; |
|
193 |
+ case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; |
|
194 |
+ case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; |
|
195 |
+ case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; |
|
196 | 196 |
} |
197 |
- |
|
197 |
+ |
|
198 | 198 |
APPEND_STR(p, strings[STR_ESC]); |
199 | 199 |
if (!DB_FLD_LAST(fld[i + 1])) APPEND_STR(p, strings[STR_AND]); |
200 | 200 |
} |
201 | 201 |
} |
202 |
- |
|
202 |
+ |
|
203 | 203 |
*p = '\0'; |
204 | 204 |
return 0; |
205 | 205 |
} |
... | ... |
@@ -237,19 +237,19 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) |
237 | 237 |
sql_cmd->len += strlen(fld[i].name); |
238 | 238 |
|
239 | 239 |
switch(fld[i].op) { |
240 |
- case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; |
|
241 |
- case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; |
|
242 |
- case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; |
|
243 |
- case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; |
|
244 |
- case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; |
|
245 |
- case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; |
|
246 |
- default: |
|
247 |
- ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); |
|
248 |
- return -1; |
|
240 |
+ case DB_EQ: sql_cmd->len += strings[STR_OP_EQ].len; break; |
|
241 |
+ case DB_NE: sql_cmd->len += strings[STR_OP_NE].len; break; |
|
242 |
+ case DB_LT: sql_cmd->len += strings[STR_OP_LT].len; break; |
|
243 |
+ case DB_GT: sql_cmd->len += strings[STR_OP_GT].len; break; |
|
244 |
+ case DB_LEQ: sql_cmd->len += strings[STR_OP_LEQ].len; break; |
|
245 |
+ case DB_GEQ: sql_cmd->len += strings[STR_OP_GEQ].len; break; |
|
246 |
+ default: |
|
247 |
+ ERR("mysql: Unsupported db_fld operator %d\n", fld[i].op); |
|
248 |
+ return -1; |
|
249 | 249 |
} |
250 | 250 |
|
251 | 251 |
sql_cmd->len += strings[STR_ESC].len; |
252 |
- |
|
252 |
+ |
|
253 | 253 |
if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += strings[STR_AND].len; |
254 | 254 |
} |
255 | 255 |
} |
... | ... |
@@ -260,7 +260,7 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) |
260 | 260 |
return -1; |
261 | 261 |
} |
262 | 262 |
p = sql_cmd->s; |
263 |
- |
|
263 |
+ |
|
264 | 264 |
APPEND_STR(p, strings[STR_SELECT]); |
265 | 265 |
if (DB_FLD_EMPTY(cmd->result)) { |
266 | 266 |
*p++ = '*'; |
... | ... |
@@ -280,14 +280,14 @@ static int build_select_cmd(str* sql_cmd, db_cmd_t* cmd) |
280 | 280 |
APPEND_CSTR(p, fld[i].name); |
281 | 281 |
|
282 | 282 |
switch(fld[i].op) { |
283 |
- case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; |
|
284 |
- case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; |
|
285 |
- case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; |
|
286 |
- case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; |
|
287 |
- case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; |
|
288 |
- case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; |
|
283 |
+ case DB_EQ: APPEND_STR(p, strings[STR_OP_EQ]); break; |
|
284 |
+ case DB_NE: APPEND_STR(p, strings[STR_OP_NE]); break; |
|
285 |
+ case DB_LT: APPEND_STR(p, strings[STR_OP_LT]); break; |
|
286 |
+ case DB_GT: APPEND_STR(p, strings[STR_OP_GT]); break; |
|
287 |
+ case DB_LEQ: APPEND_STR(p, strings[STR_OP_LEQ]); break; |
|
288 |
+ case DB_GEQ: APPEND_STR(p, strings[STR_OP_GEQ]); break; |
|
289 | 289 |
} |
290 |
- |
|
290 |
+ |
|
291 | 291 |
APPEND_STR(p, strings[STR_ESC]); |
292 | 292 |
if (!DB_FLD_LAST(fld[i + 1])) APPEND_STR(p, strings[STR_AND]); |
293 | 293 |
} |
... | ... |
@@ -319,7 +319,7 @@ static int build_replace_cmd(str* sql_cmd, db_cmd_t* cmd) |
319 | 319 |
if (!DB_FLD_LAST(fld[i + 1])) sql_cmd->len += 2; /* , twice */ |
320 | 320 |
} |
321 | 321 |
sql_cmd->len += strings[STR_VALUES].len; |
322 |
- sql_cmd->len += 1; /* ) */ |
|
322 |
+ sql_cmd->len += 1; /* ) */ |
|
323 | 323 |
|
324 | 324 |
sql_cmd->s = pkg_malloc(sql_cmd->len + 1); |
325 | 325 |
if (sql_cmd->s == NULL) { |
... | ... |
@@ -327,7 +327,7 @@ static int build_replace_cmd(str* sql_cmd, db_cmd_t* cmd) |
327 | 327 |
return -1; |
328 | 328 |
} |
329 | 329 |
p = sql_cmd->s; |
330 |
- |
|
330 |
+ |
|
331 | 331 |
APPEND_STR(p, strings[STR_REPLACE]); |
332 | 332 |
APPEND_STR(p, cmd->table); |
333 | 333 |
*p++ = ' '; |
... | ... |
@@ -356,7 +356,7 @@ struct string_buffer { |
356 | 356 |
char *s; /**< allocated memory itself */ |
357 | 357 |
int len; /**< used memory */ |
358 | 358 |
int size; /**< total size of allocated memory */ |
359 |
- int increment; /**< increment when realloc is necessary */ |
|
359 |
+ int increment; /**< increment when realloc is necessary */ |
|
360 | 360 |
}; |
361 | 361 |
|
362 | 362 |
|
... | ... |
@@ -398,7 +398,7 @@ static inline int sb_add(struct string_buffer *sb, str *nstr) |
398 | 398 |
|
399 | 399 |
/** |
400 | 400 |
* Set members of str variable. |
401 |
- * Used for temporary str variables. |
|
401 |
+ * Used for temporary str variables. |
|
402 | 402 |
*/ |
403 | 403 |
static inline str* set_str(str *str, const char *s) |
404 | 404 |
{ |
... | ... |
@@ -447,14 +447,14 @@ static int build_update_cmd(str* sql_cmd, db_cmd_t* cmd) |
447 | 447 |
rv |= sb_add(&sql_buf, set_str(&tmpstr, fld[i].name)); |
448 | 448 |
|
449 | 449 |
switch(fld[i].op) { |
450 |
- case DB_EQ: rv |= sb_add(&sql_buf, &strings[STR_OP_EQ]); break; |
|
451 |
- case DB_NE: rv |= sb_add(&sql_buf, &strings[STR_OP_NE]); break; |
|
452 |
- case DB_LT: rv |= sb_add(&sql_buf, &strings[STR_OP_LT]); break; |
|
453 |
- case DB_GT: rv |= sb_add(&sql_buf, &strings[STR_OP_GT]); break; |
|
454 |
- case DB_LEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_LEQ]); break; |
|
455 |
- case DB_GEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_GEQ]); break; |
|
450 |
+ case DB_EQ: rv |= sb_add(&sql_buf, &strings[STR_OP_EQ]); break; |
|
451 |
+ case DB_NE: rv |= sb_add(&sql_buf, &strings[STR_OP_NE]); break; |
|
452 |
+ case DB_LT: rv |= sb_add(&sql_buf, &strings[STR_OP_LT]); break; |
|
453 |
+ case DB_GT: rv |= sb_add(&sql_buf, &strings[STR_OP_GT]); break; |
|
454 |
+ case DB_LEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_LEQ]); break; |
|
455 |
+ case DB_GEQ: rv |= sb_add(&sql_buf, &strings[STR_OP_GEQ]); break; |
|
456 | 456 |
} |
457 |
- |
|
457 |
+ |
|
458 | 458 |
rv |= sb_add(&sql_buf, &strings[STR_ESC]); |
459 | 459 |
if (!DB_FLD_LAST(fld[i + 1])) rv |= sb_add(&sql_buf, &strings[STR_AND]); |
460 | 460 |
} |
... | ... |
@@ -477,7 +477,7 @@ static inline void update_field(MYSQL_BIND *param, db_fld_t* fld) |
477 | 477 |
{ |
478 | 478 |
struct my_fld* fp; /* field payload */ |
479 | 479 |
struct tm* t; |
480 |
- |
|
480 |
+ |
|
481 | 481 |
fp = DB_GET_PAYLOAD(fld); |
482 | 482 |
|
483 | 483 |
#ifndef MYSQL_FAKE_NULL |
... | ... |
@@ -486,60 +486,60 @@ static inline void update_field(MYSQL_BIND *param, db_fld_t* fld) |
486 | 486 |
#else |
487 | 487 |
if (fld->flags & DB_NULL) { |
488 | 488 |
switch(fld->type) { |
489 |
+ case DB_STR: |
|
490 |
+ case DB_CSTR: |
|
491 |
+ param->buffer = FAKE_NULL_STR.s; |
|
492 |
+ fp->length = FAKE_NULL_STR.len; |
|
493 |
+ break; |
|
494 |
+ case DB_INT: |
|
495 |
+ *(int*)param->buffer = FAKE_NULL_INT; |
|
496 |
+ break; |
|
497 |
+ case DB_BLOB: |
|
498 |
+ case DB_DATETIME: |
|
499 |
+ case DB_NONE: |
|
500 |
+ case DB_FLOAT: |
|
501 |
+ case DB_DOUBLE: |
|
502 |
+ case DB_BITMAP: |
|
503 |
+ /* we don't have fake null value for these types */ |
|
504 |
+ fp->is_null = DB_NULL; |
|
505 |
+ break; |
|
506 |
+ } |
|
507 |
+ return; |
|
508 |
+ } |
|
509 |
+#endif |
|
510 |
+ switch(fld->type) { |
|
489 | 511 |
case DB_STR: |
490 |
- case DB_CSTR: |
|
491 |
- param->buffer = FAKE_NULL_STR.s; |
|
492 |
- fp->length = FAKE_NULL_STR.len; |
|
493 |
- break; |
|
494 |
- case DB_INT: |
|
495 |
- *(int*)param->buffer = FAKE_NULL_INT; |
|
512 |
+ param->buffer = fld->v.lstr.s; |
|
513 |
+ fp->length = fld->v.lstr.len; |
|
496 | 514 |
break; |
515 |
+ |
|
497 | 516 |
case DB_BLOB: |
517 |
+ param->buffer = fld->v.blob.s; |
|
518 |
+ fp->length = fld->v.blob.len; |
|
519 |
+ break; |
|
520 |
+ |
|
521 |
+ case DB_CSTR: |
|
522 |
+ param->buffer = (char*)fld->v.cstr; |
|
523 |
+ fp->length = strlen(fld->v.cstr); |
|
524 |
+ break; |
|
525 |
+ |
|
498 | 526 |
case DB_DATETIME: |
527 |
+ t = gmtime(&fld->v.time); |
|
528 |
+ fp->time.second = t->tm_sec; |
|
529 |
+ fp->time.minute = t->tm_min; |
|
530 |
+ fp->time.hour = t->tm_hour; |
|
531 |
+ fp->time.day = t->tm_mday; |
|
532 |
+ fp->time.month = t->tm_mon + 1; |
|
533 |
+ fp->time.year = t->tm_year + 1900; |
|
534 |
+ break; |
|
535 |
+ |
|
499 | 536 |
case DB_NONE: |
537 |
+ case DB_INT: |
|
500 | 538 |
case DB_FLOAT: |
501 | 539 |
case DB_DOUBLE: |
502 | 540 |
case DB_BITMAP: |
503 |
- /* we don't have fake null value for these types */ |
|
504 |
- fp->is_null = DB_NULL; |
|
541 |
+ /* No need to do anything for these types */ |
|
505 | 542 |
break; |
506 |
- } |
|
507 |
- return; |
|
508 |
- } |
|
509 |
-#endif |
|
510 |
- switch(fld->type) { |
|
511 |
- case DB_STR: |
|
512 |
- param->buffer = fld->v.lstr.s; |
|
513 |
- fp->length = fld->v.lstr.len; |
|
514 |
- break; |
|
515 |
- |
|
516 |
- case DB_BLOB: |
|
517 |
- param->buffer = fld->v.blob.s; |
|
518 |
- fp->length = fld->v.blob.len; |
|
519 |
- break; |
|
520 |
- |
|
521 |
- case DB_CSTR: |
|
522 |
- param->buffer = (char*)fld->v.cstr; |
|
523 |
- fp->length = strlen(fld->v.cstr); |
|
524 |
- break; |
|
525 |
- |
|
526 |
- case DB_DATETIME: |
|
527 |
- t = gmtime(&fld->v.time); |
|
528 |
- fp->time.second = t->tm_sec; |
|
529 |
- fp->time.minute = t->tm_min; |
|
530 |
- fp->time.hour = t->tm_hour; |
|
531 |
- fp->time.day = t->tm_mday; |
|
532 |
- fp->time.month = t->tm_mon + 1; |
|
533 |
- fp->time.year = t->tm_year + 1900; |
|
534 |
- break; |
|
535 |
- |
|
536 |
- case DB_NONE: |
|
537 |
- case DB_INT: |
|
538 |
- case DB_FLOAT: |
|
539 |
- case DB_DOUBLE: |
|
540 |
- case DB_BITMAP: |
|
541 |
- /* No need to do anything for these types */ |
|
542 |
- break; |
|
543 | 543 |
|
544 | 544 |
} |
545 | 545 |
} |
... | ... |
@@ -594,73 +594,73 @@ static inline int update_result(db_fld_t* result, MYSQL_STMT* st) |
594 | 594 |
} |
595 | 595 |
|
596 | 596 |
switch(result[i].type) { |
597 |
- case DB_STR: |
|
598 |
- result[i].v.lstr.len = rp->length; |
|
597 |
+ case DB_STR: |
|
598 |
+ result[i].v.lstr.len = rp->length; |
|
599 | 599 |
#ifdef MYSQL_FAKE_NULL |
600 |
- if (STR_EQ(FAKE_NULL_STR,result[i].v.lstr)) { |
|
601 |
- result[i].flags |= DB_NULL; |
|
602 |
- } |
|
600 |
+ if (STR_EQ(FAKE_NULL_STR,result[i].v.lstr)) { |
|
601 |
+ result[i].flags |= DB_NULL; |
|
602 |
+ } |
|
603 | 603 |
#endif |
604 |
- break; |
|
605 |
- |
|
606 |
- case DB_BLOB: |
|
607 |
- result[i].v.blob.len = rp->length; |
|
608 |
- break; |
|
609 |
- |
|
610 |
- case DB_CSTR: |
|
611 |
- if (rp->length < STR_BUF_SIZE) { |
|
612 |
- result[i].v.cstr[rp->length] = '\0'; |
|
613 |
- } else { |
|
614 |
- /* Truncated field but rp->length contains full size, |
|
615 |
- * zero terminated the last byte in the buffer |
|
616 |
- */ |
|
617 |
- result[i].v.cstr[STR_BUF_SIZE - 1] = '\0'; |
|
618 |
- } |
|
604 |
+ break; |
|
605 |
+ |
|
606 |
+ case DB_BLOB: |
|
607 |
+ result[i].v.blob.len = rp->length; |
|
608 |
+ break; |
|
609 |
+ |
|
610 |
+ case DB_CSTR: |
|
611 |
+ if (rp->length < STR_BUF_SIZE) { |
|
612 |
+ result[i].v.cstr[rp->length] = '\0'; |
|
613 |
+ } else { |
|
614 |
+ /* Truncated field but rp->length contains full size, |
|
615 |
+ * zero terminated the last byte in the buffer |
|
616 |
+ */ |
|
617 |
+ result[i].v.cstr[STR_BUF_SIZE - 1] = '\0'; |
|
618 |
+ } |
|
619 | 619 |
#ifdef MYSQL_FAKE_NULL |
620 |
- if (strcmp(FAKE_NULL_STR.s,result[i].v.cstr)==0) { |
|
621 |
- result[i].flags |= DB_NULL; |
|
622 |
- } |
|
620 |
+ if (strcmp(FAKE_NULL_STR.s,result[i].v.cstr)==0) { |
|
621 |
+ result[i].flags |= DB_NULL; |
|
622 |
+ } |
|
623 | 623 |
#endif |
624 |
- break; |
|
625 |
- |
|
626 |
- case DB_DATETIME: |
|
627 |
- memset(&t, '\0', sizeof(struct tm)); |
|
628 |
- t.tm_sec = rp->time.second; |
|
629 |
- t.tm_min = rp->time.minute; |
|
630 |
- t.tm_hour = rp->time.hour; |
|
631 |
- t.tm_mday = rp->time.day; |
|
632 |
- t.tm_mon = rp->time.month - 1; |
|
633 |
- t.tm_year = rp->time.year - 1900; |
|
634 |
- |
|
635 |
- /* Daylight saving information got lost in the database |
|
636 |
- * so let timegm to guess it. This eliminates the bug when |
|
637 |
- * contacts reloaded from the database have different time |
|
638 |
- * of expiration by one hour when daylight saving is used |
|
639 |
- */ |
|
640 |
- t.tm_isdst = -1; |
|
624 |
+ break; |
|
625 |
+ |
|
626 |
+ case DB_DATETIME: |
|
627 |
+ memset(&t, '\0', sizeof(struct tm)); |
|
628 |
+ t.tm_sec = rp->time.second; |
|
629 |
+ t.tm_min = rp->time.minute; |
|
630 |
+ t.tm_hour = rp->time.hour; |
|
631 |
+ t.tm_mday = rp->time.day; |
|
632 |
+ t.tm_mon = rp->time.month - 1; |
|
633 |
+ t.tm_year = rp->time.year - 1900; |
|
634 |
+ |
|
635 |
+ /* Daylight saving information got lost in the database |
|
636 |
+ * so let timegm to guess it. This eliminates the bug when |
|
637 |
+ * contacts reloaded from the database have different time |
|
638 |
+ * of expiration by one hour when daylight saving is used |
|
639 |
+ */ |
|
640 |
+ t.tm_isdst = -1; |
|
641 | 641 |
#ifdef HAVE_TIMEGM |
642 |
- result[i].v.time = timegm(&t); |
|
642 |
+ result[i].v.time = timegm(&t); |
|
643 | 643 |
#else |
644 |
- result[i].v.time = _timegm(&t); |
|
644 |
+ result[i].v.time = _timegm(&t); |
|
645 | 645 |
#endif /* HAVE_TIMEGM */ |
646 |
- break; |
|
646 |
+ break; |
|
647 | 647 |
|
648 |
- case DB_INT: |
|
648 |
+ case DB_INT: |
|
649 | 649 |
#ifdef MYSQL_FAKE_NULL |
650 |
- if (FAKE_NULL_INT==result[i].v.int4) { |
|
651 |
- result[i].flags |= DB_NULL; |
|
652 |
- } |
|
653 |
- break; |
|
650 |
+ if (FAKE_NULL_INT==result[i].v.int4) { |
|
651 |
+ result[i].flags |= DB_NULL; |
|
652 |
+ } |
|
653 |
+ break; |
|
654 | 654 |
#endif |
655 |
- case DB_NONE: |
|
656 |
- case DB_FLOAT: |
|
657 |
- case DB_DOUBLE: |
|
658 |
- case DB_BITMAP: |
|
659 |
- /* No need to do anything for these types */ |
|
660 |
- break; |
|
655 |
+ case DB_NONE: |
|
656 |
+ case DB_FLOAT: |
|
657 |
+ case DB_DOUBLE: |
|
658 |
+ case DB_BITMAP: |
|
659 |
+ /* No need to do anything for these types */ |
|
660 |
+ break; |
|
661 | 661 |
} |
662 | 662 |
} |
663 |
- |
|
663 |
+ |
|
664 | 664 |
return 0; |
665 | 665 |
} |
666 | 666 |
|
... | ... |
@@ -674,79 +674,79 @@ static inline int update_result(db_fld_t* result, MYSQL_STMT* st) |
674 | 674 |
*/ |
675 | 675 |
static int exec_cmd_safe(db_cmd_t* cmd) |
676 | 676 |
{ |
677 |
- int i, err; |
|
678 |
- db_con_t* con; |
|
679 |
- struct my_cmd* mcmd; |
|
680 |
- struct my_con* mcon; |
|
681 |
- |
|
682 |
- /* First things first: retrieve connection info |
|
683 |
- * from the currently active connection and also |
|
684 |
- * mysql payload from the database command |
|
685 |
- */ |
|
686 |
- mcmd = DB_GET_PAYLOAD(cmd); |
|
687 |
- con = cmd->ctx->con[db_payload_idx]; |
|
688 |
- mcon = DB_GET_PAYLOAD(con); |
|
689 |
- |
|
690 |
- for(i = 0; i <= my_retries; i++) { |
|
691 |
- if ((mcon->flags & MY_CONNECTED) == 0) { |
|
692 |
- /* The connection is disconnected, try to reconnect */ |
|
693 |
- if (my_con_connect(con)) { |
|
694 |
- INFO("mysql: exec_cmd_safe failed to re-connect\n"); |
|
695 |
- continue; |
|
696 |
- } |
|
697 |
- } |
|
698 |
- |
|
699 |
- /* Next check the number of resets in the database connection, if this |
|
700 |
- * number is higher than the number we keep in my_cmd structure in |
|
701 |
- * last_reset variable then the connection was reset and we need to |
|
702 |
- * upload the command again to the server before executing it, because |
|
703 |
- * the server recycles all server side information upon disconnect. |
|
677 |
+ int i, err; |
|
678 |
+ db_con_t* con; |
|
679 |
+ struct my_cmd* mcmd; |
|
680 |
+ struct my_con* mcon; |
|
681 |
+ |
|
682 |
+ /* First things first: retrieve connection info |
|
683 |
+ * from the currently active connection and also |
|
684 |
+ * mysql payload from the database command |
|
704 | 685 |
*/ |
705 |
- if (mcon->resets > mcmd->last_reset) { |
|
706 |
- INFO("mysql: Connection reset detected, uploading command to server\n"); |
|
707 |
- err = upload_cmd(cmd); |
|
708 |
- if (err < 0) { |
|
709 |
- INFO("mysql: Error while uploading command\n"); |
|
710 |
- continue; |
|
711 |
- } else if (err > 0) { |
|
712 |
- /* DB API error, this is a serious problem such as memory |
|
713 |
- * allocation failure, bail out |
|
686 |
+ mcmd = DB_GET_PAYLOAD(cmd); |
|
687 |
+ con = cmd->ctx->con[db_payload_idx]; |
|
688 |
+ mcon = DB_GET_PAYLOAD(con); |
|
689 |
+ |
|
690 |
+ for(i = 0; i <= my_retries; i++) { |
|
691 |
+ if ((mcon->flags & MY_CONNECTED) == 0) { |
|
692 |
+ /* The connection is disconnected, try to reconnect */ |
|
693 |
+ if (my_con_connect(con)) { |
|
694 |
+ INFO("mysql: exec_cmd_safe failed to re-connect\n"); |
|
695 |
+ continue; |
|
696 |
+ } |
|
697 |
+ } |
|
698 |
+ |
|
699 |
+ /* Next check the number of resets in the database connection, if this |
|
700 |
+ * number is higher than the number we keep in my_cmd structure in |
|
701 |
+ * last_reset variable then the connection was reset and we need to |
|
702 |
+ * upload the command again to the server before executing it, because |
|
703 |
+ * the server recycles all server side information upon disconnect. |
|
714 | 704 |
*/ |
715 |
- return 1; |
|
716 |
- } |
|
717 |
- } |
|
718 |
- |
|
719 |
- set_mysql_params(cmd); |
|
720 |
- err = mysql_stmt_execute(mcmd->st); |
|
721 |
- if (err == 0) { |
|
722 |
- /* The command was executed successfully, now fetch all data to |
|
723 |
- * the client if it was requested by the user */ |
|
724 |
- if (mcmd->flags & MY_FETCH_ALL) { |
|
725 |
- err = mysql_stmt_store_result(mcmd->st); |
|
726 |
- if (err) { |
|
727 |
- INFO("mysql: Error while fetching data to client.\n"); |
|
728 |
- goto error; |
|
705 |
+ if (mcon->resets > mcmd->last_reset) { |
|
706 |
+ INFO("mysql: Connection reset detected, uploading command to server\n"); |
|
707 |
+ err = upload_cmd(cmd); |
|
708 |
+ if (err < 0) { |
|
709 |
+ INFO("mysql: Error while uploading command\n"); |
|
710 |
+ continue; |
|
711 |
+ } else if (err > 0) { |
|
712 |
+ /* DB API error, this is a serious problem such as memory |
|
713 |
+ * allocation failure, bail out |
|
714 |
+ */ |
|
715 |
+ return 1; |
|
716 |
+ } |
|
717 |
+ } |
|
718 |
+ |
|
719 |
+ set_mysql_params(cmd); |
|
720 |
+ err = mysql_stmt_execute(mcmd->st); |
|
721 |
+ if (err == 0) { |
|
722 |
+ /* The command was executed successfully, now fetch all data to |
|
723 |
+ * the client if it was requested by the user */ |
|
724 |
+ if (mcmd->flags & MY_FETCH_ALL) { |
|
725 |
+ err = mysql_stmt_store_result(mcmd->st); |
|
726 |
+ if (err) { |
|
727 |
+ INFO("mysql: Error while fetching data to client.\n"); |
|
728 |
+ goto error; |
|
729 |
+ } |
|
730 |
+ } |
|
731 |
+ return 0; |
|
732 |
+ } |
|
733 |
+ |
|
734 |
+error: |
|
735 |
+ /* Command execution failed, log a message and try to reconnect */ |
|
736 |
+ INFO("mysql: libmysql: %d, %s\n", mysql_stmt_errno(mcmd->st), |
|
737 |
+ mysql_stmt_error(mcmd->st)); |
|
738 |
+ INFO("mysql: Error while executing command on server, trying to reconnect\n"); |
|
739 |
+ |
|
740 |
+ my_con_disconnect(con); |
|
741 |
+ if (my_con_connect(con)) { |
|
742 |
+ INFO("mysql: Failed to reconnect server\n"); |
|
743 |
+ } else { |
|
744 |
+ INFO("mysql: Successfully reconnected server\n"); |
|
729 | 745 |
} |
730 |
- } |
|
731 |
- return 0; |
|
732 |
- } |
|
733 |
- |
|
734 |
- error: |
|
735 |
- /* Command execution failed, log a message and try to reconnect */ |
|
736 |
- INFO("mysql: libmysql: %d, %s\n", mysql_stmt_errno(mcmd->st), |
|
737 |
- mysql_stmt_error(mcmd->st)); |
|
738 |
- INFO("mysql: Error while executing command on server, trying to reconnect\n"); |
|
739 |
- |
|
740 |
- my_con_disconnect(con); |
|
741 |
- if (my_con_connect(con)) { |
|
742 |
- INFO("mysql: Failed to reconnect server\n"); |
|
743 |
- } else { |
|
744 |
- INFO("mysql: Successfully reconnected server\n"); |
|
745 | 746 |
} |
746 |
- } |
|
747 |
- |
|
748 |
- INFO("mysql: Failed to execute command, giving up\n"); |
|
749 |
- return -1; |
|
747 |
+ |
|
748 |
+ INFO("mysql: Failed to execute command, giving up\n"); |
|
749 |
+ return -1; |
|
750 | 750 |
} |
751 | 751 |
|
752 | 752 |
|
... | ... |
@@ -769,7 +769,7 @@ int my_cmd_exec(db_res_t* res, db_cmd_t* cmd) |
769 | 769 |
static void set_field(MYSQL_BIND *bind, db_fld_t* fld) |
770 | 770 |
{ |
771 | 771 |
struct my_fld* f; |
772 |
- |
|
772 |
+ |
|
773 | 773 |
f = DB_GET_PAYLOAD(fld); |
774 | 774 |
bind->is_null = &f->is_null; |
775 | 775 |
/* We can do it for all the types here, mysql will ignore it |
... | ... |
@@ -777,42 +777,42 @@ static void set_field(MYSQL_BIND *bind, db_fld_t* fld) |
777 | 777 |
*/ |
778 | 778 |
bind->length = &f->length; |
779 | 779 |
switch(fld->type) { |
780 |
- case DB_INT: |
|
781 |
- case DB_BITMAP: |
|
782 |
- bind->buffer_type = MYSQL_TYPE_LONG; |
|
783 |
- bind->buffer = &fld->v.int4; |
|
784 |
- break; |
|
785 |
- |
|
786 |
- case DB_FLOAT: |
|
787 |
- bind->buffer_type = MYSQL_TYPE_FLOAT; |
|
788 |
- bind->buffer = &fld->v.flt; |
|
789 |
- break; |
|
790 |
- |
|
791 |
- case DB_DOUBLE: |
|
792 |
- bind->buffer_type = MYSQL_TYPE_DOUBLE; |
|
793 |
- bind->buffer = &fld->v.dbl; |
|
794 |
- break; |
|
795 |
- |
|
796 |
- case DB_DATETIME: |
|
797 |
- bind->buffer_type = MYSQL_TYPE_DATETIME; |
|
798 |
- bind->buffer = &f->time; |
|
799 |
- break; |
|
800 |
- |
|
801 |
- case DB_STR: |
|
802 |
- case DB_CSTR: |
|
803 |
- bind->buffer_type = MYSQL_TYPE_VAR_STRING; |
|
804 |
- bind->buffer = ""; /* Updated on runtime */ |
|
805 |
- break; |
|
806 |
- |
|
807 |
- case DB_BLOB: |
|
808 |
- bind->buffer_type = MYSQL_TYPE_BLOB; |
|
809 |
- bind->buffer = ""; /* Updated on runtime */ |
|
810 |
- break; |
|
811 |
- |
|
812 |
- case DB_NONE: |
|
813 |
- /* Eliminates gcc warning */ |
|
814 |
- break; |
|
815 |
- |
|
780 |
+ case DB_INT: |
|
781 |
+ case DB_BITMAP: |
|
782 |
+ bind->buffer_type = MYSQL_TYPE_LONG; |
|
783 |
+ bind->buffer = &fld->v.int4; |
|
784 |
+ break; |
|
785 |
+ |
|
786 |
+ case DB_FLOAT: |
|
787 |
+ bind->buffer_type = MYSQL_TYPE_FLOAT; |
|
788 |
+ bind->buffer = &fld->v.flt; |
|
789 |
+ break; |
|
790 |
+ |
|
791 |
+ case DB_DOUBLE: |
|
792 |
+ bind->buffer_type = MYSQL_TYPE_DOUBLE; |
|
793 |
+ bind->buffer = &fld->v.dbl; |
|
794 |
+ break; |
|
795 |
+ |
|
796 |
+ case DB_DATETIME: |
|
797 |
+ bind->buffer_type = MYSQL_TYPE_DATETIME; |
|
798 |
+ bind->buffer = &f->time; |
|
799 |
+ break; |
|
800 |
+ |
|
801 |
+ case DB_STR: |
|
802 |
+ case DB_CSTR: |
|
803 |
+ bind->buffer_type = MYSQL_TYPE_VAR_STRING; |
|
804 |
+ bind->buffer = ""; /* Updated on runtime */ |
|
805 |
+ break; |
|
806 |
+ |
|
807 |
+ case DB_BLOB: |
|
808 |
+ bind->buffer_type = MYSQL_TYPE_BLOB; |
|
809 |
+ bind->buffer = ""; /* Updated on runtime */ |
|
810 |
+ break; |
|
811 |
+ |
|
812 |
+ case DB_NONE: |
|
813 |
+ /* Eliminates gcc warning */ |
|
814 |
+ break; |
|
815 |
+ |
|
816 | 816 |
} |
817 | 817 |
} |
818 | 818 |
|
... | ... |
@@ -843,7 +843,7 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params |
843 | 843 |
BUG("mysql: Number of parameters in SQL command does not match number of DB API parameters\n"); |
844 | 844 |
return 1; |
845 | 845 |
} |
846 |
- |
|
846 |
+ |
|
847 | 847 |
my_params = (MYSQL_BIND*)pkg_malloc(sizeof(MYSQL_BIND) * (count1 + count2)); |
848 | 848 |
if (my_params == NULL) { |
849 | 849 |
ERR("mysql: No memory left\n"); |
... | ... |
@@ -863,8 +863,8 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params |
863 | 863 |
|
864 | 864 |
err = mysql_stmt_bind_param(st, my_params); |
865 | 865 |
if (err) { |
866 |
- ERR("mysql: libmysqlclient: %d, %s\n", |
|
867 |
- mysql_stmt_errno(st), mysql_stmt_error(st)); |
|
866 |
+ ERR("mysql: libmysqlclient: %d, %s\n", |
|
867 |
+ mysql_stmt_errno(st), mysql_stmt_error(st)); |
|
868 | 868 |
goto error; |
869 | 869 |
} |
870 | 870 |
|
... | ... |
@@ -873,8 +873,8 @@ static int bind_mysql_params(MYSQL_STMT* st, db_fld_t* params1, db_fld_t* params |
873 | 873 |
*/ |
874 | 874 |
pkg_free(my_params); |
875 | 875 |
return err; |
876 |
- |
|
877 |
- error: |
|
876 |
+ |
|
877 |
+error: |
|
878 | 878 |
if (my_params) pkg_free(my_params); |
879 | 879 |
return err; |
880 | 880 |
} |
... | ... |
@@ -896,7 +896,7 @@ static int check_result(db_cmd_t* cmd, struct my_cmd* payload) |
896 | 896 |
/* No error means no result set to be checked */ |
897 | 897 |
if (mysql_stmt_errno(payload->st) == 0) return 0; |
898 | 898 |
ERR("mysql: Error while getting metadata of SQL command: %d, %s\n", |
899 |
- mysql_stmt_errno(payload->st), mysql_stmt_error(payload->st)); |
|
899 |
+ mysql_stmt_errno(payload->st), mysql_stmt_error(payload->st)); |
|
900 | 900 |
return -1; |
901 | 901 |
} |
902 | 902 |
n = mysql_num_fields(meta); |
... | ... |
@@ -930,44 +930,44 @@ static int check_result(db_cmd_t* cmd, struct my_cmd* payload) |
930 | 930 |
/* Now iterate through all the columns in the result set and replace |
931 | 931 |
* any occurrence of DB_UNKNOWN type with the type of the column |
932 | 932 |
* retrieved from the database and if no column name was provided then |
933 |
- * update it from the database as well. |
|
933 |
+ * update it from the database as well. |
|
934 | 934 |
*/ |
935 | 935 |
for(i = 0; i < cmd->result_count; i++) { |
936 | 936 |
fld = mysql_fetch_field_direct(meta, i); |
937 | 937 |
if (cmd->result[i].type != DB_NONE) continue; |
938 | 938 |
switch(fld->type) { |
939 |
- case MYSQL_TYPE_TINY: |
|
940 |
- case MYSQL_TYPE_SHORT: |
|
941 |
- case MYSQL_TYPE_INT24: |
|
942 |
- case MYSQL_TYPE_LONG: |
|
943 |
- cmd->result[i].type = DB_INT; |
|
944 |
- break; |
|
945 |
- |
|
946 |
- case MYSQL_TYPE_FLOAT: |
|
947 |
- cmd->result[i].type = DB_FLOAT; |
|
948 |
- break; |
|
949 |
- |
|
950 |
- case MYSQL_TYPE_DOUBLE: |
|
951 |
- cmd->result[i].type = DB_DOUBLE; |
|
952 |
- break; |
|
953 |
- |
|
954 |
- case MYSQL_TYPE_TIMESTAMP: |
|
955 |
- case MYSQL_TYPE_DATETIME: |
|
956 |
- cmd->result[i].type = DB_DATETIME; |
|
957 |
- break; |
|
958 |
- |
|
959 |
- case MYSQL_TYPE_STRING: |
|
960 |
- case MYSQL_TYPE_VAR_STRING: |
|
961 |
- cmd->result[i].type = DB_STR; |
|
962 |
- break; |
|
939 |
+ case MYSQL_TYPE_TINY: |
|
940 |
+ case MYSQL_TYPE_SHORT: |
|
941 |
+ case MYSQL_TYPE_INT24: |
|
942 |
+ case MYSQL_TYPE_LONG: |
|
943 |
+ cmd->result[i].type = DB_INT; |
|
944 |
+ break; |
|
945 |
+ |
|
946 |
+ case MYSQL_TYPE_FLOAT: |
|
947 |
+ cmd->result[i].type = DB_FLOAT; |
|
948 |
+ break; |
|
949 |
+ |
|
950 |
+ case MYSQL_TYPE_DOUBLE: |
|
951 |
+ cmd->result[i].type = DB_DOUBLE; |
|
952 |
+ break; |
|
953 |
+ |
|
954 |
+ case MYSQL_TYPE_TIMESTAMP: |
|
955 |
+ case MYSQL_TYPE_DATETIME: |
|
956 |
+ cmd->result[i].type = DB_DATETIME; |
|
957 |
+ break; |
|
958 |
+ |
|
959 |
+ case MYSQL_TYPE_STRING: |
|
960 |
+ case MYSQL_TYPE_VAR_STRING: |
|
961 |
+ cmd->result[i].type = DB_STR; |
|
962 |
+ break; |
|
963 | 963 |
|
964 |
- default: |
|
965 |
- ERR("mysql: Unsupported MySQL column type: %d, table: %s, column: %s\n", |
|
966 |
- fld->type, cmd->table.s, fld->name); |
|
967 |
- goto error; |
|
964 |
+ default: |
|
965 |
+ ERR("mysql: Unsupported MySQL column type: %d, table: %s, column: %s\n", |
|
966 |
+ fld->type, cmd->table.s, fld->name); |
|
967 |
+ goto error; |
|
968 | 968 |
} |
969 | 969 |
} |
970 |
- |
|
970 |
+ |
|
971 | 971 |
if (meta) mysql_free_result(meta); |
972 | 972 |
return 0; |
973 | 973 |
|
... | ... |
@@ -998,7 +998,7 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) |
998 | 998 |
return 1; |
999 | 999 |
} |
1000 | 1000 |
memset(result, '\0', sizeof(MYSQL_BIND) * n); |
1001 |
- |
|
1001 |
+ |
|
1002 | 1002 |
for(i = 0; i < n; i++) { |
1003 | 1003 |
f = DB_GET_PAYLOAD(fld + i); |
1004 | 1004 |
result[i].is_null = &f->is_null; |
... | ... |
@@ -1007,69 +1007,69 @@ static int bind_result(MYSQL_STMT* st, db_fld_t* fld) |
1007 | 1007 |
*/ |
1008 | 1008 |
result[i].length = &f->length; |
1009 | 1009 |
switch(fld[i].type) { |
1010 |
- case DB_INT: |
|
1011 |
- case DB_BITMAP: |
|
1012 |
- result[i].buffer_type = MYSQL_TYPE_LONG; |
|
1013 |
- result[i].buffer = &fld[i].v.int4; |
|
1014 |
- break; |
|
1015 |
- |
|
1016 |
- case DB_FLOAT: |
|
1017 |
- result[i].buffer_type = MYSQL_TYPE_FLOAT; |
|
1018 |
- result[i].buffer = &fld[i].v.flt; |
|
1019 |
- break; |
|
1020 |
- |
|
1021 |
- case DB_DOUBLE: |
|
1022 |
- result[i].buffer_type = MYSQL_TYPE_DOUBLE; |
|
1023 |
- result[i].buffer = &fld[i].v.dbl; |
|
1024 |
- break; |
|
1025 |
- |
|
1026 |
- case DB_DATETIME: |
|
1027 |
- result[i].buffer_type = MYSQL_TYPE_DATETIME; |
|
1028 |
- result[i].buffer = &f->time; |
|
1029 |
- break; |
|
1030 |
- |
|
1031 |
- case DB_STR: |
|
1032 |
- result[i].buffer_type = MYSQL_TYPE_VAR_STRING; |
|
1033 |
- if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); |
|
1034 |
- if (f->buf.s == NULL) { |
|
1035 |
- ERR("mysql: No memory left\n"); |
|
1036 |
- err = 1; |
|
1037 |
- goto error; |
|
1038 |
- } |
|
1039 |
- result[i].buffer = f->buf.s; |
|
1040 |
- fld[i].v.lstr.s = f->buf.s; |
|
1041 |
- result[i].buffer_length = STR_BUF_SIZE - 1; |
|
1042 |
- break; |
|
1043 |
- |
|
1044 |
- case DB_CSTR: |
|
1045 |
- result[i].buffer_type = MYSQL_TYPE_VAR_STRING; |
|
1046 |
- if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); |
|
1047 |
- if (f->buf.s == NULL) { |
|
1048 |
- ERR("mysql: No memory left\n"); |
|
1049 |
- err = 1; |
|
1050 |
- goto error; |
|
1051 |
- } |
|
1052 |
- result[i].buffer = f->buf.s; |
|
1053 |
- fld[i].v.cstr = f->buf.s; |
|
1054 |
- result[i].buffer_length = STR_BUF_SIZE - 1; |
|
1055 |
- break; |
|
1056 |
- |
|
1057 |
- case DB_BLOB: |
|
1058 |
- result[i].buffer_type = MYSQL_TYPE_BLOB; |
|
1059 |
- if (!f->buf.s) f->buf.s = pkg_malloc(STR_BUF_SIZE); |
|
1060 |
- if (f->buf.s == NULL) { |
|
1061 |
- ERR("mysql: No memory left\n"); |
|
1062 |
- err = 1; |
|
1063 |
- goto error; |
|
1064 |
- } |
|
1065 |
- result[i].buffer = f->buf.s; |
|
1066 |
- fld[i].v.blob.s = f->buf.s; |
|
1067 |
- result[i].buffer_length = STR_BUF_SIZE - 1; |
|
1068 |
- break; |
|
1069 |
- |
|
1070 |
- case DB_NONE: |
|
1071 |
- /* Eliminates gcc warning */ |
|
1072 |