← cproj

loop through rows with sqlite3_column_origin_name

ebfcb9c124b38141b6870847486990f27579227f · Ovidiu Constantinescu · Oct 11, 2019 17:12

sqlite3_column_origin_name needs to have  -DSQLITE_ENABLE_COLUMN_METADATA

+5 −7 · 1 file changed

  • graph/db/sqltest.c +5 −7
diff --git a/graph/db/sqltest.c b/graph/db/sqltest.c
index 35c0c9b..2c87225 100644
--- a/graph/db/sqltest.c
+++ b/graph/db/sqltest.c
@@ -185,17 +185,15 @@ int dbSelect(sqlite3 *db, char *data) {
   // 1st arg - pointed data by sqlite_stmt
   // returns integer - the result of the operation
   // Useful routines;
-    // - sqlite3_data_count() will return 0 if sqlite3_step was not called
-                  fprintf(stdout,"SQL column is: %d\n", sqlite3_data_count(res));
   rc = sqlite3_step(res);
-    // - sqlite3_column_count() will return the number of columns before sqlite3_step
-                  fprintf(stdout,"SQL column is: %d\n", sqlite3_data_count(res));
-
-  if ( rc == SQLITE_ROW ) {
-  }
+          for ( int i = 0; i < sqlite3_data_count(res) ; i++ ) {
+               fprintf(stdout,"| %s\t",sqlite3_column_origin_name(res,i));
+          }
+          fprintf(stdout,"\r\n");
   while ( rc == SQLITE_ROW ) {
           int i = 0;
   // If the return code is SQLITE_ROW we can now iterate thorugh the entire column, row by row
+    // - sqlite3_data_count() will return 0 if sqlite3_step was not called
           for ( i = 0; i < sqlite3_data_count(res) ; i++ ) {
                fprintf(stdout,"| %s\t",sqlite3_column_text(res,i));
            }