Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
/**
4
  V4.80 8 Mar 2006  (c) 2000-2006 John Lim (jlim@natsoft.com.my). All rights reserved.
5
  Released under both BSD license and Lesser GPL library license. 
6
  Whenever there is any discrepancy between the two licenses, 
7
  the BSD license will take precedence.
8
 
9
  Set tabs to 4 for best viewing.
10
 
11
*/
12
 
13
// security - hide paths
14
if (!defined('ADODB_DIR')) die();
15
 
16
class ADODB2_sybase extends ADODB_DataDict {
17
	var $databaseType = 'sybase';
18
 
19
	var $dropIndex = 'DROP INDEX %2$s.%1$s';
20
 
21
	function MetaType($t,$len=-1,$fieldobj=false)
22
	{
23
		if (is_object($t)) {
24
			$fieldobj = $t;
25
			$t = $fieldobj->type;
26
			$len = $fieldobj->max_length;
27
		}
28
 
29
		$len = -1; // mysql max_length is not accurate
30
		switch (strtoupper($t)) {
31
 
32
		case 'INT': 
33
		case 'INTEGER': return  'I';
34
		case 'BIT':
35
		case 'TINYINT': return  'I1';
36
		case 'SMALLINT': return 'I2';
37
		case 'BIGINT':  return  'I8';
38
 
39
		case 'REAL':
40
		case 'FLOAT': return 'F';
41
		default: return parent::MetaType($t,$len,$fieldobj);
42
		}
43
	}
44
 
45
	function ActualType($meta)
46
	{
47
		switch(strtoupper($meta)) {
48
		case 'C': return 'VARCHAR';
49
		case 'XL':
50
		case 'X': return 'TEXT';
51
 
52
		case 'C2': return 'NVARCHAR';
53
		case 'X2': return 'NTEXT';
54
 
55
		case 'B': return 'IMAGE';
56
 
57
		case 'D': return 'DATETIME';
58
		case 'T': return 'DATETIME';
59
		case 'L': return 'BIT';
60
 
61
		case 'I': return 'INT'; 
62
		case 'I1': return 'TINYINT';
63
		case 'I2': return 'SMALLINT';
64
		case 'I4': return 'INT';
65
		case 'I8': return 'BIGINT';
66
 
67
		case 'F': return 'REAL';
68
		case 'N': return 'NUMERIC';
69
		default:
70
			return $meta;
71
		}
72
	}
73
 
74
 
75
	function AddColumnSQL($tabname, $flds)
76
	{
77
		$tabname = $this->TableName ($tabname);
78
		$f = array();
79
		list($lines,$pkey) = $this->_GenFields($flds);
80
		$s = "ALTER TABLE $tabname $this->addCol";
81
		foreach($lines as $v) {
82
			$f[] = "\n $v";
83
		}
84
		$s .= implode(', ',$f);
85
		$sql[] = $s;
86
		return $sql;
87
	}
88
 
89
	function AlterColumnSQL($tabname, $flds)
90
	{
91
		$tabname = $this->TableName ($tabname);
92
		$sql = array();
93
		list($lines,$pkey) = $this->_GenFields($flds);
94
		foreach($lines as $v) {
95
			$sql[] = "ALTER TABLE $tabname $this->alterCol $v";
96
		}
97
 
98
		return $sql;
99
	}
100
 
101
	function DropColumnSQL($tabname, $flds)
102
	{
103
		$tabname = $this->TableName($tabname);
104
		if (!is_array($flds)) $flds = explode(',',$flds);
105
		$f = array();
106
		$s = "ALTER TABLE $tabname";
107
		foreach($flds as $v) {
108
			$f[] = "\n$this->dropCol ".$this->NameQuote($v);
109
		}
110
		$s .= implode(', ',$f);
111
		$sql[] = $s;
112
		return $sql;
113
	}
114
 
115
	// return string must begin with space
116
	function _CreateSuffix($fname,$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint)
117
	{	
118
		$suffix = '';
119
		if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
120
		if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
121
		if ($fnotnull) $suffix .= ' NOT NULL';
122
		else if ($suffix == '') $suffix .= ' NULL';
123
		if ($fconstraint) $suffix .= ' '.$fconstraint;
124
		return $suffix;
125
	}
126
 
127
	/*
128
CREATE TABLE 
129
    [ database_name.[ owner ] . | owner. ] table_name 
130
    ( { < column_definition > 
131
        | column_name AS computed_column_expression 
132
        | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
133
 
134
            | [ { PRIMARY KEY | UNIQUE } [ ,...n ] 
135
    ) 
136
 
137
[ ON { filegroup | DEFAULT } ] 
138
[ TEXTIMAGE_ON { filegroup | DEFAULT } ] 
139
 
140
< column_definition > ::= { column_name data_type } 
141
    [ COLLATE < collation_name > ] 
142
    [ [ DEFAULT constant_expression ] 
143
        | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
144
    ] 
145
    [ ROWGUIDCOL] 
146
    [ < column_constraint > ] [ ...n ] 
147
 
148
< column_constraint > ::= [ CONSTRAINT constraint_name ] 
149
    { [ NULL | NOT NULL ] 
150
        | [ { PRIMARY KEY | UNIQUE } 
151
            [ CLUSTERED | NONCLUSTERED ] 
152
            [ WITH FILLFACTOR = fillfactor ] 
153
            [ON {filegroup | DEFAULT} ] ] 
154
        ] 
155
        | [ [ FOREIGN KEY ] 
156
            REFERENCES ref_table [ ( ref_column ) ] 
157
            [ ON DELETE { CASCADE | NO ACTION } ] 
158
            [ ON UPDATE { CASCADE | NO ACTION } ] 
159
            [ NOT FOR REPLICATION ] 
160
        ] 
161
        | CHECK [ NOT FOR REPLICATION ] 
162
        ( logical_expression ) 
163
    } 
164
 
165
< table_constraint > ::= [ CONSTRAINT constraint_name ] 
166
    { [ { PRIMARY KEY | UNIQUE } 
167
        [ CLUSTERED | NONCLUSTERED ] 
168
        { ( column [ ASC | DESC ] [ ,...n ] ) } 
169
        [ WITH FILLFACTOR = fillfactor ] 
170
        [ ON { filegroup | DEFAULT } ] 
171
    ] 
172
    | FOREIGN KEY 
173
        [ ( column [ ,...n ] ) ] 
174
        REFERENCES ref_table [ ( ref_column [ ,...n ] ) ] 
175
        [ ON DELETE { CASCADE | NO ACTION } ] 
176
        [ ON UPDATE { CASCADE | NO ACTION } ] 
177
        [ NOT FOR REPLICATION ] 
178
    | CHECK [ NOT FOR REPLICATION ] 
179
        ( search_conditions ) 
180
    } 
181
 
182
 
183
	*/
184
 
185
	/*
186
	CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name 
187
    ON { table | view } ( column [ ASC | DESC ] [ ,...n ] ) 
188
		[ WITH < index_option > [ ,...n] ] 
189
		[ ON filegroup ]
190
		< index_option > :: = 
191
		    { PAD_INDEX | 
192
		        FILLFACTOR = fillfactor | 
193
		        IGNORE_DUP_KEY | 
194
		        DROP_EXISTING | 
195
		    STATISTICS_NORECOMPUTE | 
196
		    SORT_IN_TEMPDB  
197
		}
198
*/
199
	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
200
	{
201
		$sql = array();
202
 
203
		if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
204
			$sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
205
			if ( isset($idxoptions['DROP']) )
206
				return $sql;
207
		}
208
 
209
		if ( empty ($flds) ) {
210
			return $sql;
211
		}
212
 
213
		$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
214
		$clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
215
 
216
		if ( is_array($flds) )
217
			$flds = implode(', ',$flds);
218
		$s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
219
 
220
		if ( isset($idxoptions[$this->upperName]) )
221
			$s .= $idxoptions[$this->upperName];
222
 
223
		$sql[] = $s;
224
 
225
		return $sql;
226
	}
227
}
228
?>