r9576: Add generalized-boolean
[clsql.git] / db-mysql / mysql-objects.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:     mysql-objects.lisp
6 ;;;; Purpose:  CLSQL Object layer for MySQL
7 ;;;; Created:  May 2004
8 ;;;;
9 ;;;; $Id$
10 ;;;;
11 ;;;; CLSQL users are granted the rights to distribute and use this software
12 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
13 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
14 ;;;; *************************************************************************
15
16 (in-package #:clsql-mysql)
17
18 (defmethod database-get-type-specifier ((type (eql 'wall-time)) args database
19                                         (db-type (eql :mysql)))
20   (declare (ignore args database))
21   "DATETIME")
22
23 (defmethod database-output-sql-as-type ((type (eql 'boolean)) val database
24                                         (db-type (eql :mysql)))
25   (declare (ignore database))
26   (if val 1 0))
27
28 (defmethod database-output-sql-as-type ((type (eql 'generalized-boolean)) val database
29                                         (db-type (eql :mysql)))
30   (declare (ignore database))
31   (if val 1 0))
32
33 (defmethod read-sql-value (val (type (eql 'boolean)) database
34                            (db-type (eql :mysql)))
35   (declare (ignore database)) 
36   (etypecase val
37     (string (if (string= "0" val) nil t))
38     (integer (if (zerop val) nil t))))
39
40 (defmethod read-sql-value (val (type (eql 'generalized-boolean)) database
41                            (db-type (eql :mysql)))
42   (declare (ignore database)) 
43   (etypecase val
44     (string (if (string= "0" val) nil t))
45     (integer (if (zerop val) nil t))))