ANSI C and sqlite3_get_table: How to pass results array back to calling function? -


i'm trying pass results array generated sqlite3_get_table contained in function called function. working fine except can't array main function. replace char **sql_results with? here's code:

int main() {     char **sql_results = 0; // here      sql_select_table("getairports", query_string, airports_database,              sql_results, &recordcount,              &columncount);      (int = 0; < 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 take address of 1 of sql_select_table arguments , doesn't think does; &sql_results address of local variable, won't let modify sql_results in main().

instead, pass char*** sql_select_table this:

/* note sql_results char*** */ 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);  }  int main() {     char **sql_results = 0;      /* note & on sql_results */     sql_select_table("getairports", query_string, airports_database,              &sql_results, &recordcount,              &columncount);      (int = 0; < columncount; i++)         printf("%s\n", sql_results[i]); // generates "exc_bad_access"  } 

also, sqlite3_get_table deprecated:

this legacy interface preserved backwards compatibility. use of interface not recommended.

so might want start using sqlite3_exec instead.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -