Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
/**
3
 * Data Dictionary for SyBase.
4
 *
5
 * This file is part of ADOdb, a Database Abstraction Layer library for PHP.
6
 *
7
 * @package ADOdb
8
 * @link https://adodb.org Project's web site and documentation
9
 * @link https://github.com/ADOdb/ADOdb Source code and issue tracker
10
 *
11
 * The ADOdb Library is dual-licensed, released under both the BSD 3-Clause
12
 * and the GNU Lesser General Public Licence (LGPL) v2.1 or, at your option,
13
 * any later version. This means you can use it in proprietary products.
14
 * See the LICENSE.md file distributed with this source code for details.
15
 * @license BSD-3-Clause
16
 * @license LGPL-2.1-or-later
17
 *
18
 * @copyright 2000-2013 John Lim
19
 * @copyright 2014 Damien Regad, Mark Newnham and the ADOdb community
20
 */
21
 
22
// security - hide paths
23
if (!defined('ADODB_DIR')) die();
24
 
25
class ADODB2_sybase extends ADODB_DataDict {
26
	var $databaseType = 'sybase';
27
 
28
	var $dropIndex = 'DROP INDEX %2$s.%1$s';
29
 
30
	function MetaType($t,$len=-1,$fieldobj=false)
31
	{
32
		if (is_object($t)) {
33
			$fieldobj = $t;
34
			$t = $fieldobj->type;
35
			$len = $fieldobj->max_length;
36
		}
37
 
38
		$t = strtoupper($t);
39
 
40
		if (array_key_exists($t,$this->connection->customActualTypes))
41
			return  $this->connection->customActualTypes[$t];
42
 
43
		$len = -1; // mysql max_length is not accurate
44
 
45
		switch ($t) {
46
 
47
 
48
		case 'INT':
49
		case 'INTEGER': return  'I';
50
		case 'BIT':
51
		case 'TINYINT': return  'I1';
52
		case 'SMALLINT': return 'I2';
53
		case 'BIGINT':  return  'I8';
54
 
55
		case 'REAL':
56
		case 'FLOAT': return 'F';
57
		default: return parent::MetaType($t,$len,$fieldobj);
58
		}
59
	}
60
 
61
	function ActualType($meta)
62
	{
63
		$meta = strtoupper($meta);
64
 
65
		/*
66
		* Add support for custom meta types. We do this
67
		* first, that allows us to override existing types
68
		*/
69
		if (isset($this->connection->customMetaTypes[$meta]))
70
			return $this->connection->customMetaTypes[$meta]['actual'];
71
 
72
		switch(strtoupper($meta)) {
73
		case 'C': return 'VARCHAR';
74
		case 'XL':
75
		case 'X': return 'TEXT';
76
 
77
		case 'C2': return 'NVARCHAR';
78
		case 'X2': return 'NTEXT';
79
 
80
		case 'B': return 'IMAGE';
81
 
82
		case 'D': return 'DATETIME';
83
		case 'TS':
84
		case 'T': return 'DATETIME';
85
		case 'L': return 'BIT';
86
 
87
		case 'I': return 'INT';
88
		case 'I1': return 'TINYINT';
89
		case 'I2': return 'SMALLINT';
90
		case 'I4': return 'INT';
91
		case 'I8': return 'BIGINT';
92
 
93
		case 'F': return 'REAL';
94
		case 'N': return 'NUMERIC';
95
		default:
96
			return $meta;
97
		}
98
	}
99
 
100
 
101
	function AddColumnSQL($tabname, $flds)
102
	{
103
		$tabname = $this->TableName ($tabname);
104
		$f = array();
105
		list($lines,$pkey) = $this->_GenFields($flds);
106
		$s = "ALTER TABLE $tabname $this->addCol";
107
		foreach($lines as $v) {
108
			$f[] = "\n $v";
109
		}
110
		$s .= implode(', ',$f);
111
		$sql[] = $s;
112
		return $sql;
113
	}
114
 
115
	function AlterColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
116
	{
117
		$tabname = $this->TableName ($tabname);
118
		$sql = array();
119
		list($lines,$pkey) = $this->_GenFields($flds);
120
		foreach($lines as $v) {
121
			$sql[] = "ALTER TABLE $tabname $this->alterCol $v";
122
		}
123
 
124
		return $sql;
125
	}
126
 
127
	function DropColumnSQL($tabname, $flds, $tableflds='', $tableoptions='')
128
	{
129
		$tabname = $this->TableName($tabname);
130
		if (!is_array($flds)) $flds = explode(',',$flds);
131
		$f = array();
132
		$s = "ALTER TABLE $tabname";
133
		foreach($flds as $v) {
134
			$f[] = "\n$this->dropCol ".$this->NameQuote($v);
135
		}
136
		$s .= implode(', ',$f);
137
		$sql[] = $s;
138
		return $sql;
139
	}
140
 
141
	// return string must begin with space
142
	function _CreateSuffix($fname,&$ftype,$fnotnull,$fdefault,$fautoinc,$fconstraint,$funsigned)
143
	{
144
		$suffix = '';
145
		if (strlen($fdefault)) $suffix .= " DEFAULT $fdefault";
146
		if ($fautoinc) $suffix .= ' DEFAULT AUTOINCREMENT';
147
		if ($fnotnull) $suffix .= ' NOT NULL';
148
		else if ($suffix == '') $suffix .= ' NULL';
149
		if ($fconstraint) $suffix .= ' '.$fconstraint;
150
		return $suffix;
151
	}
152
 
153
	/*
154
CREATE TABLE
155
    [ database_name.[ owner ] . | owner. ] table_name
156
    ( { < column_definition >
157
        | column_name AS computed_column_expression
158
        | < table_constraint > ::= [ CONSTRAINT constraint_name ] }
159
 
160
            | [ { PRIMARY KEY | UNIQUE } [ ,...n ]
161
    )
162
 
163
[ ON { filegroup | DEFAULT } ]
164
[ TEXTIMAGE_ON { filegroup | DEFAULT } ]
165
 
166
< column_definition > ::= { column_name data_type }
167
    [ COLLATE < collation_name > ]
168
    [ [ DEFAULT constant_expression ]
169
        | [ IDENTITY [ ( seed , increment ) [ NOT FOR REPLICATION ] ] ]
170
    ]
171
    [ ROWGUIDCOL]
172
    [ < column_constraint > ] [ ...n ]
173
 
174
< column_constraint > ::= [ CONSTRAINT constraint_name ]
175
    { [ NULL | NOT NULL ]
176
        | [ { PRIMARY KEY | UNIQUE }
177
            [ CLUSTERED | NONCLUSTERED ]
178
            [ WITH FILLFACTOR = fillfactor ]
179
            [ON {filegroup | DEFAULT} ] ]
180
        ]
181
        | [ [ FOREIGN KEY ]
182
            REFERENCES ref_table [ ( ref_column ) ]
183
            [ ON DELETE { CASCADE | NO ACTION } ]
184
            [ ON UPDATE { CASCADE | NO ACTION } ]
185
            [ NOT FOR REPLICATION ]
186
        ]
187
        | CHECK [ NOT FOR REPLICATION ]
188
        ( logical_expression )
189
    }
190
 
191
< table_constraint > ::= [ CONSTRAINT constraint_name ]
192
    { [ { PRIMARY KEY | UNIQUE }
193
        [ CLUSTERED | NONCLUSTERED ]
194
        { ( column [ ASC | DESC ] [ ,...n ] ) }
195
        [ WITH FILLFACTOR = fillfactor ]
196
        [ ON { filegroup | DEFAULT } ]
197
    ]
198
    | FOREIGN KEY
199
        [ ( column [ ,...n ] ) ]
200
        REFERENCES ref_table [ ( ref_column [ ,...n ] ) ]
201
        [ ON DELETE { CASCADE | NO ACTION } ]
202
        [ ON UPDATE { CASCADE | NO ACTION } ]
203
        [ NOT FOR REPLICATION ]
204
    | CHECK [ NOT FOR REPLICATION ]
205
        ( search_conditions )
206
    }
207
 
208
 
209
	*/
210
 
211
	/*
212
	CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
213
    ON { table | view } ( column [ ASC | DESC ] [ ,...n ] )
214
		[ WITH < index_option > [ ,...n] ]
215
		[ ON filegroup ]
216
		< index_option > :: =
217
		    { PAD_INDEX |
218
		        FILLFACTOR = fillfactor |
219
		        IGNORE_DUP_KEY |
220
		        DROP_EXISTING |
221
		    STATISTICS_NORECOMPUTE |
222
		    SORT_IN_TEMPDB
223
		}
224
*/
225
	function _IndexSQL($idxname, $tabname, $flds, $idxoptions)
226
	{
227
		$sql = array();
228
 
229
		if ( isset($idxoptions['REPLACE']) || isset($idxoptions['DROP']) ) {
230
			$sql[] = sprintf ($this->dropIndex, $idxname, $tabname);
231
			if ( isset($idxoptions['DROP']) )
232
				return $sql;
233
		}
234
 
235
		if ( empty ($flds) ) {
236
			return $sql;
237
		}
238
 
239
		$unique = isset($idxoptions['UNIQUE']) ? ' UNIQUE' : '';
240
		$clustered = isset($idxoptions['CLUSTERED']) ? ' CLUSTERED' : '';
241
 
242
		if ( is_array($flds) )
243
			$flds = implode(', ',$flds);
244
		$s = 'CREATE' . $unique . $clustered . ' INDEX ' . $idxname . ' ON ' . $tabname . ' (' . $flds . ')';
245
 
246
		if ( isset($idxoptions[$this->upperName]) )
247
			$s .= $idxoptions[$this->upperName];
248
 
249
		$sql[] = $s;
250
 
251
		return $sql;
252
	}
253
}