r9310: update headers
[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, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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
26   ((type (eql 'integer)) args (database oracle-database))
27   (if args
28       (format nil "NUMBER(~A,~A)"
29               (or (first args) 38) (or (second args) 0))
30     "NUMBER(38,0)"))
31
32 (defmethod database-get-type-specifier
33   ((type (eql 'simple-base-string)) args (database oracle-database))
34   (if args
35       (format nil "VARCHAR2(~A)" (car args))
36     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")")))
37
38 (defmethod database-get-type-specifier
39   ((type (eql 'simple-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 'string)) args (database oracle-database))
46   (if args
47       (format nil "VARCHAR2(~A)" (car args))
48     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")"))
49   "VARCHAR2(512)")
50
51 (defmethod database-get-type-specifier
52   ((type (eql 'raw-string)) args (database oracle-database))
53   (if args
54       (format nil "VARCHAR2(~A)" (car args))
55     (concatenate 'string "VARCHAR2(" *oracle-default-varchar2-length* ")"))
56   "VARCHAR2(256)")
57
58 (defmethod database-get-type-specifier
59   ((type (eql 'float)) args (database oracle-database))
60   (if args
61       (format nil "NUMBER(~A,~A)"
62               (or (first args) 38) (or (second args) 38))
63     "NUMBER"))
64
65 (defmethod database-get-type-specifier
66   ((type (eql 'long-float)) args (database oracle-database))
67   (if args
68       (format nil "NUMBER(~A,~A)"
69               (or (first args) 38) (or (second args) 38))
70     "NUMBER"))
71
72 (defmethod read-sql-value (val type (database oracle-database))
73   (declare (ignore type database))
74   ;;(format t "value is \"~A\" of type ~A~%" val (type-of val))
75   (etypecase val
76     (string
77      (read-from-string val))
78     (symbol
79      nil)))
80
81 (defmethod read-sql-value (val (type (eql 'string)) database)
82   (declare (ignore database))
83   val)
84
85 (defmethod read-sql-value
86   (val (type (eql 'integer)) (database oracle-database))
87   (declare (ignore database))
88   val)
89
90 (defmethod read-sql-value (val (type (eql 'float)) (database oracle-database))
91   val)
92
93 ;;; LOCAL-TIME stuff that needs to go into hooks
94 #+local-time
95 (defmethod clsql::database-get-type-specifier
96   ((type (eql 'local-time::local-time)) args (database oracle-database))
97   (declare (ignore args))
98   "DATE")
99
100 #+local-time
101 (defmethod clsql::database-get-type-specifier
102   ((type (eql 'local-time::duration))
103    args
104    (database oracle-database))
105   (declare (ignore args))
106   "NUMBER(38)")