Преглед изворни кода

corrected define-form, added make-update-query

Samuel W. Flint пре 9 година
родитељ
комит
a718875d5d
1 измењених фајлова са 13 додато и 3 уклоњено
  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)))
+    ))