Subversion-Projekte lars-tiefland.ci

Revision

Revision 2257 | 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
 *
2414 lars 9
 * Copyright (c) 2014 - 2019, 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/)
2414 lars 32
 * @copyright	Copyright (c) 2014 - 2019, British Columbia Institute of Technology (https://bcit.ca/)
33
 * @license	https://opensource.org/licenses/MIT	MIT License
68 lars 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 ODBC 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_odbc_driver extends CI_DB_pdo_driver {
54
 
55
	/**
56
	 * Sub-driver
57
	 *
58
	 * @var	string
59
	 */
60
	public $subdriver = 'odbc';
61
 
62
	/**
63
	 * Database schema
64
	 *
65
	 * @var	string
66
	 */
67
	public $schema = 'public';
68
 
69
	// --------------------------------------------------------------------
70
 
71
	/**
72
	 * Identifier escape character
73
	 *
74
	 * Must be empty for ODBC.
75
	 *
76
	 * @var	string
77
	 */
78
	protected $_escape_char = '';
79
 
80
	/**
81
	 * ESCAPE statement string
82
	 *
83
	 * @var	string
84
	 */
85
	protected $_like_escape_str = " {escape '%s'} ";
86
 
87
	/**
88
	 * ORDER BY random keyword
89
	 *
90
	 * @var	array
91
	 */
92
	protected $_random_keyword = array('RND()', 'RND(%d)');
93
 
94
	// --------------------------------------------------------------------
95
 
96
	/**
97
	 * Class constructor
98
	 *
99
	 * Builds the DSN if not already set.
100
	 *
101
	 * @param	array	$params
102
	 * @return	void
103
	 */
104
	public function __construct($params)
105
	{
106
		parent::__construct($params);
107
 
108
		if (empty($this->dsn))
109
		{
110
			$this->dsn = 'odbc:';
111
 
112
			// Pre-defined DSN
113
			if (empty($this->hostname) && empty($this->HOSTNAME) && empty($this->port) && empty($this->PORT))
114
			{
115
				if (isset($this->DSN))
116
				{
117
					$this->dsn .= 'DSN='.$this->DSN;
118
				}
119
				elseif ( ! empty($this->database))
120
				{
121
					$this->dsn .= 'DSN='.$this->database;
122
				}
123
 
124
				return;
125
			}
126
 
127
			// If the DSN is not pre-configured - try to build an IBM DB2 connection string
128
			$this->dsn .= 'DRIVER='.(isset($this->DRIVER) ? '{'.$this->DRIVER.'}' : '{IBM DB2 ODBC DRIVER}').';';
129
 
130
			if (isset($this->DATABASE))
131
			{
132
				$this->dsn .= 'DATABASE='.$this->DATABASE.';';
133
			}
134
			elseif ( ! empty($this->database))
135
			{
136
				$this->dsn .= 'DATABASE='.$this->database.';';
137
			}
138
 
139
			if (isset($this->HOSTNAME))
140
			{
141
				$this->dsn .= 'HOSTNAME='.$this->HOSTNAME.';';
142
			}
143
			else
144
			{
145
				$this->dsn .= 'HOSTNAME='.(empty($this->hostname) ? '127.0.0.1;' : $this->hostname.';');
146
			}
147
 
148
			if (isset($this->PORT))
149
			{
150
				$this->dsn .= 'PORT='.$this->port.';';
151
			}
152
			elseif ( ! empty($this->port))
153
			{
154
				$this->dsn .= ';PORT='.$this->port.';';
155
			}
156
 
157
			$this->dsn .= 'PROTOCOL='.(isset($this->PROTOCOL) ? $this->PROTOCOL.';' : 'TCPIP;');
158
		}
159
	}
160
 
161
	// --------------------------------------------------------------------
162
 
163
	/**
2107 lars 164
	 * Platform-dependent string escape
68 lars 165
	 *
166
	 * @param	string
167
	 * @return	string
168
	 */
169
	protected function _escape_str($str)
170
	{
2107 lars 171
		$this->display_error('db_unsupported_feature');
68 lars 172
	}
173
 
174
	// --------------------------------------------------------------------
175
 
176
	/**
177
	 * Determines if a query is a "write" type.
178
	 *
179
	 * @param	string	An SQL query string
180
	 * @return	bool
181
	 */
182
	public function is_write_type($sql)
183
	{
1257 lars 184
		if (preg_match('#^(INSERT|UPDATE).*RETURNING\s.+(\,\s?.+)*$#is', $sql))
68 lars 185
		{
186
			return FALSE;
187
		}
188
 
189
		return parent::is_write_type($sql);
190
	}
191
 
192
	// --------------------------------------------------------------------
193
 
194
	/**
195
	 * Show table query
196
	 *
197
	 * Generates a platform-specific query string so that the table names can be fetched
198
	 *
199
	 * @param	bool	$prefix_limit
200
	 * @return	string
201
	 */
202
	protected function _list_tables($prefix_limit = FALSE)
203
	{
204
		$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$this->schema."'";
205
 
206
		if ($prefix_limit !== FALSE && $this->dbprefix !== '')
207
		{
208
			return $sql." AND table_name LIKE '".$this->escape_like_str($this->dbprefix)."%' "
209
				.sprintf($this->_like_escape_str, $this->_like_escape_chr);
210
		}
211
 
212
		return $sql;
213
	}
214
 
215
	// --------------------------------------------------------------------
216
 
217
	/**
218
	 * Show column query
219
	 *
220
	 * Generates a platform-specific query string so that the column names can be fetched
221
	 *
222
	 * @param	string	$table
223
	 * @return	string
224
	 */
225
	protected function _list_columns($table = '')
226
	{
227
		return 'SELECT column_name FROM information_schema.columns WHERE table_name = '.$this->escape($table);
228
	}
229
}