dbd/mysql/statement.c

changeset 9
06eb2850703f
parent 7
4480ae002881
child 10
3aa8a37a3dd8
equal deleted inserted replaced
8:0b805fda1c91 9:06eb2850703f
88 int i = p - 2; 88 int i = p - 2;
89 89
90 const char *str = NULL; 90 const char *str = NULL;
91 size_t *str_len = NULL; 91 size_t *str_len = NULL;
92 double *num = NULL; 92 double *num = NULL;
93 int *boolean = NULL;
93 94
94 switch(type) { 95 switch(type) {
95 case LUA_TNIL: 96 case LUA_TNIL:
96 bind[i].buffer_type = MYSQL_TYPE_NULL; 97 bind[i].buffer_type = MYSQL_TYPE_NULL;
97 bind[i].is_null = (my_bool*)1; 98 bind[i].is_null = (my_bool*)1;
99 break;
100
101 case LUA_TBOOLEAN:
102 boolean = (int *)malloc(sizeof(int));
103 *boolean = lua_toboolean(L, p);
104 bind[i].buffer_type = MYSQL_TYPE_LONG;
105 bind[i].is_null = (my_bool*)0;
106 bind[i].buffer = (char *)boolean;
107 bind[i].length = 0;
98 break; 108 break;
99 109
100 case LUA_TNUMBER: 110 case LUA_TNUMBER:
101 /* 111 /*
102 * num needs to be it's own 112 * num needs to be it's own
103 * memory here 113 * memory here
104 */ 114 */
105 num = (double *)malloc(sizeof(double)); 115 num = (double *)malloc(sizeof(double));
106 *num = luaL_checknumber(L, p); 116 *num = lua_tonumber(L, p);
107 117
108 bind[i].buffer_type = MYSQL_TYPE_DOUBLE; 118 bind[i].buffer_type = MYSQL_TYPE_DOUBLE;
109 bind[i].is_null = (my_bool*)0; 119 bind[i].is_null = (my_bool*)0;
110 bind[i].buffer = (char *)num; 120 bind[i].buffer = (char *)num;
111 bind[i].length = 0; 121 bind[i].length = 0;
112 break; 122 break;
113 123
114 case LUA_TSTRING: 124 case LUA_TSTRING:
115 str_len = malloc(sizeof(size_t)); 125 str_len = malloc(sizeof(size_t));
116 str = luaL_checklstring(L, p, str_len); 126 str = lua_tolstring(L, p, str_len);
117 127
118 bind[i].buffer_type = MYSQL_TYPE_STRING; 128 bind[i].buffer_type = MYSQL_TYPE_STRING;
119 bind[i].is_null = (my_bool*)0; 129 bind[i].is_null = (my_bool*)0;
120 bind[i].buffer = (char *)str; 130 bind[i].buffer = (char *)str;
121 bind[i].length = str_len; 131 bind[i].length = str_len;
149 * the allocation of double and string 159 * the allocation of double and string
150 * bind params. If the interface are 160 * bind params. If the interface are
151 * extended with other types they 161 * extended with other types they
152 * will need to be added here 162 * will need to be added here
153 */ 163 */
154 if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE) { 164 if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE || bind[i].buffer_type == MYSQL_TYPE_LONG) {
155 if (bind[i].buffer) 165 if (bind[i].buffer)
156 free(bind[i].buffer); 166 free(bind[i].buffer);
157 } else if (bind[i].buffer_type == MYSQL_TYPE_STRING) { 167 } else if (bind[i].buffer_type == MYSQL_TYPE_STRING) {
158 if (bind[i].length) 168 if (bind[i].length)
159 free(bind[i].length); 169 free(bind[i].length);

mercurial