added dates/times to the parameter value coersion and pulled this into
authorRuss Tyndall <russ@acceleration.net>
Tue, 30 Oct 2012 15:55:28 +0000 (11:55 -0400)
committerNathan Bird <nathan@acceleration.net>
Tue, 4 Dec 2012 21:18:11 +0000 (16:18 -0500)
a new generic prepare-sql-parameter

ChangeLog
sql/command-object.lisp
sql/package.lisp

index 40ee2d7fc91b84ffcb1546ed2d7bbe098e3c9447..0db8fd13284cb15d9eed842b6c88592cc3dfaa23 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2012-10-30  Russ Tyndall <russ@acceleration.net>
+       * sql/command-object.lisp - added dates/times to the parameter value
+       coersion and pulled this into a new generic prepare-sql-parameter
+
 2012-09-04  Kevin Rosenberg  <kevin@rosenberg.net>
        * Version 6.3 released
 
index d931bac46ed4fd63240c5ada0b0003844b4804a0..6af4bc86287a6e7aadfad03c179d01127c1140f8 100644 (file)
                      :documentation "Have we already prepared this command object?")
    ))
 
+
+(defgeneric prepare-sql-parameter (sql-parameter)
+  (:documentation "This method is responsible for formatting parameters
+     as the database expects them (eg: :false is nil, nil is :null, dates are iso8601 strings)")
+  (:method (sql-parameter)
+    (typecase sql-parameter
+      (null :null)
+      (symbol
+       (if (member sql-parameter (list :false :F))
+           nil
+           (princ-to-string sql-parameter)))
+      (clsql-sys:date (format-date nil sql-parameter :format :iso8601))
+      (clsql-sys:wall-time (format-time nil sql-parameter :format :iso8601))
+      (t sql-parameter))))
+
 (defmethod initialize-instance :after ((o command-object) &key &allow-other-keys )
-  ;; Inits parameter nulls
+  ;; Inits parameter value coersion
   (setf (parameters o) (parameters o)))
 
 (defmethod (setf parameters) (new (o command-object))
   " This causes the semantics to match cl-sql instead of cl-postgresql
   "
   (setf (slot-value o 'parameters)
-       (loop for p in new
-             collecting (cond ((null p) :null)
-                              ((member p (list :false :F)) nil)
-                              (T p)))))
+       (loop for p in new collecting (prepare-sql-parameter p))))
 
 (defun reset-command-object (co)
   "Resets the command object to have no name and to be unprepared
index eb5b0ed46282984b0c64420642daee9f48fbf413..eb6faf8cc1396bb6aa3fd5c6acb4b3195659e5fe 100644 (file)
      ;; Command-object.lisp
      #:expression
      #:parameters
+     #:prepare-sql-parameter
      #:prepared-name
      #:has-been-prepared
      #:command-object