This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
phptsmadmin/application/classes/Database/TSM.php

115 lines
3.2 KiB
PHP
Raw Permalink Normal View History

2011-03-03 23:06:18 +00:00
<?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
*/
2011-08-31 21:36:33 +00:00
abstract class Database_TSM extends Database {
2011-03-03 23:06:18 +00:00
// 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
2011-08-31 21:36:33 +00:00
protected $msg_format = '[A-Z]{3}[0-9]{4}[I|E|W|S]';
2011-03-03 23:06:18 +00:00
// Our Message Codes stored in the last query
2011-08-31 21:36:33 +00:00
protected $_query_msg_codes = array();
2011-03-03 23:06:18 +00:00
// Our return code error messages we can ignore
2011-08-31 21:36:33 +00:00
protected $ignore_codes = array(
2011-03-03 23:06:18 +00:00
'ANS8001I', // Return code %s.
);
// Our return code error messages we can ignore
2011-08-31 21:36:33 +00:00
protected $nodata_codes = array(
2011-03-03 23:06:18 +00:00
'ANR2034E', // SELECT: No match found using this criteria.
);
2011-08-31 21:36:33 +00:00
protected $execute_stdout = '';
protected $execute_stderr = '';
protected $execute_rc = NULL;
2011-05-23 10:01:27 +00:00
// Our required abstract methods
public function begin($mode = NULL) {}
public function commit() {}
public function rollback() {}
public function set_charset($charset) {}
2011-08-31 21:36:33 +00:00
public function list_tables($like = NULL) {}
// Required methods
abstract protected function execute($sql);
2011-05-23 10:01:27 +00:00
2011-05-28 09:46:46 +00:00
/**
* 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;
}
2011-04-08 05:34:04 +00:00
private function clear() {
$this->_query_msg_codes = array();
}
2011-05-23 10:01:27 +00:00
public function query($type, $sql, $as_object = FALSE, array $params = NULL) {
2011-03-03 23:06:18 +00:00
// Make sure the database is connected
2012-11-26 05:57:18 +00:00
if (! $this->_connection && ! $this->connect())
return new Database_TSM_Result(array(),'',$as_object,$params);
2011-04-08 05:34:04 +00:00
$this->clear();
2011-03-03 23:06:18 +00:00
if ( ! empty($this->_config['profiling']))
// Benchmark this query for the current instance
$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
// Execute the query
2011-08-31 21:36:33 +00:00
$result = $this->execute($sql);
2011-03-03 23:06:18 +00:00
2011-08-31 21:36:33 +00:00
if ($this->execute_stderr AND $this->execute_rc) {
// This benchmark is worthless
2011-03-03 23:06:18 +00:00
if (isset($benchmark))
Profiler::delete($benchmark);
2012-11-26 05:57:18 +00:00
SystemMessage::TSM('error',sprintf('%s (%s)',$this->execute_stdout,$this->execute_stderr),$sql);
2011-03-03 23:06:18 +00:00
}
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');
2011-06-24 01:27:21 +00:00
elseif ($type === Database::SHOW)
return new Database_TSM_Show($result, $sql, $as_object, $params);
2011-08-31 21:36:33 +00:00
elseif ($type === Database::SET)
return new Database_TSM_Set($result, $sql, $as_object, $params);
2011-03-03 23:06:18 +00:00
}
2011-05-23 10:01:27 +00:00
public function escape($value) {
2011-03-03 23:06:18 +00:00
// SQL standard is to use single-quotes for all values
return "'$value'";
}
2011-08-31 21:36:33 +00:00
}
?>