dbd/postgresql/statement.c

changeset 4
c50b0e6f25d6
parent 3
b61020ca4753
child 8
0b805fda1c91
equal deleted inserted replaced
3:b61020ca4753 4:c50b0e6f25d6
179 } 179 }
180 free(params); 180 free(params);
181 181
182 if (!result) { 182 if (!result) {
183 lua_pushboolean(L, 0); 183 lua_pushboolean(L, 0);
184 lua_pushstring(L, "Unable to allocate result handle"); 184 lua_pushfstring(L, DBI_ERR_ALLOC_RESULT, PQerrorMessage(statement->postgresql));
185 return 2; 185 return 2;
186 } 186 }
187 187
188 status = PQresultStatus(result); 188 status = PQresultStatus(result);
189 if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { 189 if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
190 lua_pushboolean(L, 0); 190 lua_pushboolean(L, 0);
191 lua_pushfstring(L, "Unable to execute statment: %s", PQresultErrorMessage(result)); 191 lua_pushfstring(L, DBI_ERR_BINDING_EXEC, PQresultErrorMessage(result));
192 return 2; 192 return 2;
193 } 193 }
194 194
195 statement->result = result; 195 statement->result = result;
196 196
207 int tuple = statement->tuple++; 207 int tuple = statement->tuple++;
208 int i; 208 int i;
209 int num_columns; 209 int num_columns;
210 210
211 if (!statement->result) { 211 if (!statement->result) {
212 luaL_error(L, "fetch called on a closed or invalid statement"); 212 luaL_error(L, DBI_ERR_FETCH_INVALID);
213 return 0; 213 return 0;
214 } 214 }
215 215
216 if (PQresultStatus(statement->result) != PGRES_TUPLES_OK) { 216 if (PQresultStatus(statement->result) != PGRES_TUPLES_OK) {
217 lua_pushnil(L); 217 lua_pushnil(L);
282 LUA_PUSH_ATTRIB_BOOL(name, val); 282 LUA_PUSH_ATTRIB_BOOL(name, val);
283 } else { 283 } else {
284 LUA_PUSH_ARRAY_BOOL(d, val); 284 LUA_PUSH_ARRAY_BOOL(d, val);
285 } 285 }
286 } else { 286 } else {
287 luaL_error(L, "Unknown push type in result set"); 287 luaL_error(L, DBI_ERR_UNKNOWN_PUSH);
288 } 288 }
289 } 289 }
290 } 290 }
291 291
292 return 1; 292 return 1;
337 */ 337 */
338 free(new_sql); 338 free(new_sql);
339 339
340 if (!result) { 340 if (!result) {
341 lua_pushnil(L); 341 lua_pushnil(L);
342 lua_pushstring(L, "Unable to allocate prepare result handle"); 342 lua_pushfstring(L, DBI_ERR_ALLOC_STATEMENT, PQerrorMessage(statement->postgresql));
343 return 2; 343 return 2;
344 } 344 }
345 345
346 status = PQresultStatus(result); 346 status = PQresultStatus(result);
347 if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { 347 if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) {
348 const char *err_string = PQresultErrorMessage(result); 348 const char *err_string = PQresultErrorMessage(result);
349 PQclear(result); 349 PQclear(result);
350 350
351 lua_pushnil(L); 351 lua_pushnil(L);
352 lua_pushfstring(L, "Unable to prepare statment: %s", err_string); 352 lua_pushfstring(L, DBI_ERR_PREP_STATEMENT, err_string);
353 return 2; 353 return 2;
354 } 354 }
355 355
356 PQclear(result); 356 PQclear(result);
357 357

mercurial