Commits

Greg Slepak committed 93326d8

added assoc-row-with-db to database_utils.lsp

Comments (0)

Files changed (2)

   * added documentation for MAX_POST_LENGTH in request.lsp
   * fix to Jeff's JSON.lsp plugin (switched to " instead of ' for strings)
   * DF:activate-plugin can now be used to load all lisp files in a directory
-  * added a dragonfly_utils.lsp file to the DF.DB folder, includes handy fn-query-with-db function.
+  * added a dragonfly_utils.lsp file to the DF.DB folder, includes fn-query-with-db and assoc-row-with-db
   * fixed handling of floats in Sqlite3 on some architectures (more improvements needed though, see TODO)
 
 Version 0.6

example-site/dragonfly-framework/plugins-inactive/db/database_utils.lsp

 ; this cannot be used because newlisp's 'caller' function is broken.
 ; define-smacro defined in utils.lsp (part of Dragonfly's core functions)
 ; (define-smacro (for-query-with-db db query )
-; 	(letn (db (eval db) sql (db:prepare-sql (eval query)) keys '() ctx (prefix (caller)))
-; 		;(println ctx " vs " (prefix (caller)))
+; 	(letn (db (eval db) sql (db:prepare-sql (eval query)) keys '())
 ; 		(dotimes (i (sql:col-count))
 ; 			;(push (sym (upper-case (sql:col-name i)) (prefix (caller))) keys -1)
-; 			;(push (sym (upper-case (sql:col-name i)) ctx) keys -1)
 ; 			(push (sym (upper-case (sql:col-name i)) Dragonfly) keys -1)
 ; 		)
 ; 		(push-autorelease-pool) ; in case we have blobs
 	)
 )
 (global 'fn-query-with-db)
+
+(define (assoc-row-with-db db query)
+	(let (sql (db:prepare-sql query) keys '())
+		(set 'keys (map sql:col-name (sequence 0 (-- (sql:col-count))))
+		     'values (sql:next-row)
+		)
+		(deallocate sql)
+		(when (list? values) (transpose (list keys values)))
+	)
+)
+(global 'assoc-row-with-db)