├── README.md ├── documentation ├── .svn │ ├── entries │ └── text-base │ │ ├── css.css.svn-base │ │ └── sqlrelay_api.html.svn-base ├── css.css └── sqlrelay_api.html ├── index.html ├── sqlrelay_driver.php ├── sqlrelay_forge.php ├── sqlrelay_result.php └── sqlrelay_utility.php /README.md: -------------------------------------------------------------------------------- 1 | CodeIgniter Sqlrelay Adapter Prepare 2 | based on CodeIgniter v2.1.0 3 | 4 | 5 | 1. database.php config 6 | 7 | Application/config/database.php 8 | 9 | $db['dbsqlrelay']['hostname'] = 'hostname'; 10 | $db['dbsqlrelay']['port'] = 'portnumber'; 11 | $db['dbsqlrelay']['username'] = 'username'; 12 | $db['dbsqlrelay']['password'] = 'password'; 13 | $db['dbsqlrelay']['database'] = ''; 14 | $db['dbsqlrelay']['dbdriver'] = 'sqlrelay'; 15 | $db['dbsqlrelay']['dbcase'] = 'oci8'; 16 | 17 | 2. Sqlrelay Adapter Add 18 | System/database/driver/sqlrelay 19 | 20 | - Sqlrelay_driver.php 21 | - Sqlrelay_result.php 22 | - Sqlrelay_forge.php 23 | - Sqlrelay_utility.php 24 | 25 | ##### Bug? (because use sqlrelay) 26 | 27 | System/database/driver/oci8/oci8_driver.php 28 | 29 | $_commit = ""; 30 | $escape_str =""; 31 | 32 | 33 | CodeIgniter Sqlrelay Adapter Function 34 | - 35 | 36 | 37 | 1. common use 38 | 39 | http://codeigniter.com/user_guide/database/index.html 40 | 41 | use same codeigniter methods. 42 | 43 | 2. function stored procedure() 44 | 45 | case1. only input variable 46 | 47 | $params = array( 48 | array('name'=>':variable1','value'=>'value'), 49 | array('name'=>':variable2','value'=>'value') 50 | ); 51 | 52 | $query = $this->db->stored procedure($package, $procedure, $params); 53 | foreach($query->result() as $row) // return sqlrelay resource_id 54 | { 55 | echo $row->colname; 56 | } 57 | 58 | case2. output variable 59 | 60 | $params = array( 61 | array('name'=>':variable1','value'=>'value'), 62 | array('name'=>':variable2','value'=>'@out') 63 | ); 64 | $query = $this->db->stored procedure($package, $procedure, $params); 65 | foreach($query as $k=>$v) // return common array 66 | { 67 | echo "$k / $v"; 68 | } 69 | 70 | 71 | 3. unsupported_function 72 | 73 | - function reconnect() 74 | - function db_select() 75 | - function db_set_charset() 76 | - function insert_id() 77 | - function _error_number() 78 | 79 | -------------------------------------------------------------------------------- /documentation/.svn/entries: -------------------------------------------------------------------------------- 1 | 10 2 | 3 | dir 4 | 426 5 | svn+ssh://jjang9b@cow.pmang.com/svnroot/NeoCS/dev/sqlrelay_v.0.7/documentation 6 | svn+ssh://jjang9b@cow.pmang.com/svnroot/NeoCS 7 | 8 | 9 | 10 | 2012-03-12T02:40:27.502556Z 11 | 413 12 | jjang9b 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | ea9355d4-033e-4161-925d-26adea21c4fd 28 | 29 | css.css 30 | file 31 | 32 | 33 | 34 | 35 | 2012-03-28T05:34:59.238938Z 36 | 51ec1848e6e942e998696145defd6e84 37 | 2011-08-26T08:37:18.700481Z 38 | 277 39 | jjang9b 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 528 62 | 63 | sqlrelay_api.html 64 | file 65 | 66 | 67 | 68 | 69 | 2012-03-28T05:34:59.245938Z 70 | 332e2d64c003a472bf35c2580456a5ca 71 | 2012-03-12T02:40:27.502556Z 72 | 413 73 | jjang9b 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 2813 96 | 97 | -------------------------------------------------------------------------------- /documentation/.svn/text-base/css.css.svn-base: -------------------------------------------------------------------------------- 1 | body { 2 | background: #ffffff; 3 | color: #696969; 4 | font-size: 13pt; 5 | line-height: 150%; 6 | font-family: times, Times New Roman, times-roman, georgia, serif, 맑은고딕; 7 | max-width: 30em; 8 | margin: 0 0 5em 9em; 9 | } 10 | h1 code, h2 code, h3 code, h4 code, 11 | h1 a, h2 a, h3 a, h4 a 12 | { 13 | color: inherit; 14 | font-size: inherit; 15 | } 16 | 17 | pre, code { 18 | font-family: Bitstream Vera Sans Mono; 19 | font-size: 10pt; 20 | color: #2f4f4f; 21 | } 22 | 23 | pre { 24 | padding-left: 1em; 25 | border-left: 1px solid #a9a9a9; 26 | } 27 | 28 | a { color: #800000; text-decoration : none;} -------------------------------------------------------------------------------- /documentation/.svn/text-base/sqlrelay_api.html.svn-base: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Sqlrelay Adapter API 5 | 6 | 7 | 8 | Prepare 9 | Function 10 | 11 |

 

12 | 13 | CodeIgniter Sqlrelay Adapter Prepare
14 | based on CodeIgniter v2.1.0 15 |

16 | 17 | 18 | 1. database.php config 19 |

 20 | 	Application/config/database.php
 21 | 	
 22 | 	ex)
 23 | 	$db['dbsqlrelay']['hostname'] = 'hostname';
 24 | 	$db['dbsqlrelay']['port'] = 'portnumber'; 
 25 | 	$db['dbsqlrelay']['username'] = 'username';
 26 | 	$db['dbsqlrelay']['password'] = 'password';
 27 | 	$db['dbsqlrelay']['database'] = '';
 28 | 	$db['dbsqlrelay']['dbdriver'] = 'sqlrelay';
 29 | 	$db['dbsqlrelay']['dbcase'] = 'oci8';
 30 | 	
31 | 32 | 2. Sqlrelay Adapter Add 33 |
 34 | 	System/database/driver/sqlrelay
 35 | 	
 36 | 	- Sqlrelay_driver.php
 37 | 	- Sqlrelay_result.php
 38 | 	- Sqlrelay_forge.php
 39 | 	- Sqlrelay_utility.php
 40 | 	
41 | 42 | 3. Bug? (because use sqlrelay) 43 |
 44 | 	System/database/driver/oci8/oci8_driver.php
 45 | 	$_commit = "";
 46 | 	$escape_str ="";
 47 | 	
48 | 49 |

 

50 |

 

51 | 52 |

53 | CodeIgniter Sqlrelay Adapter Function 54 |

55 | 56 | 1. common use 57 |
 58 | 	http://codeigniter.com/user_guide/database/index.html
 59 | 	use same codeigniter methods.
 60 | 	
61 |

 

62 | 63 | 2. function stored procedure() 64 |
 65 | 	case1. only input variable
 66 | 		$params = array(
 67 | 			array('name'=>':variable1','value'=>'value'),
 68 | 			array('name'=>':variable2','value'=>'value')
 69 | 		);
 70 | 
 71 | 		$query = $this->db->stored procedure($package, $procedure, $params);
 72 | 		foreach($query->result() as $row)				// return sqlrelay resource_id
 73 | 		{
 74 | 			echo $row->colname;
 75 | 		}
 76 | 	
 77 | 	case2. output variable
 78 | 		$params = array(
 79 | 				array('name'=>':variable1','value'=>'value'),
 80 | 				array('name'=>':variable2','value'=>'@out')
 81 | 				);
 82 | 		$query = $this->db->stored procedure($package, $procedure, $params);
 83 | 		foreach($query as $k=>$v)					// return common array
 84 | 		{
 85 | 			echo "$k / $v";
 86 | 		}
 87 | 	
88 | 89 | 3. unsupported_function 90 |
 91 | 	 - function reconnect()
 92 | 	 - function db_select()
 93 | 	 - function db_set_charset()
 94 | 	 - function insert_id()
 95 | 	 - function _error_number()
 96 | 	
97 | 98 | 99 | 100 |
101 | Copyright 2012, BBin
102 | jjang9b@gmail.com 103 |
104 | 105 | 106 | -------------------------------------------------------------------------------- /documentation/css.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #ffffff; 3 | color: #696969; 4 | font-size: 13pt; 5 | line-height: 150%; 6 | font-family: times, Times New Roman, times-roman, georgia, serif, 맑은고딕; 7 | max-width: 30em; 8 | margin: 0 0 5em 9em; 9 | } 10 | h1 code, h2 code, h3 code, h4 code, 11 | h1 a, h2 a, h3 a, h4 a 12 | { 13 | color: inherit; 14 | font-size: inherit; 15 | } 16 | 17 | pre, code { 18 | font-family: Bitstream Vera Sans Mono; 19 | font-size: 10pt; 20 | color: #2f4f4f; 21 | } 22 | 23 | pre { 24 | padding-left: 1em; 25 | border-left: 1px solid #a9a9a9; 26 | } 27 | 28 | a { color: #800000; text-decoration : none;} -------------------------------------------------------------------------------- /documentation/sqlrelay_api.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Sqlrelay Adapter API 5 | 6 | 7 | 8 | Prepare 9 | Function 10 | 11 |

 

12 | 13 | CodeIgniter Sqlrelay Adapter Prepare
14 | based on CodeIgniter v2.1.0 15 |

16 | 17 | 18 | 1. database.php config 19 |

 20 | 	Application/config/database.php
 21 | 	
 22 | 	ex)
 23 | 	$db['dbsqlrelay']['hostname'] = 'hostname';
 24 | 	$db['dbsqlrelay']['port'] = 'portnumber'; 
 25 | 	$db['dbsqlrelay']['username'] = 'username';
 26 | 	$db['dbsqlrelay']['password'] = 'password';
 27 | 	$db['dbsqlrelay']['database'] = '';
 28 | 	$db['dbsqlrelay']['dbdriver'] = 'sqlrelay';
 29 | 	$db['dbsqlrelay']['dbcase'] = 'oci8';
 30 | 	
31 | 32 | 2. Sqlrelay Adapter Add 33 |
 34 | 	System/database/driver/sqlrelay
 35 | 	
 36 | 	- Sqlrelay_driver.php
 37 | 	- Sqlrelay_result.php
 38 | 	- Sqlrelay_forge.php
 39 | 	- Sqlrelay_utility.php
 40 | 	
41 | 42 | 3. Bug? (because use sqlrelay) 43 |
 44 | 	System/database/driver/oci8/oci8_driver.php
 45 | 	$_commit = "";
 46 | 	$escape_str ="";
 47 | 	
48 | 49 |

 

50 |

 

51 | 52 |

53 | CodeIgniter Sqlrelay Adapter Function 54 |

55 | 56 | 1. common use 57 |
 58 | 	http://codeigniter.com/user_guide/database/index.html
 59 | 	use same codeigniter methods.
 60 | 	
61 |

 

62 | 63 | 2. function stored procedure() 64 |
 65 | 	case1. only input variable
 66 | 		$params = array(
 67 | 			array('name'=>':variable1','value'=>'value'),
 68 | 			array('name'=>':variable2','value'=>'value')
 69 | 		);
 70 | 
 71 | 		$query = $this->db->stored procedure($package, $procedure, $params);
 72 | 		foreach($query->result() as $row)				// return sqlrelay resource_id
 73 | 		{
 74 | 			echo $row->colname;
 75 | 		}
 76 | 	
 77 | 	case2. output variable
 78 | 		$params = array(
 79 | 				array('name'=>':variable1','value'=>'value'),
 80 | 				array('name'=>':variable2','value'=>'@out')
 81 | 				);
 82 | 		$query = $this->db->stored procedure($package, $procedure, $params);
 83 | 		foreach($query as $k=>$v)					// return common array
 84 | 		{
 85 | 			echo "$k / $v";
 86 | 		}
 87 | 	
88 | 89 | 3. unsupported_function 90 |
 91 | 	 - function reconnect()
 92 | 	 - function db_select()
 93 | 	 - function db_set_charset()
 94 | 	 - function insert_id()
 95 | 	 - function _error_number()
 96 | 	
97 | 98 | 99 | 100 |
101 | Copyright 2012, BBin
102 | jjang9b@gmail.com 103 |
104 | 105 | 106 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 403 Forbidden 4 | 5 | 6 | 7 |

Directory access is forbidden.

8 | 9 | 10 | -------------------------------------------------------------------------------- /sqlrelay_driver.php: -------------------------------------------------------------------------------- 1 | dbcase.'/'.$this->dbcase.'_driver.php'); 41 | $class_name = "CI_DB_".$this->dbcase."_driver"; 42 | 43 | if(! class_exists('CI_DB_each_driver')) 44 | { 45 | eval('class CI_DB_each_driver extends '.$class_name.' 46 | { 47 | function __construct($params) { parent::__construct($params); } 48 | function call_1($method,$a){ return $this->$method($a); } 49 | function call_2($method,$a,$b){ return $this->$method($a,$b); } 50 | function call_3($method,$a,$b,$c){ return $this->$method($a,$b,$c); } 51 | function call_4($method,$a,$b,$c,$d){ return $this->$method($a,$b,$c,$d); } 52 | function call_5($method,$a,$b,$c,$d,$e){ return $this->$method($a,$b,$c,$d,$e); } 53 | }'); 54 | } 55 | $this->CI_sqlrelay_driver = new CI_DB_each_driver($params); 56 | } 57 | 58 | /* 59 | * Non-persistent database connection 60 | * 61 | * @access private called by the base class 62 | * @return resource 63 | */ 64 | 65 | public function db_connect() 66 | { 67 | return sqlrcon_alloc($this->hostname, $this->port, "", $this->username, $this->password, 0, 1); 68 | } 69 | 70 | // -------------------------------------------------------------------- 71 | 72 | /** 73 | * Persistent database connection 74 | * 75 | * @access private called by the base class 76 | * @return resource 77 | */ 78 | 79 | public function db_pconnect() 80 | { 81 | return sqlrcon_alloc($this->hostname, $this->port, "", $this->username, $this->password, 0, 1); 82 | } 83 | 84 | // -------------------------------------------------------------------- 85 | 86 | /** 87 | * Reconnect 88 | * 89 | * Keep / reestablish the db connection if no queries have been 90 | * sent for a length of time exceeding the server's idle timeout 91 | * 92 | * @access public 93 | * @return void 94 | */ 95 | 96 | public function reconnect() 97 | { 98 | // not supported in sqlrelay 99 | return $this->display_error('db_unsupported_function'); 100 | } 101 | 102 | // -------------------------------------------------------------------- 103 | 104 | /** 105 | * Select the database 106 | * 107 | * @access private called by the base class 108 | * @return resource 109 | */ 110 | 111 | public function db_select() 112 | { 113 | // not supported in sqlrelay, but return true; 114 | return TRUE; 115 | } 116 | 117 | // -------------------------------------------------------------------- 118 | 119 | /** 120 | * Set client character set 121 | * 122 | * @access public 123 | * @param string 124 | * @param string 125 | * @return resource 126 | */ 127 | 128 | public function db_set_charset($charset, $collation) 129 | { 130 | // not supported in sqlrelay, but return true; 131 | return TRUE; 132 | 133 | } 134 | 135 | // -------------------------------------------------------------------- 136 | 137 | /** 138 | * Version number query string 139 | * 140 | * @access public 141 | * @return string 142 | */ 143 | 144 | protected function _version() 145 | { 146 | return sqlrcon_dbVersion($this->conn_id); 147 | } 148 | 149 | // -------------------------------------------------------------------- 150 | 151 | /** 152 | * Execute the query 153 | * 154 | * @access private called by the base class 155 | * @param string an SQL query 156 | * @return resource 157 | */ 158 | 159 | protected function _execute($sql) 160 | { 161 | $this->get_cursor(); 162 | sqlrcur_lowerCaseColumnNames($this->curs_id); 163 | 164 | if(!sqlrcur_sendQuery($this->curs_id,$sql)){ 165 | $errstr = sqlrcur_errorMessage($this->curs_id); 166 | echo $errstr; 167 | } 168 | 169 | 170 | return $this->curs_id; 171 | } 172 | 173 | // -------------------------------------------------------------------- 174 | 175 | /** 176 | * Prep the query 177 | * 178 | * If needed, each database adapter can prep the query string 179 | * 180 | * @access private called by execute() 181 | * @param string an SQL query 182 | * @return string 183 | */ 184 | 185 | private function _prep_query($sql) 186 | { 187 | return sqlrcur_prepareQuery($this->curs_id, $sql); 188 | } 189 | 190 | // -------------------------------------------------------------------- 191 | 192 | /** 193 | * getCursor. Returns a cursor from the datbase 194 | * 195 | * @access public 196 | * @return cursor id 197 | */ 198 | 199 | public function get_cursor() 200 | { 201 | return $this->curs_id = sqlrcur_alloc($this->conn_id); 202 | } 203 | 204 | // -------------------------------------------------------------------- 205 | 206 | /** 207 | * Stored Procedure. Executes a stored procedure 208 | * 209 | * @access public 210 | * @param package package stored procedure is in 211 | * @param procedure stored procedure to execute 212 | * @param params array of parameters 213 | * @return array 214 | * 215 | * params array keys 216 | * 217 | * KEY OPTIONAL NOTES 218 | * name no the name of the parameter should be in : format 219 | * value no the value of the parameter. If this is an OUT or IN OUT parameter, 220 | * this should be a reference to a variable 221 | * type yes the type of the parameter 222 | * length yes the max size of the parameter 223 | */ 224 | 225 | public function stored_procedure($package, $procedure, $params) 226 | { 227 | if($this->dbcase =='oci8') 228 | { 229 | if ($package == '' OR $procedure == '' OR ! is_array($params)) 230 | { 231 | if ($this->db_debug) 232 | { 233 | log_message('error', 'Invalid query: '.$package.'.'.$procedure); 234 | return $this->display_error('db_invalid_query'); 235 | } 236 | return FALSE; 237 | } 238 | 239 | // build the query string 240 | $sql = "begin $package.$procedure("; 241 | 242 | foreach ($params as $param) 243 | { 244 | $sql .= $param['name'] . ","; 245 | } 246 | $sql = trim($sql, ",") . "); end;"; 247 | 248 | $this->get_cursor(); 249 | $this->_prep_query($sql); 250 | $this->_bind_params($params); 251 | 252 | $result = sqlrcur_executeQuery($this->curs_id); 253 | 254 | if($this->output_bool = TRUE) 255 | { 256 | foreach($this->output_name as $k) 257 | { 258 | $this->output_result[$k] = sqlrcur_getOutputBindString($this->curs_id, $k); 259 | } 260 | return $this->output_result; 261 | } 262 | return $result; 263 | } 264 | else 265 | { 266 | return $this->display_error('db_unsupported_function'); 267 | } 268 | } 269 | 270 | // -------------------------------------------------------------------- 271 | 272 | /** 273 | * Bind parameters 274 | * 275 | * @access private 276 | * @return none 277 | */ 278 | 279 | private function _bind_params($params) 280 | { 281 | if ( ! is_array($params)) 282 | { 283 | return; 284 | } 285 | 286 | foreach ($params as $param) 287 | { 288 | foreach (array('name', 'value') as $val) 289 | { 290 | if ( ! isset($param[$val])) 291 | { 292 | $param[$val] = ''; 293 | } 294 | } 295 | $param['name'] = substr($param['name'], 1, strlen($param['name'])); 296 | 297 | if(strtolower($param['value']) == '@out') 298 | { 299 | sqlrcur_defineOutputBindString($this->curs_id, $param['name'], 1000); 300 | $this->output_bool = TRUE; 301 | $this->output_name[] = $param['name']; 302 | } 303 | else 304 | { 305 | sqlrcur_inputBind($this->curs_id, $param['name'], $param['value']); 306 | } 307 | } 308 | } 309 | 310 | // -------------------------------------------------------------------- 311 | 312 | /** 313 | * Begin Transaction 314 | * 315 | * @access public 316 | * @return bool 317 | */ 318 | 319 | public function trans_begin($test_mode = FALSE) 320 | { 321 | if ( ! $this->trans_enabled) 322 | { 323 | return TRUE; 324 | } 325 | 326 | // When transactions are nested we only begin/commit/rollback the outermost ones 327 | if ($this->_trans_depth > 0) 328 | { 329 | return TRUE; 330 | } 331 | 332 | $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE; 333 | sqlrcon_autoCommitOff($this->conn_id); 334 | return TRUE; 335 | } 336 | 337 | // -------------------------------------------------------------------- 338 | 339 | /** 340 | * Commit Transaction 341 | * 342 | * @access public 343 | * @return bool 344 | */ 345 | 346 | public function trans_commit() 347 | { 348 | if ( ! $this->trans_enabled) 349 | { 350 | return TRUE; 351 | } 352 | 353 | // When transactions are nested we only begin/commit/rollback the outermost ones 354 | if ($this->_trans_depth > 0) 355 | { 356 | return TRUE; 357 | } 358 | 359 | $ref = sqlrcon_commit($this->conn_id); 360 | if($this->dbcase == 'oci8' OR $this->dbcase == 'odbc' OR $this->dbcase == 'mysql' OR $this->dbcase == 'mysqli' OR $this->dbcase == 'cubrid') 361 | { 362 | sqlrcon_autoCommitOn($this->conn_id); 363 | } 364 | return $ref; 365 | } 366 | 367 | // -------------------------------------------------------------------- 368 | 369 | /** 370 | * Rollback Transaction 371 | * 372 | * @access public 373 | * @return bool 374 | */ 375 | 376 | public function trans_rollback() 377 | { 378 | if ( ! $this->trans_enabled) 379 | { 380 | return TRUE; 381 | } 382 | 383 | // When transactions are nested we only begin/commit/rollback the outermost ones 384 | if ($this->_trans_depth > 0) 385 | { 386 | return TRUE; 387 | } 388 | 389 | $ret = sqlrcon_rollback($this->conn_id); 390 | if($this->dbcase == 'oci8' OR $this->dbcase == 'odbc' OR $this->dbcase == 'mysql' OR $this->dbcase == 'mysqli' OR $this->dbcase == 'cubrid') 391 | { 392 | sqlrcon_autoCommitOn($this->conn_id); 393 | } 394 | return $ret; 395 | } 396 | 397 | // -------------------------------------------------------------------- 398 | 399 | /** 400 | * Escape String 401 | * 402 | * @access public 403 | * @param string 404 | * @param bool whether or not the string will be used in a LIKE condition 405 | * @return string 406 | */ 407 | 408 | public function escape_str($str, $like = FALSE) 409 | { 410 | return $this->CI_sqlrelay_driver->call_2('escape_str', $str, $like); 411 | } 412 | 413 | // -------------------------------------------------------------------- 414 | 415 | /** 416 | * Affected Rows 417 | * 418 | * @access public 419 | * @return integer 420 | */ 421 | 422 | public function affected_rows() 423 | { 424 | return sqlrcur_affectedRows($this->curs_id); 425 | } 426 | 427 | // -------------------------------------------------------------------- 428 | 429 | /** 430 | * Insert ID 431 | * 432 | * @access public 433 | * @return integer 434 | */ 435 | 436 | public function insert_id() 437 | { 438 | // not supported in sqlrelay 439 | return $this->display_error('db_unsupported_function'); 440 | } 441 | 442 | // -------------------------------------------------------------------- 443 | 444 | /** 445 | * "Count All" query 446 | * 447 | * Generates a platform-specific query string that counts all records in 448 | * the specified database 449 | * 450 | * @access public 451 | * @param string 452 | * @return string 453 | */ 454 | 455 | public function count_all($table = "") 456 | { 457 | $_count_string = $this->CI_sqlrelay_driver->_count_string; 458 | 459 | if ($table === "") 460 | { 461 | return 0; 462 | } 463 | 464 | $query = $this->query($_count_string . $this->_protect_identifiers('numrows') . " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE)); 465 | 466 | if ($query->num_rows() == 0) 467 | { 468 | return 0; 469 | } 470 | 471 | $row = $query->row(); 472 | return (int) $row->numrows; 473 | } 474 | 475 | // -------------------------------------------------------------------- 476 | 477 | /** 478 | * Show table query 479 | * 480 | * Generates a platform-specific query string so that the table names can be fetched 481 | * 482 | * @access protected 483 | * @param boolean 484 | * @return string 485 | */ 486 | 487 | protected function _list_tables($prefix_limit = FALSE) 488 | { 489 | return $this->CI_sqlrelay_driver->call_1('_list_tables', $prefix_limit); 490 | } 491 | 492 | // -------------------------------------------------------------------- 493 | 494 | /** 495 | * Show column query 496 | * 497 | * Generates a platform-specific query string so that the column names can be fetched 498 | * 499 | * @access protected 500 | * @param string the table name 501 | * @return string 502 | */ 503 | 504 | protected function _list_columns($table = '') 505 | { 506 | return $this->CI_sqlrelay_driver->call_1('_list_columns', $table); 507 | } 508 | 509 | // -------------------------------------------------------------------- 510 | 511 | /** 512 | * Field data query 513 | * 514 | * Generates a platform-specific query so that the column data can be retrieved 515 | * 516 | * @access protected 517 | * @param string the table name 518 | * @return object 519 | */ 520 | 521 | protected function _field_data($table) 522 | { 523 | return $this->CI_sqlrelay_driver->call_1('_field_data', $table); 524 | } 525 | 526 | // -------------------------------------------------------------------- 527 | 528 | /** 529 | * The error message string 530 | * 531 | * @access protected 532 | * @return string 533 | */ 534 | 535 | protected function _error_message() 536 | { 537 | return sqlrcur_errorMessage($this->curs_id); 538 | } 539 | 540 | // -------------------------------------------------------------------- 541 | 542 | /** 543 | * The error message number 544 | * 545 | * @access protected 546 | * @return integer 547 | */ 548 | 549 | protected function _error_number() 550 | { 551 | // not supported in sqlrelay, but return true; 552 | return ''; 553 | } 554 | 555 | // -------------------------------------------------------------------- 556 | 557 | /** 558 | * Escape the SQL Identifiers 559 | * 560 | * This function escapes column and table names 561 | * 562 | * @access protected 563 | * @param string 564 | * @return string 565 | */ 566 | 567 | protected function _escape_identifiers($item) 568 | { 569 | return $this->CI_sqlrelay_driver->call_1('_escape_identifiers', $item); 570 | } 571 | 572 | // -------------------------------------------------------------------- 573 | 574 | /** 575 | * From Tables 576 | * 577 | * This function implicitly groups FROM tables so there is no confusion 578 | * about operator precedence in harmony with SQL standards 579 | * 580 | * @access protected 581 | * @param type 582 | * @return type 583 | */ 584 | 585 | protected function _from_tables($tables) 586 | { 587 | return $this->CI_sqlrelay_driver->call_1('_from_tables', $tables); 588 | } 589 | 590 | // -------------------------------------------------------------------- 591 | 592 | /** 593 | * Insert statement 594 | * 595 | * Generates a platform-specific insert string from the supplied data 596 | * 597 | * @access protected 598 | * @param string the table name 599 | * @param array the insert keys 600 | * @param array the insert values 601 | * @return string 602 | */ 603 | 604 | protected function _insert($table, $keys, $values) 605 | { 606 | return $this->CI_sqlrelay_driver->call_3('_insert', $table, $keys, $values); 607 | } 608 | 609 | // -------------------------------------------------------------------- 610 | 611 | /** 612 | * Update statement 613 | * 614 | * Generates a platform-specific update string from the supplied data 615 | * 616 | * @access protected 617 | * @param string the table name 618 | * @param array the update data 619 | * @param array the where clause 620 | * @param array the orderby clause 621 | * @param array the limit clause 622 | * @return string 623 | */ 624 | 625 | protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE) 626 | { 627 | return $this->CI_sqlrelay_driver->call_5('_update', $table, $values, $where, $orderby, $limit); 628 | } 629 | 630 | // -------------------------------------------------------------------- 631 | 632 | /** 633 | * Truncate statement 634 | * 635 | * Generates a platform-specific truncate string from the supplied data 636 | * If the database does not support the truncate() command 637 | * This function maps to "DELETE FROM table" 638 | * 639 | * @access protected 640 | * @param string the table name 641 | * @return string 642 | */ 643 | 644 | protected function _truncate($table) 645 | { 646 | return $this->CI_sqlrelay_driver->call_1('_truncate', $table); 647 | } 648 | 649 | // -------------------------------------------------------------------- 650 | 651 | /** 652 | * Delete statement 653 | * 654 | * Generates a platform-specific delete string from the supplied data 655 | * 656 | * @access protected 657 | * @param string the table name 658 | * @param array the where clause 659 | * @param string the limit clause 660 | * @return string 661 | */ 662 | 663 | protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) 664 | { 665 | $params = array('ar_where' => $this->ar_where); 666 | $this->CI_sqlrelay_driver = new CI_DB_each_driver($params); 667 | return $this->CI_sqlrelay_driver->call_4('_delete', $table, $where, $like, $limit); 668 | } 669 | 670 | // -------------------------------------------------------------------- 671 | 672 | /** 673 | * Limit string 674 | * 675 | * Generates a platform-specific LIMIT clause 676 | * 677 | * @access protected 678 | * @param string the sql query string 679 | * @param integer the number of rows to limit the query to 680 | * @param integer the offset value 681 | * @return string 682 | */ 683 | 684 | protected function _limit($sql, $limit, $offset) 685 | { 686 | return $this->CI_sqlrelay_driver->call_3('_limit', $sql, $limit, $offset); 687 | } 688 | 689 | // -------------------------------------------------------------------- 690 | 691 | /** 692 | * Close DB Connection 693 | * 694 | * @access protected 695 | * @param resource 696 | * @return void 697 | */ 698 | 699 | protected function _close($conn_id) 700 | { 701 | sqlrcon_endSession($conn_id); 702 | sqlrcon_free($conn_id); 703 | } 704 | 705 | } 706 | /* End of file sqlrelay_driver.php */ 707 | /* Location: ./system/database/drivers/sqlrelay/sqlrelay_driver.php */ 708 | -------------------------------------------------------------------------------- /sqlrelay_forge.php: -------------------------------------------------------------------------------- 1 | db 34 | $CI =& get_instance(); 35 | $this->db =& $CI->db; 36 | 37 | require_once(BASEPATH.'database/drivers/'.$this->db->dbcase.'/'.$this->db->dbcase.'_forge.php'); 38 | $CI_DB_each_forge = "CI_DB_".$this->db->dbcase."_forge"; 39 | $this->CI_sqlrelay_forge = new $CI_DB_each_forge(); 40 | } 41 | 42 | // -------------------------------------------------------------------- 43 | 44 | /** 45 | * Create database 46 | * 47 | * @access public 48 | * @param string the database name 49 | * @return bool 50 | */ 51 | 52 | function _create_database($name) 53 | { 54 | return $this->CI_sqlrelay_forge->_create_database($name); 55 | } 56 | 57 | // -------------------------------------------------------------------- 58 | 59 | /** 60 | * Drop database 61 | * 62 | * @access private 63 | * @param string the database name 64 | * @return bool 65 | */ 66 | 67 | function _drop_database($name) 68 | { 69 | return $this->CI_sqlrelay_forge->_drop_database($name); 70 | } 71 | 72 | // -------------------------------------------------------------------- 73 | 74 | /** 75 | * Create Table 76 | * 77 | * @access private 78 | * @param string the table name 79 | * @param array the fields 80 | * @param mixed primary key(s) 81 | * @param mixed key(s) 82 | * @param boolean should 'IF NOT EXISTS' be added to the SQL 83 | * @return bool 84 | */ 85 | 86 | function _create_table($table, $fields, $primary_keys, $keys, $if_not_exists) 87 | { 88 | return $this->CI_sqlrelay_forge->_create_table($table, $fields, $primary_keys, $keys, $if_not_exists); 89 | } 90 | 91 | // -------------------------------------------------------------------- 92 | 93 | /** 94 | * Drop Table 95 | * 96 | * @access private 97 | * @return bool 98 | */ 99 | 100 | function _drop_table($table) 101 | { 102 | return $this->CI_sqlrelay_forge->_drop_table($table); 103 | } 104 | 105 | // -------------------------------------------------------------------- 106 | 107 | /** 108 | * Alter table query 109 | * 110 | * Generates a platform-specific query so that a table can be altered 111 | * Called by add_column(), drop_column(), and column_alter(), 112 | * 113 | * @access private 114 | * @param string the ALTER type (ADD, DROP, CHANGE) 115 | * @param string the column name 116 | * @param string the table name 117 | * @param string the column definition 118 | * @param string the default value 119 | * @param boolean should 'NOT NULL' be added 120 | * @param string the field after which we should add the new field 121 | * @return object 122 | */ 123 | 124 | function _alter_table($alter_type, $table, $column_name, $column_definition = '', $default_value = '', $null = '', $after_field = '') 125 | { 126 | return $this->CI_sqlrelay_forge->_alter_table($alter_type, $table, $column_name, $column_definition, $default_value, $nulil, $after_field); 127 | } 128 | 129 | // -------------------------------------------------------------------- 130 | 131 | /** 132 | * Rename a table 133 | * 134 | * Generates a platform-specific query so that a table can be renamed 135 | * 136 | * @access private 137 | * @param string the old table name 138 | * @param string the new table name 139 | * @return string 140 | */ 141 | 142 | function _rename_table($table_name, $new_table_name) 143 | { 144 | return $this->CI_sqlrelay_forge->_rename_table($table_name, $new_table_name); 145 | } 146 | 147 | } 148 | 149 | /* End of file sqlrelay_forge.php */ 150 | /* Location: ./system/database/drivers/sqlrelay/sqlrelay_forge.php */ 151 | -------------------------------------------------------------------------------- /sqlrelay_result.php: -------------------------------------------------------------------------------- 1 | result_id); 38 | } 39 | 40 | // -------------------------------------------------------------------- 41 | 42 | /** 43 | * Number of fields in the result set 44 | * 45 | * @access public 46 | * @return integer 47 | */ 48 | public function num_fields() 49 | { 50 | return sqlrcur_colCount($this->result_id); 51 | } 52 | 53 | // -------------------------------------------------------------------- 54 | 55 | /** 56 | * Fetch Field Names 57 | * 58 | * Generates an array of column names 59 | * 60 | * @access public 61 | * @return array 62 | */ 63 | public function list_fields() 64 | { 65 | // not use this method; 66 | } 67 | 68 | // -------------------------------------------------------------------- 69 | 70 | /** 71 | * Field data 72 | * 73 | * Generates an array of objects containing field meta-data 74 | * 75 | * @access public 76 | * @return array 77 | */ 78 | public function field_data() 79 | { 80 | $retval = array(); 81 | for($i=0;$iresult_id);$i++) 82 | { 83 | $F = new stdClass(); 84 | $F->name = strtolower(sqlrcur_getColumnName($this->result_id, $i)); 85 | $F->type = sqlrcur_getColumnType($this->result_id, $i); 86 | $F->max_length = sqlrcur_getColumnLength($this->result_id, $i); 87 | $F->primary_key = sqlrcur_getColumnIsPrimaryKey($this->result_id, $i); 88 | $F->default = ''; 89 | 90 | $retval[] = $F; 91 | } 92 | 93 | return $retval; 94 | } 95 | 96 | // -------------------------------------------------------------------- 97 | 98 | /** 99 | * Free the result 100 | * 101 | * @return null 102 | */ 103 | public function free_result() 104 | { 105 | if (is_resource($this->result_id)) 106 | { 107 | sqlrcur_free($this->result_id); 108 | $this->result_id = FALSE; 109 | } 110 | } 111 | 112 | // -------------------------------------------------------------------- 113 | 114 | /** 115 | * Data Seek 116 | * 117 | * Moves the internal pointer to the desired offset. We call 118 | * this internally before fetching results to make sure the 119 | * result set starts at zero 120 | * 121 | * @access protected 122 | * @return array 123 | */ 124 | protected function _data_seek($n = 0) 125 | { 126 | RETURN FALSE; 127 | // not use thie method; 128 | } 129 | 130 | // -------------------------------------------------------------------- 131 | 132 | /** 133 | * Result - associative array 134 | * 135 | * Returns the result set as an array 136 | * 137 | * @access protected 138 | * @return array 139 | */ 140 | protected function _fetch_assoc() 141 | { 142 | if(is_int($this->current_row)) 143 | { 144 | $result = $this->_fetch_array(); 145 | if($result != false) 146 | { 147 | foreach($result as $key=>$value) 148 | { 149 | $result[$key] = $value; 150 | } 151 | } 152 | return $result; 153 | } 154 | } 155 | 156 | // -------------------------------------------------------------------- 157 | 158 | /** 159 | * Result - array 160 | * 161 | * Returns the result set as an array 162 | * 163 | * @access private 164 | * @return array 165 | */ 166 | private function _fetch_array() 167 | { 168 | $result = sqlrcur_getRowAssoc($this->result_id, $this->current_row); 169 | $this->current_row++; 170 | return $result; 171 | } 172 | 173 | // -------------------------------------------------------------------- 174 | 175 | /** 176 | * Result - object 177 | * 178 | * Returns the result set as an object 179 | * 180 | * @access protected 181 | * @return object 182 | */ 183 | protected function _fetch_object() 184 | { 185 | if(is_int($this->current_row)) 186 | { 187 | $result = $this->_fetch_array(); 188 | if($result != false) 189 | { 190 | $obj = new stdClass(); 191 | foreach($result as $key=>$value) 192 | { 193 | $obj->{$key} = $value; 194 | } 195 | $result = $obj; 196 | } 197 | return $result; 198 | } 199 | } 200 | 201 | } 202 | /* End of file sqlrelay_result.php */ 203 | /* Location: ./system/database/drivers/sqlrelay/sqlrelay_result.php */ 204 | -------------------------------------------------------------------------------- /sqlrelay_utility.php: -------------------------------------------------------------------------------- 1 | db 34 | $CI =& get_instance(); 35 | $this->db =& $CI->db; 36 | 37 | require_once(BASEPATH.'database/drivers/'.$this->db->dbcase.'/'.$this->db->dbcase.'_utility.php'); 38 | $CI_DB_each_utility = "CI_DB_".$this->db->dbcase."_utility"; 39 | $this->CI_sqlrelay_utility = new $CI_DB_each_utility(); 40 | } 41 | 42 | // -------------------------------------------------------------------- 43 | 44 | /** 45 | * List databases 46 | * 47 | * @access private 48 | * @return bool 49 | */ 50 | 51 | function _list_databases() 52 | { 53 | return $this->CI_sqlrelay_utility->_list_databases(); 54 | } 55 | 56 | // -------------------------------------------------------------------- 57 | 58 | /** 59 | * Optimize table query 60 | * 61 | * Generates a platform-specific query so that a table can be optimized 62 | * 63 | * @access private 64 | * @param string the table name 65 | * @return object 66 | */ 67 | 68 | function _optimize_table($table) 69 | { 70 | return $this->CI_sqlrelay_utility->_optimize_table($table); 71 | } 72 | 73 | // -------------------------------------------------------------------- 74 | 75 | /** 76 | * Repair table query 77 | * 78 | * Generates a platform-specific query so that a table can be repaired 79 | * 80 | * @access private 81 | * @param string the table name 82 | * @return object 83 | */ 84 | 85 | function _repair_table($table) 86 | { 87 | return $this->CI_sqlrelay_utility->_repair_table($table); 88 | } 89 | 90 | // -------------------------------------------------------------------- 91 | 92 | /** 93 | * backup Export 94 | * 95 | * @access private 96 | * @param array Preferences 97 | * @return mixed 98 | */ 99 | 100 | function _backup($params = array()) 101 | { 102 | if($this->db->dbcase == 'mysql') 103 | { 104 | if (count($params) == 0) 105 | { 106 | return FALSE; 107 | } 108 | 109 | // Extract the prefs for simplicity 110 | extract($params); 111 | 112 | // Build the output 113 | $output = ''; 114 | foreach ((array)$tables as $table) 115 | { 116 | // Is the table in the "ignore" list? 117 | if (in_array($table, (array)$ignore, TRUE)) 118 | { 119 | continue; 120 | } 121 | 122 | // Get the table schema 123 | $query = $this->db->query("SHOW CREATE TABLE `".$this->db->database.'`.'.$table); 124 | 125 | // No result means the table name was invalid 126 | if ($query === FALSE) 127 | { 128 | continue; 129 | } 130 | 131 | // Write out the table schema 132 | $output .= '#'.$newline.'# TABLE STRUCTURE FOR: '.$table.$newline.'#'.$newline.$newline; 133 | 134 | if ($add_drop == TRUE) 135 | { 136 | $output .= 'DROP TABLE IF EXISTS '.$table.';'.$newline.$newline; 137 | } 138 | 139 | $i = 0; 140 | $result = $query->result_array(); 141 | foreach ($result[0] as $val) 142 | { 143 | if ($i++ % 2) 144 | { 145 | $output .= $val.';'.$newline.$newline; 146 | } 147 | } 148 | 149 | // If inserts are not needed we're done... 150 | if ($add_insert == FALSE) 151 | { 152 | continue; 153 | } 154 | 155 | // Grab all the data from the current table 156 | $query = $this->db->query("SELECT * FROM {$table}"); 157 | 158 | if ($query->num_rows() == 0) 159 | { 160 | continue; 161 | } 162 | 163 | // Fetch the field names and determine if the field is an 164 | // integer type. We use this info to decide whether to 165 | // surround the data with quotes or not 166 | 167 | $i = 0; 168 | $field_str = ''; 169 | $is_int = array(); 170 | 171 | for($i=0;$iresult_id);$i++) 172 | { 173 | // Most versions of MySQL store timestamp as a string 174 | $is_int[$i] = (in_array( 175 | strtolower(sqlrcur_getColumnType($query->result_id, $i)), 176 | array('tinyint', 'smallint', 'mediumint', 'int', 'bigint'), //, 'timestamp'), 177 | TRUE) 178 | ) ? TRUE : FALSE; 179 | 180 | // Create a string of field names 181 | $field_str .= '`'.sqlrcur_getColumnName($query->result_id, $i).'`, '; 182 | } 183 | 184 | // Trim off the end comma 185 | $field_str = preg_replace( "/, $/" , "" , $field_str); 186 | 187 | 188 | // Build the insert string 189 | foreach ($query->result_array() as $row) 190 | { 191 | $val_str = ''; 192 | 193 | $i = 0; 194 | foreach ($row as $v) 195 | { 196 | // Is the value NULL? 197 | if ($v === NULL) 198 | { 199 | $val_str .= 'NULL'; 200 | } 201 | else 202 | { 203 | // Escape the data if it's not an integer 204 | if ($is_int[$i] == FALSE) 205 | { 206 | $val_str .= $this->db->escape($v); 207 | } 208 | else 209 | { 210 | $val_str .= $v; 211 | } 212 | } 213 | 214 | // Append a comma 215 | $val_str .= ', '; 216 | 217 | // Remove the comma at the end of the string 218 | $val_str = preg_replace( "/, $/" , "" , $val_str); 219 | 220 | // Build the INSERT string 221 | $output .= 'INSERT INTO '.$table.' ('.$field_str.') VALUES ('.$val_str.');'.$newline; 222 | } 223 | 224 | $output .= $newline.$newline; 225 | } 226 | return $output; 227 | } 228 | } 229 | else 230 | { 231 | return $this->db->display_error('db_unsupported_function'); 232 | } 233 | } 234 | 235 | } 236 | /* End of file sqlrelay_utility.php */ 237 | /* Location: ./system/database/drivers/sqlrelay/sqlrelay_utility.php */ 238 | --------------------------------------------------------------------------------