Commits

Greg Slepak  committed ae95682

added assoc-rows-with-db

  • Participants
  • Parent commits 04e4d2b

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 fn-query-with-db and assoc-row-with-db
+  * added db/dragonfly_utils, includes fn-query-with-db, assoc-row-with-db and assoc-rows-with-db
   * fixed handling of floats in Sqlite3 on some architectures (more improvements needed though, see TODO)
 
 Version 0.6

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

 	)
 )
 (global 'assoc-row-with-db)
+
+(define (assoc-rows-with-db db query params , sql keys values rows)
+	(when (setf sql (db:prepare-sql query))
+		(when (and (or (not params) (sql:bind-params params))
+		         (setf values (sql:next-row)))
+			(set 'keys (map sql:col-name (sequence 0 (-- (sql:col-count))))
+			     'rows '())
+			(while (list? values)
+				(push (transpose (list keys values)) rows -1)
+				(setf values (sql:next-row))
+			)
+		)
+		(deallocate sql)
+		rows
+	)
+)
+(global 'assoc-rows-with-db)