-
-
Save garbados/716d26684fe59c6d1d04c72f1213af18 to your computer and use it in GitHub Desktop.
Example of bizarre output.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; hi. | |
;; i'm very unfamiliar with sqlite, | |
;; and for that matter guile too. | |
;; i'm an experienced programmer, i assure you -- | |
;; i just can't seem the find the docs i need | |
;; to resolve this simple riddle. | |
;; how do i read back | |
;; what i've written | |
;; with guile-sqlite3? | |
;; the following code is the general case | |
;; of my exact problem. | |
;; if you know what i'm doing wrong, | |
;; would you let me know? | |
(use-modules (sqlite3)) | |
(define table "db_crud") | |
(define db-name (string-append table ".db")) | |
(define db (sqlite-open db-name (logior SQLITE_OPEN_CREATE | |
SQLITE_OPEN_READWRITE))) | |
;; regenerate the table | |
(sqlite-exec db (string-append "DROP TABLE IF EXISTS " table)) | |
(sqlite-exec db | |
(string-append "create table " | |
table | |
" (" | |
" ref text primary key," | |
" block text not null" | |
")")) | |
;; insert a row. this works | |
(let* ((query (string-append "insert into " | |
table | |
" values (?,?);")) | |
(stmt (sqlite-prepare db query))) | |
(sqlite-bind stmt 1 "hello") | |
(sqlite-bind stmt 2 "world") | |
(sqlite-finalize stmt)) | |
;; read the row back by key. this doesn't work | |
(let* ((query (string-append "select block from " | |
table | |
" where 'ref' = ?")) | |
(stmt (sqlite-prepare db query))) | |
(sqlite-bind stmt 1 "hello") | |
(let ((result (sqlite-finalize stmt))) | |
(display result))) | |
;; 0 | |
;; reading back all results also doesn't work | |
(let* ((query (string-append "select block from " table)) | |
(stmt (sqlite-prepare db query))) | |
(let ((result (sqlite-finalize stmt))) | |
(display result))) | |
;; 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment