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 CUBRID 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_cubrid_driver extends CI_DB_pdo_driver {
54
 
55
	/**
56
	 * Sub-driver
57
	 *
58
	 * @var	string
59
	 */
60
	public $subdriver = 'cubrid';
61
 
62
	/**
63
	 * Identifier escape character
64
	 *
65
	 * @var	string
66
	 */
67
	protected $_escape_char = '`';
68
 
69
	/**
70
	 * ORDER BY random keyword
71
	 *
72
	 * @var array
73
	 */
74
	protected $_random_keyword = array('RANDOM()', 'RANDOM(%d)');
75
 
76
	// --------------------------------------------------------------------
77
 
78
	/**
79
	 * Class constructor
80
	 *
81
	 * Builds the DSN if not already set.
82
	 *
83
	 * @param	array	$params
84
	 * @return	void
85
	 */
86
	public function __construct($params)
87
	{
88
		parent::__construct($params);
89
 
90
		if (empty($this->dsn))
91
		{
92
			$this->dsn = 'cubrid:host='.(empty($this->hostname) ? '127.0.0.1' : $this->hostname);
93
 
94
			empty($this->port) OR $this->dsn .= ';port='.$this->port;
95
			empty($this->database) OR $this->dsn .= ';dbname='.$this->database;
96
			empty($this->char_set) OR $this->dsn .= ';charset='.$this->char_set;
97
		}
98
	}
99
 
100
	// --------------------------------------------------------------------
101
 
102
	/**
103
	 * Show table query
104
	 *
105
	 * Generates a platform-specific query string so that the table names can be fetched
106
	 *
107
	 * @param	bool	$prefix_limit
108
	 * @return	string
109
	 */
110
	protected function _list_tables($prefix_limit = FALSE)
111
	{
112
		$sql = 'SHOW TABLES';
113
 
114
		if ($prefix_limit === TRUE && $this->dbprefix !== '')
115
		{
116
			return $sql." LIKE '".$this->escape_like_str($this->dbprefix)."%'";
117
		}
118
 
119
		return $sql;
120
	}
121
 
122
	// --------------------------------------------------------------------
123
 
124
	/**
125
	 * Show column query
126
	 *
127
	 * Generates a platform-specific query string so that the column names can be fetched
128
	 *
129
	 * @param	string	$table
130
	 * @return	string
131
	 */
132
	protected function _list_columns($table = '')
133
	{
134
		return 'SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE);
135
	}
136
 
137
	// --------------------------------------------------------------------
138
 
139
	/**
140
	 * Returns an object with field data
141
	 *
142
	 * @param	string	$table
143
	 * @return	array
144
	 */
145
	public function field_data($table)
146
	{
147
		if (($query = $this->query('SHOW COLUMNS FROM '.$this->protect_identifiers($table, TRUE, NULL, FALSE))) === FALSE)
148
		{
149
			return FALSE;
150
		}
151
		$query = $query->result_object();
152
 
153
		$retval = array();
154
		for ($i = 0, $c = count($query); $i < $c; $i++)
155
		{
156
			$retval[$i]			= new stdClass();
157
			$retval[$i]->name		= $query[$i]->Field;
158
 
159
			sscanf($query[$i]->Type, '%[a-z](%d)',
160
				$retval[$i]->type,
161
				$retval[$i]->max_length
162
			);
163
 
164
			$retval[$i]->default		= $query[$i]->Default;
165
			$retval[$i]->primary_key	= (int) ($query[$i]->Key === 'PRI');
166
		}
167
 
168
		return $retval;
169
	}
170
 
171
	// --------------------------------------------------------------------
172
 
173
	/**
174
	 * Truncate statement
175
	 *
176
	 * Generates a platform-specific truncate string from the supplied data
177
	 *
178
	 * If the database does not support the TRUNCATE statement,
179
	 * then this method maps to 'DELETE FROM table'
180
	 *
181
	 * @param	string	$table
182
	 * @return	string
183
	 */
184
	protected function _truncate($table)
185
	{
186
		return 'TRUNCATE '.$table;
187
	}
188
 
189
	// --------------------------------------------------------------------
190
 
191
	/**
192
	 * FROM tables
193
	 *
194
	 * Groups tables in FROM clauses if needed, so there is no confusion
195
	 * about operator precedence.
196
	 *
197
	 * @return	string
198
	 */
199
	protected function _from_tables()
200
	{
201
		if ( ! empty($this->qb_join) && count($this->qb_from) > 1)
202
		{
203
			return '('.implode(', ', $this->qb_from).')';
204
		}
205
 
206
		return implode(', ', $this->qb_from);
207
	}
208
 
209
}