← cproj

while loop

efb50457752fde2f9d53020fee5cbff4ffce6084 · Ovidiu Constantinescu · Oct 11, 2019 15:50

+17 −6 · 1 file changed

  • graph/db/sqltest.c +17 −6
diff --git a/graph/db/sqltest.c b/graph/db/sqltest.c
index f7e2ab0..35c0c9b 100644
--- a/graph/db/sqltest.c
+++ b/graph/db/sqltest.c
@@ -184,16 +184,27 @@ int dbSelect(sqlite3 *db, char *data) {
   //2.Step
   // 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);
-  while ( rc == SQLITE_ROW) {
+    // - 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 ) {
+  }
+  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
-       fprintf(stdout,"SQLite data is: %s\t",sqlite3_column_text(res,1));
-       fprintf(stdout," %d\n",sqlite3_column_int(res,2));
-        rc = sqlite3_step(res);
+          for ( i = 0; i < sqlite3_data_count(res) ; i++ ) {
+               fprintf(stdout,"| %s\t",sqlite3_column_text(res,i));
+           }
+          fprintf(stdout,"\r\n");
+  // Grab next row
+         rc = sqlite3_step(res);
+   }
+
 
-  }
 
   // Finalize - clean up after using.
   rc = sqlite3_finalize(res);