6740f94bddfcc625a5828362c9b12bf98db0f320
[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
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   ;;(format t "value is \"~A\" of type ~A~%" val (type-of val))
74   (declare (ignore type))
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   val)
88
89 (defmethod read-sql-value (val (type (eql 'float)) (database oracle-database))
90   val)
91
92 ;;; LOCAL-TIME stuff that needs to go into hooks
93 #+local-time
94 (defmethod clsql::database-get-type-specifier
95   ((type (eql 'local-time::local-time)) args (database oracle-database))
96   (declare (ignore args))
97   "DATE")
98
99 #+local-time
100 (defmethod clsql::database-get-type-specifier
101   ((type (eql 'local-time::duration))
102    args
103    (database oracle-database))
104   (declare (ignore args))
105   "NUMBER(38)")