I.e. check out this awesome function:
Code: Select all
(define-smacro (for-query-with-db db query ctx)
(letn (db (eval db) sql (db:prepare-sql query) keys '())
(dotimes (i (sql:col-count))
(push (sym (upper-case (sql:col-name i)) ctx) keys -1)
)
(push-autorelease-pool) ; in case we have blobs
(while (list? (setf values (sql:next-row)))
(eval (expand (cons 'begin $args) (unify keys values)))
)
(pop-autorelease-pool)
(deallocate sql)
)
)
This function is going to be in Dragonfly 0.61, it will let you do stuff like this:
Code: Select all
<table>
<tr><td>ID</td><td>Name</td><td>Age</td></tr>
<% (for-query-with-db db "SELECT rowid,name,age FROM people" %>
<tr><td><%=ROWID%></td><td><%=NAME%></td><td><%=AGE%></td></tr>
<% ) %>
</table>
Code: Select all
<table>
<tr><td>ID</td><td>Name</td><td>Age</td></tr>
<% (for-query-with-db db "SELECT rowid,name,age FROM people" DF %>
<tr><td><%=ROWID%></td><td><%=NAME%></td><td><%=AGE%></td></tr>
<% ) %>
</table>
Edit: updated function definition to use 'expand' and 'unify'