Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement datetime unparsing to restore symmetry :)

  • Loading branch information...
commit 702e01f6d05f76ceae0a76f7664fbe741e0526de 1 parent 4435f22
Peter Bex authored
Showing with 36 additions and 0 deletions.
  1. +26 −0 freetds.scm
  2. +10 −0 tests/run.scm
View
26 freetds.scm
@@ -841,6 +841,32 @@ with the FreeTDS egg. If not, see <http://www.gnu.org/licenses/>.
(data-format-datatype-set!
fmt* (foreign-value "CS_INT_TYPE" CS_INT))
#t)
+ ((date? param)
+ (data-format-datatype-set!
+ fmt* (foreign-value "CS_DATETIME_TYPE" CS_INT))
+ ((foreign-lambda* c-pointer
+ (((c-pointer "CS_CONTEXT") ctx)
+ (c-string s)
+ ((c-pointer "CS_DATAFMT") fmt))
+ "CS_CHAR *tmp = (CS_CHAR *)s;"
+ "CS_DATAFMT src;"
+ "CS_DATETIME *res;"
+ "CS_RETCODE ret;"
+ "res = malloc(sizeof(CS_DATETIME));"
+ "if (res == NULL)"
+ " C_return(res);"
+ "src.namelen = 0;"
+ "src.datatype = CS_CHAR_TYPE;"
+ "src.maxlength = strlen(s);"
+ "ret = cs_convert(ctx, &src, s, fmt, res, NULL);"
+ "if (ret != CS_SUCCEED) {"
+ " free(res);"
+ " C_return(NULL);"
+ "}"
+ "C_return(res);")
+ ;; We can't use ~4 or ~5 because FreeTDS chokes on the 'T'
+ ;; time separator. Also, it doesn't grok timezones.
+ *app-context* (date->string param "~1 ~3") fmt*))
(else (error "Unknown parameter type" param)))))
(data-format-name-length-set! fmt* 0) ; All params are nameless
(data-format-status-set! fmt* (foreign-value "CS_INPUTVALUE" CS_INT))
View
10 tests/run.scm
@@ -123,6 +123,16 @@
'((0.0 -1.5 110.12345))
(result-values
(send-query connection "SELECT ?, ?, ?" 0.0 -1.5 110.12345)))
+ (test "Datetime values are written correctly"
+ ;; TODO: Figure out how to make this thing use timezones
+ `((,(make-date 0 0 0 0 1 1 2000 0)
+ ,(make-date 0 56 1 17 9 5 2011 0)
+ ,(make-date 0 58 14 17 9 5 2011 0)))
+ (result-values (send-query connection
+ "SELECT ?, ?, ?"
+ (make-date 0 0 0 0 1 1 2000 0)
+ (make-date 0 56 1 17 9 5 2011 0)
+ (make-date 0 58 14 17 9 5 2011 0))))
(test "NULL values are written correctly"
(list (list (sql-null) (sql-null)))
(result-values

0 comments on commit 702e01f

Please sign in to comment.
Something went wrong with that request. Please try again.