86 for (p = 2; p <= n; p++) { |
86 for (p = 2; p <= n; p++) { |
87 int type = lua_type(L, p); |
87 int type = lua_type(L, p); |
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; |
91 size_t *str_len = NULL; |
92 double *num = NULL; |
92 double *num = NULL; |
93 |
93 |
94 switch(type) { |
94 switch(type) { |
95 case LUA_TNIL: |
95 case LUA_TNIL: |
96 bind[i].buffer_type = MYSQL_TYPE_NULL; |
96 bind[i].buffer_type = MYSQL_TYPE_NULL; |
110 bind[i].buffer = (char *)num; |
110 bind[i].buffer = (char *)num; |
111 bind[i].length = 0; |
111 bind[i].length = 0; |
112 break; |
112 break; |
113 |
113 |
114 case LUA_TSTRING: |
114 case LUA_TSTRING: |
115 str = luaL_checklstring(L, p, &str_len); |
115 str_len = malloc(sizeof(size_t)); |
|
116 str = luaL_checklstring(L, p, str_len); |
116 |
117 |
117 bind[i].buffer_type = MYSQL_TYPE_STRING; |
118 bind[i].buffer_type = MYSQL_TYPE_STRING; |
118 bind[i].is_null = (my_bool*)0; |
119 bind[i].is_null = (my_bool*)0; |
119 bind[i].buffer = (char *)str; |
120 bind[i].buffer = (char *)str; |
120 bind[i].length = &str_len; |
121 bind[i].length = str_len; |
121 break; |
122 break; |
122 |
123 |
123 default: |
124 default: |
124 error_message = DBI_ERR_BINDING_UNKNOWN; |
125 error_message = DBI_ERR_BINDING_UNKNOWN; |
125 goto cleanup; |
126 goto cleanup; |
143 int i; |
144 int i; |
144 |
145 |
145 for (i = 0; i < num_bind_params; i++) { |
146 for (i = 0; i < num_bind_params; i++) { |
146 /* |
147 /* |
147 * Free the memory associated with |
148 * Free the memory associated with |
148 * the allocation of double bind |
149 * the allocation of double and string |
149 * params. If the interface is |
150 * bind params. If the interface are |
150 * extended with other types they |
151 * extended with other types they |
151 * will need to be added here |
152 * will need to be added here |
152 */ |
153 */ |
153 if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE && bind[i].buffer) { |
154 if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE) { |
154 free(bind[i].buffer); |
155 if (bind[i].buffer) |
|
156 free(bind[i].buffer); |
|
157 } else if (bind[i].buffer_type == MYSQL_TYPE_STRING) { |
|
158 if (bind[i].length) |
|
159 free(bind[i].length); |
155 } |
160 } |
156 } |
161 } |
157 |
162 |
158 free(bind); |
163 free(bind); |
159 } |
164 } |