Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 #include "db_row.h"
00034
00035 #include <string.h>
00036 #include "../../dprint.h"
00037 #include "../../mem/mem.h"
00038
00039
00040
00041
00042 inline int db_free_row(db_row_t* _r)
00043 {
00044 int col;
00045 db_val_t* _val;
00046
00047 if (!_r) {
00048 LM_ERR("invalid parameter value\n");
00049 return -1;
00050 }
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 for (col = 0; col < ROW_N(_r); col++) {
00062 _val = &(ROW_VALUES(_r)[col]);
00063 switch (VAL_TYPE(_val)) {
00064 case DB1_STRING:
00065 if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
00066 LM_DBG("free VAL_STRING[%d] '%s' at %p\n", col,
00067 (char *)VAL_STRING(_val),
00068 (char *)VAL_STRING(_val));
00069 pkg_free((char *)VAL_STRING(_val));
00070 VAL_STRING(_val) = NULL;
00071 }
00072 break;
00073 case DB1_STR:
00074 if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
00075 LM_DBG("free VAL_STR[%d] '%.*s' at %p\n", col,
00076 VAL_STR(_val).len,
00077 VAL_STR(_val).s, VAL_STR(_val).s);
00078 pkg_free(VAL_STR(_val).s);
00079 VAL_STR(_val).s = NULL;
00080 }
00081 break;
00082 case DB1_BLOB:
00083 if ( (!VAL_NULL(_val)) && VAL_FREE(_val)) {
00084 LM_DBG("free VAL_BLOB[%d] at %p\n", col, VAL_BLOB(_val).s);
00085 pkg_free(VAL_BLOB(_val).s);
00086 VAL_BLOB(_val).s = NULL;
00087 }
00088 break;
00089 default:
00090 break;
00091 }
00092 }
00093
00094 ROW_N(_r) = 0;
00095
00096 if (ROW_VALUES(_r)) {
00097 LM_DBG("freeing row values at %p\n", ROW_VALUES(_r));
00098 pkg_free(ROW_VALUES(_r));
00099 ROW_VALUES(_r) = NULL;
00100 }
00101 return 0;
00102 }
00103
00104
00111 inline int db_allocate_row(const db1_res_t* _res, db_row_t* _row)
00112 {
00113 int len = sizeof(db_val_t) * RES_COL_N(_res);
00114 ROW_VALUES(_row) = (db_val_t*)pkg_malloc(len);
00115 if (!ROW_VALUES(_row)) {
00116 LM_ERR("no private memory left\n");
00117 return -1;
00118 }
00119 LM_DBG("allocate %d bytes for row values at %p\n", len, ROW_VALUES(_row));
00120
00121 memset(ROW_VALUES(_row), 0, len);
00122
00123 ROW_N(_row) = RES_COL_N(_res);
00124
00125 return 0;
00126 }