if (!(table = ast_calloc(1, sizeof(*table) + strlen(orig_tablename) + 1))) {
ast_log(LOG_ERROR, "Unable to allocate memory for new table structure\n");
+ PQclear(result);
AST_LIST_UNLOCK(&psql_tables);
return NULL;
}
if (!(column = ast_calloc(1, sizeof(*column) + strlen(fname) + strlen(ftype) + 2))) {
ast_log(LOG_ERROR, "Unable to allocate column element for %s, %s\n", orig_tablename, fname);
+ PQclear(result);
destroy_table(table);
AST_LIST_UNLOCK(&psql_tables);
return NULL;
ast_mutex_lock(&pgsql_lock);
if (pgsql_exec(database, tablename, ast_str_buffer(sql), &result) != 0) {
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
return NULL;
}
ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows);
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
- ast_mutex_unlock(&pgsql_lock);
PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
return NULL;
}
for (i = 0; i < numFields; i++)
ast_debug(1, "Postgresql RealTime: Could not find any rows in table %s@%s.\n", tablename, database);
}
- ast_mutex_unlock(&pgsql_lock);
PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
return var;
}
if (pgsql_exec(database, table, ast_str_buffer(sql), &result) != 0) {
ast_mutex_unlock(&pgsql_lock);
- return NULL;
- }
+ return NULL;
+ } else {
+ ExecStatusType result_status = PQresultStatus(result);
+ if (result_status != PGRES_COMMAND_OK
+ && result_status != PGRES_TUPLES_OK
+ && result_status != PGRES_NONFATAL_ERROR) {
+ ast_log(LOG_WARNING,
+ "PostgreSQL RealTime: Failed to query %s@%s. Check debug for more info.\n", table, database);
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
+ ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
+ PQresultErrorMessage(result), PQresStatus(result_status));
+ PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
+ return NULL;
+ }
+ }
ast_debug(1, "PostgreSQL RealTime: Result=%p Query: %s\n", result, ast_str_buffer(sql));
ast_debug(1, "PostgreSQL RealTime: Found %d rows.\n", num_rows);
if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
- ast_mutex_unlock(&pgsql_lock);
PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
return NULL;
}
for (i = 0; i < numFields; i++)
ast_debug(1, "PostgreSQL RealTime: Could not find any rows in table %s.\n", table);
}
- ast_mutex_unlock(&pgsql_lock);
PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
return cfg;
}
if (pgsql_exec(database, tablename, ast_str_buffer(sql), &result) != 0) {
ast_mutex_unlock(&pgsql_lock);
return -1;
+ } else {
+ ExecStatusType result_status = PQresultStatus(result);
+ if (result_status != PGRES_COMMAND_OK
+ && result_status != PGRES_TUPLES_OK
+ && result_status != PGRES_NONFATAL_ERROR) {
+ ast_log(LOG_WARNING,
+ "PostgreSQL RealTime: Failed to query database. Check debug for more info.\n");
+ ast_debug(1, "PostgreSQL RealTime: Query: %s\n", ast_str_buffer(sql));
+ ast_debug(1, "PostgreSQL RealTime: Query Failed because: %s (%s)\n",
+ PQresultErrorMessage(result), PQresStatus(result_status));
+ PQclear(result);
+ ast_mutex_unlock(&pgsql_lock);
+ return -1;
+ }
}
numrows = atoi(PQcmdTuples(result));
}
insertid = PQoidValue(result);
+ PQclear(result);
ast_mutex_unlock(&pgsql_lock);
ast_debug(1, "PostgreSQL RealTime: row inserted on table: %s, id: %u\n", table, insertid);