I’m trying to pass the results array generated by sqlite3_get_table contained
in a function called by another function. Everything is working fine except I
can’t get the array back into the main function. What exactly do I replace the
char **sql_results with? Here’s the code:
int main()
{
char **sql_results = 0; // help here
sql_select_table("GetAirports", query_string, AIRPORTS_DATABASE,
sql_results, &RecordCount,
&ColumnCount);
for (int i = 0; i < ColumnCount; i++)
printf("%s\n", sql_results[i]); // Generates "EXC_BAD_ACCESS"
}
void sql_select_table(const char *query_name, const char *sql_query,
const char *sql_database,
char **sql_results, int *RecordCount,
int *ColumnCount)
{
sqlite3_get_table(open_database, sql_query,
&sql_results, RecordCount,
ColumnCount, &error_msg);
}
You’re trying to take the address of one of the
sql_select_tablearguments and that doesn’t do what you think it does;&sql_resultsis just the address of a local variable, it won’t let you modify thesql_resultsinmain().Instead, pass a
char***intosql_select_tablelike this:Also,
sqlite3_get_tableis deprecated:So you might want to start using
sqlite3_execinstead.