Explorar el Código

corrected define-form, added make-update-query

Samuel W. Flint hace 9 años
padre
commit
a718875d5d
Se han modificado 1 ficheros con 13 adiciones y 3 borrados
  1. 13 3
      collect.lisp

+ 13 - 3
collect.lisp

@@ -112,11 +112,21 @@
     `(:div (:input :type "radio" :name ,label :value ,value)
        ,name (:br))))
 
+(defun make-update-query (table columns fields)
+  (let ((actual-query (format nil "INSERT INTO ~a (~{~a~^, ~}) values (~{~a~^, ~})"
+                              table
+                              columns
+                              (iter (for i in columns)
+                                    (collect "?"))))
+        (fields (iter (for field in fields)
+                      (collect `(post-parameter ,field)))))
+    `(execute-non-query *db* ,actual-query ,@fields)))
+
 (defmacro define-form (name table (&rest fields) &key &allow-other-keys)
   (let* ((columns (map 'list #'second fields))
          (field-names (map 'list #'(lambda (column)
                                      (concatenate 'string "fld_" column))
                            columns))
-         (form-entries (map 'list #'make-form-entry fields)))
-    `(list (list ,@columns)
-           (list ,@field-names))))
+         (form-entries (map 'list #'make-form-entry fields))
+         (update-query (make-update-query table columns field-names)))
+    ))