Commits

Greg Slepak committed abcd650

added for-query-with-db

  • Participants
  • Parent commits e020246

Comments (0)

Files changed (6)

-Version 0.61
+Version 0.7
 
   * all code uses new ++,--,extend,write,read functions (still compatible with older newlisps)
   * now $BINARY can handle large data (compensated for a newLISP bug in 'read-buffer').
   * 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 db/dragonfly_utils, includes fn-query-with-db, assoc-row-with-db, assoc-rows-with-db and query-cell-with-db
+  * db/dragonfly_utils includes for-query-with-db, fn-query-with-db, assoc-row-with-db, assoc-rows-with-db and query-cell-with-db
   * fixed handling of floats in Sqlite3 on some architectures (more improvements needed though, see TODO)
   * added 'extract' and '<-' functions to core utils
 

File example-site/dragonfly-framework/dragonfly.lsp

 ;; @module dragonfly.lsp
 ;; @description The heart of Dragonfly - A newLISP web framework for rapid web development.
-;; @version 0.61
+;; @version 0.70
 ;; @author Team Dragonfly 2009
 ;; @location http://code.google.com/p/dragonfly-newlisp/
 ;; <br>This file is the main entry-point of the Dragonfly framework and
 ; DF is a convenient shorthand to the Dragonfly context
 (constant (global 'DF) Dragonfly)
 (constant (global 'DRAGONFLY_MAJOR) 0)
-(constant (global 'DRAGONFLY_MINOR) 61)
+(constant (global 'DRAGONFLY_MINOR) 70)
 (constant (global 'DRAGONFLY_VERSION) (format "Version %d.%d" DRAGONFLY_MAJOR DRAGONFLY_MINOR))
 
 ; make sure these two are defined

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

 ;; @version 1.0
 ;; @author Greg Slepak
 
-; this cannot be used because newlisp's 'caller' function is broken.
+(context MAIN)
+
 ; 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 '())
-; 		(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)) Dragonfly) 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)
-; 	)
-; )
-
-(context MAIN)
+(define-smacro (for-query-with-db db query)
+	(letn (ctx (prefix db) db (eval db) sql (db:prepare-sql (eval query)) keys '() values)
+		(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)
+	)
+)
 
 (define (fn-query-with-db db query func params , sql keys values)
 	(when (setf sql (db:prepare-sql query))

File example-site/dragonfly-framework/plugins-inactive/dragonfly_api.lsp

 ;;
 ;; @module Dragonfly
 ;; @author Marc Hildmann <marc.hildmann at gmail.com>, Greg Slepak <greg at taoeffect.com>
-;; @version 0.61
+;; @version 0.70
 ;; 
 ;; @location http://code.google.com/p/dragonfly-newlisp/
 ;; @description A newLISP web framework for rapid web development

File example-site/dragonfly-framework/plugins-inactive/dragonfly_twitter.lsp

 ;;
 ;; @module Dragonfly Twitter search plugin
 ;; @author Marc Hildmann <marc.hildmann at gmail.com>
-;; @version 0.61
+;; @version 0.70
 ;; 
 ;; @location http://code.google.com/p/dragonfly-newlisp/
 ;; @description A newLISP web framework for rapid web development

File example-site/views/dragonfly_sqlite3.html

 				<tr class="header"><td>ID</td><td>Name</td><td>Age</td></tr>
 				<% (fn-query-with-db db "SELECT rowid,name,age FROM people" (fn (row) %>
 					<tr>
-						<td><%=(lookup "rowid" row)%></td>
-						<td><%=(lookup "name" row)%></td>
-						<td><%=(lookup "age" row)%></td>
+						<td><%=(<- "rowid" row)%></td>
+						<td><%=(<- "name" row)%></td>
+						<td><%=(<- "age" row)%></td>
 					</tr>
 				<% )) %>
 			</table>
+			<table>
+				<tr class="header"><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>
+			
 		</p>
 		<p>
 			The table above was created like so: