r9427: 22 May 2004 Kevin Rosenberg
[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 (defparameter *oracle-default-varchar2-length* "512")
19
20 (defmethod database-get-type-specifier
21   (type args (database oracle-database))
22   (declare (ignore type args))
23   (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")"))
24
25 (defmethod database-get-type-specifier ((type (eql 'integer)) args (database oracle-database))
26   (if args
27       (format nil "NUMBER(~A,~A)"
28               (or (first args) 38) (or (second args) 0))
29     "INTEGER"))
30
31 (defmethod database-get-type-specifier
32   ((type (eql 'bigint)) args (database oracle-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
39   ((type (eql 'simple-base-string)) args (database oracle-database))
40   (if args
41       (format nil "VARCHAR2(~A)" (car args))
42     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")")))
43
44 (defmethod database-get-type-specifier
45   ((type (eql 'simple-string)) args (database oracle-database))
46   (if args
47       (format nil "VARCHAR2(~A)" (car args))
48     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")")))
49
50 (defmethod database-get-type-specifier
51   ((type (eql 'string)) args (database oracle-database))
52   (if args
53       (format nil "VARCHAR2(~A)" (car args))
54     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")")))
55
56 (defmethod database-get-type-specifier
57   ((type (eql 'raw-string)) args (database oracle-database))
58   (if args
59       (format nil "VARCHAR2(~A)" (car args))
60     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")")))
61
62 (defmethod database-get-type-specifier
63   ((type (eql 'float)) args (database oracle-database))
64   (if args
65       (format nil "NUMBER(~A,~A)" (or (first args) 38) (or (second args) 38))
66     "double precision"))
67
68 (defmethod database-get-type-specifier
69   ((type (eql 'long-float)) args (database oracle-database))
70   (if args
71       (format nil "NUMBER(~A,~A)"
72               (or (first args) 38) (or (second args) 38))
73     "double precision"))
74
75 (defmethod database-get-type-specifier
76     ((type (eql 'boolean)) args (database oracle-database))
77   (declare (ignore args))
78   "CHAR(1)")
79
80 (defmethod read-sql-value (val type (database oracle-database))
81   ;;(format t "value is \"~A\" of type ~A~%" val (type-of val))
82   (declare (ignore type))
83   (etypecase val
84     (string
85      (read-from-string val))
86     (symbol
87      nil)))
88
89 (defmethod read-sql-value
90   (val (type (eql 'integer)) (database oracle-database))
91   val)
92
93 (defmethod read-sql-value (val (type (eql 'float)) (database oracle-database))
94   val)
95
96 (defmethod read-sql-value (val (type (eql 'boolean)) (database oracle-database))
97   (when (char-equal #\t (schar val 0))
98     t))
99
100 (defmethod database-get-type-specifier
101   ((type (eql 'wall-time)) args (database oracle-database))
102   (declare (ignore args))
103   "DATE")
104
105 (defmethod database-get-type-specifier
106   ((type (eql 'duration))
107    args
108    (database oracle-database))
109   (declare (ignore args))
110   "NUMBER(38)")