Subversion-Projekte lars-tiefland.ci

Revision

Revision 2242 | Revision 2257 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
68 lars 1
<?php
2
/**
3
 * CodeIgniter
4
 *
5
 * An open source application development framework for PHP
6
 *
7
 * This content is released under the MIT License (MIT)
8
 *
2254 lars 9
 * Copyright (c) 2014 - 2017, British Columbia Institute of Technology
68 lars 10
 *
11
 * Permission is hereby granted, free of charge, to any person obtaining a copy
12
 * of this software and associated documentation files (the "Software"), to deal
13
 * in the Software without restriction, including without limitation the rights
14
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
 * copies of the Software, and to permit persons to whom the Software is
16
 * furnished to do so, subject to the following conditions:
17
 *
18
 * The above copyright notice and this permission notice shall be included in
19
 * all copies or substantial portions of the Software.
20
 *
21
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
 * THE SOFTWARE.
28
 *
29
 * @package	CodeIgniter
30
 * @author	EllisLab Dev Team
31
 * @copyright	Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
2254 lars 32
 * @copyright	Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
68 lars 33
 * @license	http://opensource.org/licenses/MIT	MIT License
34
 * @link	https://codeigniter.com
35
 * @since	Version 3.0.0
36
 * @filesource
37
 */
38
defined('BASEPATH') OR exit('No direct script access allowed');
39
 
40
/**
41
 * PDO IBM DB2 Database Adapter Class
42
 *
43
 * Note: _DB is an extender class that the app controller
44
 * creates dynamically based on whether the query builder
45
 * class is being used or not.
46
 *
47
 * @package		CodeIgniter
48
 * @subpackage	Drivers
49
 * @category	Database
50
 * @author		EllisLab Dev Team
51
 * @link		https://codeigniter.com/user_guide/database/
52
 */
53
class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver {
54
 
55
	/**
56
	 * Sub-driver
57
	 *
58
	 * @var	string
59
	 */
60
	public $subdriver = 'ibm';
61
 
62
	// --------------------------------------------------------------------
63
 
64
	/**
65
	 * Class constructor
66
	 *
67
	 * Builds the DSN if not already set.
68
	 *
69
	 * @param	array	$params
70
	 * @return	void
71
	 */
72
	public function __construct($params)
73
	{
74
		parent::__construct($params);
75
 
76
		if (empty($this->dsn))
77
		{
78
			$this->dsn = 'ibm:';
79
 
80
			// Pre-defined DSN
81
			if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
82
			{
83
				if (isset($this->DSN))
84
				{
85
					$this->dsn .= 'DSN='.$this->DSN;
86
				}
87
				elseif ( ! empty($this->database))
88
				{
89
					$this->dsn .= 'DSN='.$this->database;
90
				}
91
 
92
				return;
93
			}
94
 
95
			$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
96
 
97
			if (isset($this->DATABASE))
98
			{
99
				$this->dsn .= 'DATABASE='.$this->DATABASE.';';
100
			}
101
			elseif ( ! empty($this->database))
102
			{
103
				$this->dsn .= 'DATABASE='.$this->database.';';
104
			}
105
 
106
			if (isset($this->HOSTNAME))
107
			{
108
				$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
109
			}
110
			else
111
			{
112
				$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
113
			}
114
 
115
			if (isset($this->PORT))
116
			{
117
				$this->dsn .= 'PORT='.$this->port.';';
118
			}
119
			elseif ( ! empty($this->port))
120
			{
121
				$this->dsn .= ';PORT='.$this->port.';';
122
			}
123
 
124
			$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
125
		}
126
	}
127
 
128
	// --------------------------------------------------------------------
129
 
130
	/**
131
	 * Show table query
132
	 *
133
	 * Generates a platform-specific query string so that the table names can be fetched
134
	 *
135
	 * @param	bool	$prefix_limit
136
	 * @return	string
137
	 */
138
	protected function _list_tables($prefix_limit = FALSE)
139
	{
140
		$sql = 'SELECT "tabname" FROM "syscat"."tables"
141
			WHERE "type" = \'T\' AND LOWER("tabschema") = '.$this->escape(strtolower($this->database));
142
 
143
		if ($prefix_limit === TRUE && $this->dbprefix !== '')
144
		{
145
			$sql .= ' AND "tabname" LIKE \''.$this->escape_like_str($this->dbprefix)."%' "
146
				.sprintf($this->_like_escape_str, $this->_like_escape_chr);
147
		}
148
 
149
		return $sql;
150
	}
151
 
152
	// --------------------------------------------------------------------
153
 
154
	/**
155
	 * Show column query
156
	 *
157
	 * Generates a platform-specific query string so that the column names can be fetched
158
	 *
159
	 * @param	string	$table
160
	 * @return	array
161
	 */
162
	protected function _list_columns($table = '')
163
	{
164
		return 'SELECT "colname" FROM "syscat"."columns"
165
			WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
166
				AND LOWER("tabname") = '.$this->escape(strtolower($table));
167
	}
168
 
169
	// --------------------------------------------------------------------
170
 
171
	/**
172
	 * Returns an object with field data
173
	 *
174
	 * @param	string	$table
175
	 * @return	array
176
	 */
177
	public function field_data($table)
178
	{
179
		$sql = 'SELECT "colname" AS "name", "typename" AS "type", "default" AS "default", "length" AS "max_length",
180
				CASE "keyseq" WHEN NULL THEN 0 ELSE 1 END AS "primary_key"
181
			FROM "syscat"."columns"
182
			WHERE LOWER("tabschema") = '.$this->escape(strtolower($this->database)).'
183
				AND LOWER("tabname") = '.$this->escape(strtolower($table)).'
184
			ORDER BY "colno"';
185
 
186
		return (($query = $this->query($sql)) !== FALSE)
187
			? $query->result_object()
188
			: FALSE;
189
	}
190
 
191
	// --------------------------------------------------------------------
192
 
193
	/**
194
	 * Update statement
195
	 *
196
	 * Generates a platform-specific update string from the supplied data
197
	 *
198
	 * @param	string	$table
199
	 * @param	array	$values
200
	 * @return	string
201
	 */
202
	protected function _update($table, $values)
203
	{
204
		$this->qb_limit = FALSE;
205
		$this->qb_orderby = array();
206
		return parent::_update($table, $values);
207
	}
208
 
209
	// --------------------------------------------------------------------
210
 
211
	/**
212
	 * Delete statement
213
	 *
214
	 * Generates a platform-specific delete string from the supplied data
215
	 *
216
	 * @param	string	$table
217
	 * @return	string
218
	 */
219
	protected function _delete($table)
220
	{
221
		$this->qb_limit = FALSE;
222
		return parent::_delete($table);
223
	}
224
 
225
	// --------------------------------------------------------------------
226
 
227
	/**
228
	 * LIMIT
229
	 *
230
	 * Generates a platform-specific LIMIT clause
231
	 *
232
	 * @param	string	$sql	SQL Query
233
	 * @return	string
234
	 */
235
	protected function _limit($sql)
236
	{
237
		$sql .= ' FETCH FIRST '.($this->qb_limit + $this->qb_offset).' ROWS ONLY';
238
 
239
		return ($this->qb_offset)
240
			? 'SELECT * FROM ('.$sql.') WHERE rownum > '.$this->qb_offset
241
			: $sql;
242
	}
243
 
244
}