db_cmd   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/external/sqlite.xtm

Implementation

;; lining everything up neatly is left as an excercise for the reader :)
(bind-func db_cmd
  (lambda (sql_cmd)
    (let ((tail:i8** (salloc))
          (stmt_:sqlite3_stmt** (salloc))
          (stmt:sqlite3_stmt* null)
          (res (sqlite3_prepare_v2 DB sql_cmd -1 stmt_ tail)))
      (set! stmt (pref stmt_ 0))
      (beginz
       (if (<> SQLITE_OK res)
           (println "SQLITE Err:" (Str (sqlite3_errstr res)))
           (let ((columns (sqlite3_column_count stmt)) (i 0))
             (printout "\n | ")
             (dotimes (i columns)
               (printout (Str (sqlite3_column_name stmt i)) " | "))
             (println "\n------------------------")
             (while (= SQLITE_ROW (sqlite3_step stmt))
               (printout " | ")
               (dotimes (i columns)
                 (db_print_column stmt i)
                 (printout " | "))
               (println))))
       void)
      (set! res (sqlite3_finalize stmt))
      void)))


Back to Index

Similar Entries