MINOR: transaction functions renamed for consistency, field list lookups now cached for speed improvements

This commit is contained in:
Geoff Munn 2011-01-11 21:17:17 +00:00
parent 99f2cb179e
commit 2bd6e9fb8e

View File

@ -88,6 +88,15 @@ class PostgreSQLDatabase extends SS_Database {
*/
private static $cached_ordered_specifically=array();
/**
*
* This holds a copy of all the queries that run through the function fieldList()
* This is one of the most-often called functions, and repeats itself a great deal in the unit tests.
*
* @var array
*/
private static $cached_fieldlists=array();
/**
* Override the language that tsearch uses. By default it is 'english, but
* could be any of the supported languages that can be found in the
@ -278,7 +287,7 @@ class PostgreSQLDatabase extends SS_Database {
$this->selectDatabase($this->database_original);
$this->connectDatabase();
$this->query("DROP DATABASE $db_to_drop");
$this->query("DROP DATABASE \"$db_to_drop\"");
}
/**
@ -647,6 +656,7 @@ class PostgreSQLDatabase extends SS_Database {
// First, we split the column specifications into parts
// TODO: this returns an empty array for the following string: int(11) not null auto_increment
// on second thoughts, why is an auto_increment field being passed through?
$pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\']+)?\s?(check\s[\w()\'",\s]+)?$/i';
preg_match($pattern, $colSpec, $matches);
@ -757,6 +767,8 @@ class PostgreSQLDatabase extends SS_Database {
public function fieldList($table) {
//Query from http://www.alberton.info/postgresql_meta_info.html
//This gets us more information than we need, but I've included it all for the moment....
if(!isset(self::$cached_fieldlists[$table])){
$fields = $this->query("SELECT ordinal_position, column_name, data_type, column_default, is_nullable, character_maximum_length, numeric_precision, numeric_scale FROM information_schema.columns WHERE table_name = '$table' ORDER BY ordinal_position;");
$output = array();
@ -838,7 +850,9 @@ class PostgreSQLDatabase extends SS_Database {
}
return $output;
self::$cached_fieldlists[$table]=$output;
}
return self::$cached_fieldlists[$table];
}
/**
@ -1059,6 +1073,7 @@ class PostgreSQLDatabase extends SS_Database {
*/
public function tableList() {
$schema_SQL = pg_escape_string($this->dbConn, $this->schema);
$tables=array();
foreach($this->query("SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = '{$schema_SQL}' AND tablename NOT ILIKE 'pg_%' AND tablename NOT ILIKE 'sql_%'") as $record) {
//$table = strtolower(reset($record));
$table = reset($record);
@ -1066,7 +1081,7 @@ class PostgreSQLDatabase extends SS_Database {
}
//Return an empty array if there's nothing in this database
return isset($tables) ? $tables : Array();
return $tables;
}
function TableExists($tableName){
@ -1375,8 +1390,9 @@ class PostgreSQLDatabase extends SS_Database {
//TODO: the DbValue result does not include the numeric_scale option (ie, the ,0 value in 4,0)
if($asDbValue)
return Array('data_type'=>'decimal', 'precision'=>'4', 'default'=> (int)$values['default']);
else return "decimal(4,0){$values['arrayValue']}";
return Array('data_type'=>'decimal', 'precision'=>'4');
else
return "decimal(4,0){$values['arrayValue']}";
}
function escape_character($escape=false){
@ -1712,7 +1728,7 @@ class PostgreSQLDatabase extends SS_Database {
* Start a prepared transaction
* See http://developer.postgresql.org/pgdocs/postgres/sql-set-transaction.html for details on transaction isolation options
*/
public function startTransaction($transaction_mode=false, $session_characteristics=false){
public function transactionStart($transaction_mode=false, $session_characteristics=false){
DB::query('BEGIN;');
if($transaction_mode)
@ -1745,7 +1761,7 @@ class PostgreSQLDatabase extends SS_Database {
/*
* Commit everything inside this transaction so far
*/
public function endTransaction(){
public function transactionEnd(){
DB::query('COMMIT;');
}