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; |
92 |
92 double *num = NULL; |
93 double num; |
|
94 |
93 |
95 switch(type) { |
94 switch(type) { |
96 case LUA_TNIL: |
95 case LUA_TNIL: |
97 bind[i].buffer_type = MYSQL_TYPE_NULL; |
96 bind[i].buffer_type = MYSQL_TYPE_NULL; |
98 bind[i].is_null = (my_bool*)1; |
97 bind[i].is_null = (my_bool*)1; |
99 break; |
98 break; |
100 |
99 |
101 case LUA_TNUMBER: |
100 case LUA_TNUMBER: |
102 num = luaL_checknumber(L, p); |
101 /* |
|
102 * num needs to be it's own |
|
103 * memory here |
|
104 */ |
|
105 num = (double *)malloc(sizeof(double)); |
|
106 *num = luaL_checknumber(L, p); |
103 |
107 |
104 bind[i].buffer_type = MYSQL_TYPE_DOUBLE; |
108 bind[i].buffer_type = MYSQL_TYPE_DOUBLE; |
105 bind[i].is_null = (my_bool*)0; |
109 bind[i].is_null = (my_bool*)0; |
106 bind[i].buffer = (char *)# |
110 bind[i].buffer = (char *)num; |
107 bind[i].length = 0; |
111 bind[i].length = 0; |
108 break; |
112 break; |
109 |
113 |
110 case LUA_TSTRING: |
114 case LUA_TSTRING: |
111 str = luaL_checklstring(L, p, &str_len); |
115 str = luaL_checklstring(L, p, &str_len); |
133 } |
137 } |
134 |
138 |
135 metadata = mysql_stmt_result_metadata(statement->stmt); |
139 metadata = mysql_stmt_result_metadata(statement->stmt); |
136 |
140 |
137 cleanup: |
141 cleanup: |
138 if (bind) |
142 if (bind) { |
|
143 int i; |
|
144 |
|
145 for (i = 0; i < num_bind_params; i++) { |
|
146 /* |
|
147 * Free the memory associated with |
|
148 * the allocation of double bind |
|
149 * params. If the interface is |
|
150 * extended with other types they |
|
151 * will need to be added here |
|
152 */ |
|
153 if (bind[i].buffer_type == MYSQL_TYPE_DOUBLE && bind[i].buffer) { |
|
154 free(bind[i].buffer); |
|
155 } |
|
156 } |
|
157 |
139 free(bind); |
158 free(bind); |
|
159 } |
140 |
160 |
141 if (error_message) { |
161 if (error_message) { |
142 lua_pushboolean(L, 0); |
162 lua_pushboolean(L, 0); |
143 lua_pushfstring(L, error_message, mysql_stmt_error(statement->stmt)); |
163 lua_pushfstring(L, error_message, mysql_stmt_error(statement->stmt)); |
144 return 2; |
164 return 2; |