Fixes for KH 3.3 - to do with case file names
This commit is contained in:
13
application/classes/Database/Exception.php
Normal file
13
application/classes/Database/Exception.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Exception
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Database_Exception extends Kohana_Database_Exception {
|
||||
}
|
||||
?>
|
63
application/classes/Database/Result.php
Normal file
63
application/classes/Database/Result.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database show result. See [Results](/database/results) for usage and examples.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Query/Show
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
abstract class Database_Result extends Kohana_Database_Result {
|
||||
protected $_internal_row = 0;
|
||||
protected $_rows;
|
||||
|
||||
// Required Abstract Classes
|
||||
public function __destruct() {}
|
||||
|
||||
public function seek($offset) {
|
||||
if ($this->offsetExists($offset)) {
|
||||
// Set the current row to the offset
|
||||
$this->_current_row = $this->_internal_row = $offset;
|
||||
|
||||
return TRUE;
|
||||
|
||||
} else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
public function current() {
|
||||
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
|
||||
return FALSE;
|
||||
|
||||
// Return an stdClass
|
||||
if ($this->_as_object === TRUE) {
|
||||
return $this;
|
||||
|
||||
} elseif (is_string($this->_as_object)) {
|
||||
// Return an object of given class name
|
||||
$o = new $this->_as_object;
|
||||
|
||||
return $o->load_object($this->_rows[$this->_current_row]);
|
||||
|
||||
// Return an array of the row
|
||||
} else {
|
||||
return $this->_rows[$this->_current_row];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a row value from the query
|
||||
*
|
||||
* TSM returns all columns in upper case
|
||||
*/
|
||||
public function get($name, $default = NULL) {
|
||||
$name = strtoupper($name);
|
||||
|
||||
return parent::get($name,$default);
|
||||
}
|
||||
}
|
||||
?>
|
114
application/classes/Database/TSM.php
Normal file
114
application/classes/Database/TSM.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database connection.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Drivers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
abstract class Database_TSM extends Database {
|
||||
// Database in use by each connection
|
||||
protected static $_current_databases = array();
|
||||
|
||||
// Use SET NAMES to set the character set
|
||||
protected static $_set_names;
|
||||
|
||||
// Identifier for this connection within the PHP driver
|
||||
protected $_connection_id;
|
||||
|
||||
// TSM does not use a backtick for identifiers
|
||||
protected $_identifier = '';
|
||||
|
||||
// Our TSM Message Format
|
||||
protected $msg_format = '[A-Z]{3}[0-9]{4}[I|E|W|S]';
|
||||
|
||||
// Our Message Codes stored in the last query
|
||||
protected $_query_msg_codes = array();
|
||||
|
||||
// Our return code error messages we can ignore
|
||||
protected $ignore_codes = array(
|
||||
'ANS8001I', // Return code %s.
|
||||
);
|
||||
// Our return code error messages we can ignore
|
||||
protected $nodata_codes = array(
|
||||
'ANR2034E', // SELECT: No match found using this criteria.
|
||||
);
|
||||
|
||||
protected $execute_stdout = '';
|
||||
protected $execute_stderr = '';
|
||||
protected $execute_rc = NULL;
|
||||
|
||||
// Our required abstract methods
|
||||
public function begin($mode = NULL) {}
|
||||
public function commit() {}
|
||||
public function rollback() {}
|
||||
public function set_charset($charset) {}
|
||||
public function list_tables($like = NULL) {}
|
||||
|
||||
// Required methods
|
||||
abstract protected function execute($sql);
|
||||
|
||||
/**
|
||||
* Return the caching defined in the current configuration.
|
||||
*
|
||||
* $cache_time = $db->caching("table");
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function caching($table) {
|
||||
return ($this->_config['caching'] AND isset($this->_config['cache'][$table])) ? $this->_config['cache'][$table] : FALSE;
|
||||
}
|
||||
|
||||
private function clear() {
|
||||
$this->_query_msg_codes = array();
|
||||
}
|
||||
|
||||
public function query($type, $sql, $as_object = FALSE, array $params = NULL) {
|
||||
// Make sure the database is connected
|
||||
if (! $this->_connection && ! $this->connect())
|
||||
return new Database_TSM_Result(array(),'',$as_object,$params);
|
||||
|
||||
$this->clear();
|
||||
|
||||
if ( ! empty($this->_config['profiling']))
|
||||
// Benchmark this query for the current instance
|
||||
$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
|
||||
|
||||
// Execute the query
|
||||
$result = $this->execute($sql);
|
||||
|
||||
if ($this->execute_stderr AND $this->execute_rc) {
|
||||
// This benchmark is worthless
|
||||
if (isset($benchmark))
|
||||
Profiler::delete($benchmark);
|
||||
|
||||
SystemMessage::TSM('error',sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
|
||||
}
|
||||
|
||||
if (isset($benchmark))
|
||||
Profiler::stop($benchmark);
|
||||
|
||||
// Set the last query
|
||||
$this->last_query = $sql;
|
||||
|
||||
if ($type === Database::SELECT)
|
||||
// Return an iterator of results
|
||||
return new Database_TSM_Result($result, $sql, $as_object, $params);
|
||||
elseif ($type === Database::INSERT)
|
||||
throw new Kohana_Exception('Database INSERTS are not supported');
|
||||
elseif ($type === Database::SHOW)
|
||||
return new Database_TSM_Show($result, $sql, $as_object, $params);
|
||||
elseif ($type === Database::SET)
|
||||
return new Database_TSM_Set($result, $sql, $as_object, $params);
|
||||
}
|
||||
|
||||
public function escape($value) {
|
||||
// SQL standard is to use single-quotes for all values
|
||||
return "'$value'";
|
||||
}
|
||||
}
|
||||
?>
|
163
application/classes/Database/TSM/DB2.php
Normal file
163
application/classes/Database/TSM/DB2.php
Normal file
@@ -0,0 +1,163 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database connection using DB2.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Drivers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Database_TSM_DB2 extends Database_TSM {
|
||||
public function connect() {
|
||||
if ($this->_connection)
|
||||
return;
|
||||
|
||||
// Extract the connection parameters, adding required variabels
|
||||
extract($this->_config['connection'] + array(
|
||||
'database' => '',
|
||||
'hostname' => '',
|
||||
'username' => '',
|
||||
'port' => '',
|
||||
'password' => '',
|
||||
'persistent' => FALSE,
|
||||
));
|
||||
|
||||
// Get user login details from user session - these are set by login
|
||||
if (! $username)
|
||||
$username = Session::instance()->get_once(Kohana::config('auth.session_key'));
|
||||
if (! $password)
|
||||
$password = Session::instance()->get_once('password');
|
||||
|
||||
// Prevent this information from showing up in traces
|
||||
unset($this->_config['connection']['username'], $this->_config['connection']['password']);
|
||||
|
||||
if (! $username OR ! $password)
|
||||
HTTP::redirect('login');
|
||||
|
||||
try {
|
||||
if ($persistent) {
|
||||
// Create a persistent connection
|
||||
throw new Kohana_Exception('Cant do persistant connections');
|
||||
|
||||
} else {
|
||||
// Create a connection and force it to be a new link
|
||||
$constring = sprintf('DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=%s;UID=%s;PWD=%s',
|
||||
$database,$hostname,$port,'TCPIP',$username,$password);
|
||||
|
||||
$this->_connection = db2_connect($constring,NULL,NULL);
|
||||
echo debug::vars(array('s'=>$constring,'em'=>db2_conn_errormsg()));die();
|
||||
|
||||
if ($this->_connection) {
|
||||
$result = DB::query(Database::SET,'SET SCHEMA='.$database)->execute(Kohana::config('config.client_type'));
|
||||
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
|
||||
|
||||
return TSM::instance()->set($username,$password,$result);
|
||||
|
||||
} else
|
||||
HTTP::redirect(Request::detect_uri());
|
||||
}
|
||||
|
||||
} catch (ErrorException $e) {
|
||||
// No connection exists
|
||||
$this->_connection = NULL;
|
||||
|
||||
throw new Database_Exception(':error', array(
|
||||
':error' => sprintf('%s error in %s (%s)',$e->getMessage(),$e->getFile(),$e->getLine()),
|
||||
),
|
||||
$e->getCode());
|
||||
}
|
||||
|
||||
// \xFF is a better delimiter, but the PHP driver uses underscore
|
||||
$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
|
||||
|
||||
if ( ! empty($this->_config['charset'])) {
|
||||
// Set the character set
|
||||
$this->set_charset($this->_config['charset']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function execute($sql) {
|
||||
$result = @db2_exec($this->_connection,$sql);
|
||||
$this->execute_stderr = db2_stmt_errormsg();
|
||||
$this->execute_rc = db2_stmt_error();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function list_columns($table, $like = NULL, $add_prefix = TRUE) {
|
||||
// Make sure the database is connected
|
||||
$this->_connection or $this->connect();
|
||||
|
||||
// Quote the table name
|
||||
$table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table;
|
||||
|
||||
if (is_string($like))
|
||||
// Search for column names
|
||||
throw new Kohana_Exception('Like queries not implemented');
|
||||
else
|
||||
// Find all column names
|
||||
$result = db2_columns($this->_connection,NULL,NULL,$table);
|
||||
|
||||
$count = 0;
|
||||
$columns = array();
|
||||
while ($row = db2_fetch_assoc($result)) {
|
||||
list($type, $length) = $this->_parse_type($row['TYPE_NAME']);
|
||||
|
||||
$column = $this->datatype($type);
|
||||
|
||||
$column['column_name'] = $row['COLUMN_NAME'];
|
||||
$column['data_type'] = $type;
|
||||
$column['is_nullable'] = ($row['IS_NULLABLE'] == 'YES');
|
||||
$column['ordinal_position'] = ++$count;
|
||||
|
||||
switch (strtolower($column['data_type'])) {
|
||||
case 'float':
|
||||
if (isset($length))
|
||||
list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
if (isset($length))
|
||||
// MySQL attribute
|
||||
$column['display'] = $length;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
switch ($column['data_type']) {
|
||||
case 'binary':
|
||||
case 'varbinary':
|
||||
$column['character_maximum_length'] = $length;
|
||||
break;
|
||||
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
$column['character_maximum_length'] = $length;
|
||||
case 'text':
|
||||
case 'tinytext':
|
||||
case 'mediumtext':
|
||||
case 'longtext':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
break;
|
||||
|
||||
case 'enum':
|
||||
case 'set':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
$column['options'] = explode('\',\'', substr($length, 1, -1));
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// TSM attributes
|
||||
$column['comment'] = $row['REMARKS'];
|
||||
$columns[$row['COLUMN_NAME']] = $column;
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
}
|
||||
?>
|
49
application/classes/Database/TSM/Result.php
Normal file
49
application/classes/Database/TSM/Result.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database result. See [Results](/database/results) for usage and examples.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Query/Result
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Database_TSM_Result extends Database_Result {
|
||||
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
|
||||
parent::__construct($result, $sql, $as_object, $params);
|
||||
|
||||
$start = FALSE;
|
||||
// Is this a DB2 result?
|
||||
if (is_resource($result) AND function_exists('db2_fetch_object')) {
|
||||
// If we are running a DB2 set command, we can return
|
||||
if (preg_match('/^SET/',$sql))
|
||||
return;
|
||||
|
||||
while ($r = db2_fetch_object($result))
|
||||
$this->_rows[$this->_internal_row++] = (array)$r;
|
||||
|
||||
// Is this an DSMADMC result?
|
||||
} elseif (is_array($result))
|
||||
foreach ($result as $line) {
|
||||
if (! trim($line)) {
|
||||
if ($start)
|
||||
$this->_internal_row++;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
list($k,$v) = explode(':',$line,2);
|
||||
|
||||
$this->_rows[$this->_internal_row][trim($k)] = trim($v);
|
||||
$start = TRUE;
|
||||
}
|
||||
else
|
||||
throw new Kohana_Exception('Unknown result :result',array(':result'=>$result));
|
||||
|
||||
$this->_total_rows = $this->_internal_row;
|
||||
$this->_internal_row = 0;
|
||||
}
|
||||
}
|
||||
?>
|
15
application/classes/Database/TSM/Set.php
Normal file
15
application/classes/Database/TSM/Set.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database set result.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Query/Set
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Database_TSM_Set extends Database_Result {
|
||||
}
|
||||
?>
|
90
application/classes/Database/TSM/Show.php
Normal file
90
application/classes/Database/TSM/Show.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database show result. See [Results](/database/results) for usage and examples.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Query/Show
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Database_TSM_Show extends Database_Result {
|
||||
private $data = array();
|
||||
|
||||
public function __construct($result, $sql, $as_object = FALSE, array $params = NULL) {
|
||||
parent::__construct($result, $sql, $as_object, $params);
|
||||
|
||||
$sql = strtolower($sql);
|
||||
|
||||
$start = FALSE;
|
||||
$barcodewarn = FALSE;
|
||||
foreach ($result as $line) {
|
||||
if (! trim($line))
|
||||
continue;
|
||||
|
||||
if (preg_match('/^show slots /',$sql)) {
|
||||
$library = strtoupper(preg_replace('/^show slots /','',$sql));
|
||||
|
||||
if (preg_match('/^Slot /',$line)) {
|
||||
if ($start)
|
||||
$this->_internal_row++;
|
||||
|
||||
$slot = array();
|
||||
foreach ((preg_split('/,\s*/',$line,-1)) as $slotkey => $val)
|
||||
if (preg_match('/^element number\s+/',$val))
|
||||
$slot['element'] = (int)preg_replace('/^element number\s+/','',$val);
|
||||
elseif (preg_match('/^Slot\s+/',$val))
|
||||
$slot['slot'] = preg_replace('/^Slot\s+/','',$val);
|
||||
elseif (preg_match('/^status\s+/',$val))
|
||||
$slot['status'] = preg_replace('/^status\s+/','',$val);
|
||||
elseif (preg_match('/^barcode value </',$val))
|
||||
$slot['barcodelabel'] = preg_replace('/^barcode value <(.*)>/',"$1",$val);
|
||||
elseif (preg_match('/^barcode\s+/',$val))
|
||||
$slot['barcode'] = preg_replace('/^barcode /','',$val);
|
||||
|
||||
$slot['library'] = $library;
|
||||
$this->_rows[$this->_internal_row] = new Slot($slot);
|
||||
$start = TRUE;
|
||||
|
||||
if (! $barcodewarn AND $slot['status'] == 'Allocated' AND $slot['barcode'] == 'not present') {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Missing Bar Code Labels'),
|
||||
'type'=>'warning',
|
||||
'body'=>sprintf(_('Some allocated slots do not have a bar code label, you may need to run "AUDIT LIBRARY %s CHECKLABEL=BARCODE"'),$library),
|
||||
));
|
||||
|
||||
$barcodewarn = TRUE;
|
||||
}
|
||||
|
||||
} elseif (preg_match('/busy.$/',$line)) {
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Library is Busy'),
|
||||
'type'=>'info',
|
||||
'body'=>_('The library appears busy at the moment.'),
|
||||
));
|
||||
|
||||
return;
|
||||
|
||||
} elseif (preg_match('/:/',$line)) {
|
||||
$line = str_replace(' ','',$line);
|
||||
list($k,$v) = explode(':',$line,2);
|
||||
|
||||
$this->data[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_total_rows = $this->_internal_row;
|
||||
$this->_internal_row = 0;
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
if (isset($this->data[$key]))
|
||||
return $this->data[$key];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
186
application/classes/Database/Tsm/dsmadmc.php
Normal file
186
application/classes/Database/Tsm/dsmadmc.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* TSM database connection using DSMADMC.
|
||||
*
|
||||
* @package PTA
|
||||
* @subpackage TSM
|
||||
* @category Drivers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 phpTSMadmin Development Team
|
||||
* @license http://phptsmadmin.sf.net/license.html
|
||||
*/
|
||||
class Database_Tsm_dsmadmc extends Database_TSM {
|
||||
public function connect() {
|
||||
// Extract the connection parameters, adding required variabels
|
||||
extract($this->_config['connection'] + array(
|
||||
'database' => '',
|
||||
'hostname' => '',
|
||||
'username' => '',
|
||||
'password' => '',
|
||||
'persistent' => FALSE,
|
||||
));
|
||||
|
||||
// Get user login details from user session - these are set by login
|
||||
if (! $username)
|
||||
$username = Session::instance()->get_once(Kohana::$config->load('auth')->session_key);
|
||||
if (! $password)
|
||||
$password = Session::instance()->get_once('password');
|
||||
|
||||
// Prevent this information from showing up in traces
|
||||
unset($this->_config['connection']['username'], $this->_config['connection']['password']);
|
||||
|
||||
if (! file_exists(Kohana::$config->load('config')->client)) {
|
||||
SystemMessage::TSM('error',sprintf('Unable to find the dsmadmc at <b>%s</b>',Kohana::$config->load('config')->client),'');
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! $username OR ! $password)
|
||||
HTTP::redirect('login');
|
||||
|
||||
try {
|
||||
if ($persistent) {
|
||||
// Create a persistent connection
|
||||
throw new Kohana_Exception('Cant do persistant connections');
|
||||
|
||||
} else {
|
||||
// Create a connection and force it to be a new link
|
||||
$this->_connection = sprintf('%s %s -id=%s -password=%s -displ=list -editor=no -dataonly=YES %s %s ',
|
||||
Kohana::$config->load('config')->client,
|
||||
$database ? '-server='.$database : '',
|
||||
$username,
|
||||
$password,
|
||||
Kohana::$config->load('config')->client_errorlogname ? sprintf('-errorlogname=%s',Kohana::$config->load('config')->client_errorlogname) : '',
|
||||
$database ? sprintf('-se=%s',$database) : ''
|
||||
);
|
||||
|
||||
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
|
||||
|
||||
if ($result->count()) {
|
||||
return TSM::instance()->set($username,$password,$result);
|
||||
|
||||
} else {
|
||||
$this->_connection = FALSE;
|
||||
|
||||
// @todo Get ANS8034E (ID not recognised), or ??????E (invalid password)
|
||||
SystemMessage::add(array(
|
||||
'title'=>_('Login Failed'),
|
||||
'type'=>'error',
|
||||
'body'=>_('Invalid Username and/or Password.')
|
||||
));
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ErrorException $e) {
|
||||
// No connection exists
|
||||
$this->_connection = NULL;
|
||||
|
||||
throw new Database_Exception(':error', array(
|
||||
':error' => sprintf('%s error in %s (%s)',$e->getMessage(),$e->getFile(),$e->getLine()),
|
||||
),
|
||||
$e->getCode());
|
||||
}
|
||||
}
|
||||
|
||||
protected function execute($sql) {
|
||||
$this->execute_stdout = '';
|
||||
|
||||
// We need to escape any back slashes, since the exec will transpose them
|
||||
// @todo Is there a better way of doing this?
|
||||
$sql = str_replace('\\','\\\\',$sql);
|
||||
|
||||
$this->execute_stderr = exec($this->_connection.'"'.$sql.'"',$this->execute_stdout,$this->execute_rc);
|
||||
if (Kohana::$config->load('config.site.mode') == Kohana::DEVELOPMENT)
|
||||
SystemMessage::TSM('info',sprintf('%s (%s) [%s]',$this->_connection.'"'.$sql.'"',join("\n",$this->execute_stdout),$this->execute_rc),$sql);
|
||||
|
||||
// Work out our message codes
|
||||
$result = array();
|
||||
foreach ($this->execute_stdout as $line)
|
||||
if (! preg_match('/^('.$this->msg_format.')\s+/',$line,$matches))
|
||||
array_push($result,$line);
|
||||
elseif (! in_array($matches[1],$this->ignore_codes))
|
||||
array_push($this->_query_msg_codes,$matches[1]);
|
||||
|
||||
// If we got a no data code
|
||||
if (array_intersect($this->_query_msg_codes,$this->nodata_codes)) {
|
||||
$result = array();
|
||||
$this->execute_rc = 0;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function list_columns($table, $like = NULL, $add_prefix = TRUE) {
|
||||
// Quote the table name
|
||||
$table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table;
|
||||
|
||||
if (is_string($like))
|
||||
// Search for column names
|
||||
throw new Kohana_Exception('Like queries not implemented');
|
||||
else
|
||||
// Find all column names
|
||||
$result = $this->query(Database::SELECT, sprintf('SELECT * FROM SYSCAT.COLUMNS WHERE TABNAME=\'%s\'',$table), FALSE);
|
||||
|
||||
$count = 0;
|
||||
$columns = array();
|
||||
foreach ($result as $row) {
|
||||
list($type, $length) = $this->_parse_type($row['TYPENAME']);
|
||||
|
||||
$column = $this->datatype($type);
|
||||
|
||||
$column['column_name'] = $row['COLNAME'];
|
||||
$column['data_type'] = $type;
|
||||
$column['is_nullable'] = ($row['NULLS'] == 'TRUE');
|
||||
$column['ordinal_position'] = ++$count;
|
||||
|
||||
switch (strtolower($column['data_type'])) {
|
||||
case 'float':
|
||||
if (isset($length))
|
||||
list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
if (isset($length))
|
||||
// MySQL attribute
|
||||
$column['display'] = $length;
|
||||
break;
|
||||
|
||||
case 'string':
|
||||
switch ($column['data_type']) {
|
||||
case 'binary':
|
||||
case 'varbinary':
|
||||
$column['character_maximum_length'] = $length;
|
||||
break;
|
||||
|
||||
case 'char':
|
||||
case 'varchar':
|
||||
$column['character_maximum_length'] = $length;
|
||||
case 'text':
|
||||
case 'tinytext':
|
||||
case 'mediumtext':
|
||||
case 'longtext':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
break;
|
||||
|
||||
case 'enum':
|
||||
case 'set':
|
||||
$column['collation_name'] = $row['Collation'];
|
||||
$column['options'] = explode('\',\'', substr($length, 1, -1));
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// TSM attributes
|
||||
$column['comment'] = $row['REMARKS'];
|
||||
$columns[$row['COLNAME']] = $column;
|
||||
}
|
||||
|
||||
return $columns ? $columns : array('');
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user