r9478: 25 May 2004 Kevin Rosenberg <kevin@rosenberg.net>
[clsql.git] / db-oracle / oracle-objects.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name: oracle-objects.lisp
6 ;;;;
7 ;;;; $Id$
8 ;;;;
9 ;;;; This file is part of CLSQL.
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-oracle)
17
18 (defmethod database-get-type-specifier (type args database (db-type (eql :oracle)))
19   (declare (ignore type args database))
20     (format nil "VARCHAR2(~D)" *default-varchar-length*))
21
22 (defmethod database-get-type-specifier ((type (eql 'integer)) args 
23                                         database (db-type (eql :oracle)))
24   (declare (ignore database))
25   (if args
26       (format nil "NUMBER(~A,~A)"
27               (or (first args) 38) (or (second args) 0))
28     "INTEGER"))
29
30 (defmethod database-get-type-specifier ((type (eql 'bigint)) args
31                                         database (db-type (eql :oracle)))
32   (declare (ignore database)) 
33   (if args
34       (format nil "NUMBER(~A,~A)"
35               (or (first args) 38) (or (second args) 0))
36     "NUMBER(38,0)"))
37
38 (defmethod database-get-type-specifier ((type (eql 'string)) args
39                                         database (db-type (eql :oracle)))
40   (declare (ignore database)) 
41   (if args
42       (format nil "CHAR(~A)" (car args))
43     (format nil "VARCHAR2(~D)" *default-varchar-length*)))
44
45 (defmethod database-get-type-specifier ((type (eql 'varchar)) args
46                                         database (db-type (eql :oracle)))
47   (declare (ignore database)) 
48   (if args
49       (format nil "VARCHAR2(~A)" (car args))
50     (format nil "VARCHAR2(~D)" *default-varchar-length*)))
51
52 (defmethod database-get-type-specifier ((type (eql 'float)) args
53                                         database (db-type (eql :oracle)))
54   (declare (ignore database)) 
55   (if args
56       (format nil "NUMBER(~A,~A)" (or (first args) 38) (or (second args) 38))
57     "DOUBLE PRECISION"))
58
59 (defmethod database-get-type-specifier ((type (eql 'long-float)) args
60                                         database (db-type (eql :oracle)))
61   (declare (ignore database)) 
62   (if args
63       (format nil "NUMBER(~A,~A)"
64               (or (first args) 38) (or (second args) 38))
65     "DOUBLE PRECISION"))
66
67 (defmethod database-get-type-specifier ((type (eql 'boolean)) args
68                                         database (db-type (eql :oracle)))
69   (declare (ignore args database))
70   "CHAR(1)")
71
72 (defmethod read-sql-value (val type
73                            database (db-type (eql :oracle)))
74   ;;(format t "value is \"~A\" of type ~A~%" val (type-of val))
75   (declare (ignore type database))
76   (etypecase val
77     (string
78      (read-from-string val))
79     (symbol
80      nil)))
81
82 (defmethod read-sql-value (val (type (eql 'integer))
83                            database (db-type (eql :oracle)))
84   (declare (ignore database))
85   val)
86
87 (defmethod read-sql-value (val (type (eql 'float))
88                            database (db-type (eql :oracle)))
89   (declare (ignore database))
90   val)
91
92 (defmethod read-sql-value (val (type (eql 'boolean))
93                            database (db-type (eql :oracle)))
94   (declare (ignore database))
95   (when (char-equal #\t (schar val 0))
96     t))
97
98 (defmethod database-get-type-specifier ((type (eql 'wall-time)) args
99                                         database (db-type (eql :oracle)))
100   (declare (ignore args database))
101   "DATE")
102
103 (defmethod database-get-type-specifier ((type (eql 'duration)) args
104                                         database (db-type (eql :oracle)))
105   (declare (ignore args database))
106   "NUMBER(38)")