Commits

Greg Slepak committed 04e4d2b

improved fn-query-with-db and assoc-row-with-db

  • Participants
  • Parent commits 93326d8

Comments (0)

Files changed (1)

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

 ; 	)
 ; )
 
-(define (fn-query-with-db db query func)
-	(let (sql (db:prepare-sql query) keys '())
-		(setf keys (map sql:col-name (sequence 0 (-- (sql:col-count)))))
-		(push-autorelease-pool) ; in case we have blobs
-		(while (list? (setf values (sql:next-row)))
-			(func (transpose (list keys values)))
+(define (fn-query-with-db db query func params , sql keys values)
+	(when (setf sql (db:prepare-sql query))
+		(when (or (not params) (sql:bind-params params))
+			(setf keys (map sql:col-name (sequence 0 (-- (sql:col-count)))))
+			(push-autorelease-pool) ; in case we have blobs
+			(while (list? (setf values (sql:next-row)))
+				(func (transpose (list keys values))))
+			(pop-autorelease-pool)
 		)
-		(pop-autorelease-pool)
 		(deallocate sql)
 	)
 )
 (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)
+(define (assoc-row-with-db db query params , sql keys values result)
+	(when (setf sql (db:prepare-sql query))
+		(when (or (not params) (sql:bind-params params))
+			(set 'keys (map sql:col-name (sequence 0 (-- (sql:col-count))))
+			     'values (sql:next-row))
+			(when (list? values)
+				(setf result (transpose (list keys values))))
 		)
 		(deallocate sql)
-		(when (list? values) (transpose (list keys values)))
+		result
 	)
 )
 (global 'assoc-row-with-db)