Improvements for scrutinizer
This commit is contained in:
parent
7cf3c436dd
commit
23c1cf0e5b
@ -55,16 +55,62 @@ abstract class DB_Util {
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Get database-specific sql to create a new table
|
||||
* Convienience public function to generate sql for creating a db table
|
||||
*
|
||||
* @abstract
|
||||
* @param string $name
|
||||
* @param array $columns
|
||||
* @param array $fields
|
||||
* @param array $constraints
|
||||
* @param array $indexes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function create_table($name, $columns, array $constraints=array(), array $indexes=array());
|
||||
public function create_table($name, $fields, array $constraints=array(), array $indexes=array())
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
// Eg $column_array[$colname] = array(
|
||||
// 'type' => ...,
|
||||
// 'constraint' => ...,
|
||||
// 'index' => ...,
|
||||
// )
|
||||
foreach($fields as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
|
||||
$column_array[$colname] = array();
|
||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
||||
}
|
||||
|
||||
if( ! empty($constraints))
|
||||
{
|
||||
foreach($constraints as $col => $const)
|
||||
{
|
||||
$column_array[$col]['constraint'] = $const;
|
||||
}
|
||||
}
|
||||
|
||||
// Join column definitons together
|
||||
$columns = array();
|
||||
foreach($column_array as $n => $props)
|
||||
{
|
||||
$str = '"'.$n.'"';
|
||||
$str .= (isset($props['type'])) ? " {$props['type']}" : "";
|
||||
$str .= (isset($props['constraint'])) ? " {$props['constraint']}" : "";
|
||||
|
||||
$columns[] = $str;
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = 'CREATE TABLE "'.$name.'" (';
|
||||
$sql .= implode(', ', $columns);
|
||||
$sql .= ')';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get database-specific sql to drop a table
|
||||
|
@ -88,9 +88,12 @@ function Query($params = '')
|
||||
{
|
||||
return $cmanager->get_connection($params);
|
||||
}
|
||||
elseif ( ! is_scalar($params))
|
||||
{
|
||||
// Otherwise, return a new connection
|
||||
return $cmanager->connect($params);
|
||||
}
|
||||
|
||||
// Otherwise, return a new connection
|
||||
return $cmanager->connect($params);
|
||||
}
|
||||
|
||||
// End of common.php
|
@ -61,7 +61,7 @@ class Firebird_Result extends PDOStatement {
|
||||
// but we only want "interbase result" types when attempting to fetch data
|
||||
if (is_resource($link) && get_resource_type($link) === "interbase result")
|
||||
{
|
||||
while($row = ibase_fetch_assoc($link, IBASE_FETCH_BLOBS))
|
||||
while($row = fbird_fetch_assoc($link, IBASE_FETCH_BLOBS))
|
||||
{
|
||||
$this->result[] = $row;
|
||||
}
|
||||
|
@ -24,66 +24,6 @@
|
||||
*/
|
||||
class Firebird_Util extends DB_Util {
|
||||
|
||||
/**
|
||||
* Convienience public function to generate sql for creating a db table
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $fields
|
||||
* @param array $constraints
|
||||
* @param array $indexes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function create_table($name, $fields, array $constraints=array(), array $indexes=array())
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
// Eg $column_array[$colname] = array(
|
||||
// 'type' => ...,
|
||||
// 'constraint' => ...,
|
||||
// 'index' => ...,
|
||||
// )
|
||||
foreach($fields as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
|
||||
$column_array[$colname] = array();
|
||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
||||
}
|
||||
|
||||
if( ! empty($constraints))
|
||||
{
|
||||
foreach($constraints as $col => $const)
|
||||
{
|
||||
$column_array[$col]['constraint'] = $const;
|
||||
}
|
||||
}
|
||||
|
||||
// Join column definitons together
|
||||
$columns = array();
|
||||
foreach($column_array as $n => $props)
|
||||
{
|
||||
$str = '"'.$n.'"';
|
||||
$str .= (isset($props['type'])) ? " {$props['type']}" : "";
|
||||
$str .= (isset($props['constraint'])) ? " {$props['constraint']}" : "";
|
||||
|
||||
$columns[] = $str;
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = 'CREATE TABLE "'.$name.'" (';
|
||||
$sql .= implode(', ', $columns);
|
||||
$sql .= ')';
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Drop the selected table
|
||||
*
|
||||
|
@ -23,65 +23,6 @@
|
||||
*/
|
||||
class PgSQL_Util extends DB_Util {
|
||||
|
||||
/**
|
||||
* Database-specific method to create a new table
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $columns
|
||||
* @param array $constraints
|
||||
* @param array $indexes
|
||||
* @return string
|
||||
*/
|
||||
public function create_table($name, $columns, array $constraints=array(), array $indexes=array())
|
||||
{
|
||||
$column_array = array();
|
||||
|
||||
// Reorganize into an array indexed with column information
|
||||
// Eg $column_array[$colname] = array(
|
||||
// 'type' => ...,
|
||||
// 'constraint' => ...,
|
||||
// 'index' => ...,
|
||||
// )
|
||||
foreach($columns as $colname => $type)
|
||||
{
|
||||
if(is_numeric($colname))
|
||||
{
|
||||
$colname = $type;
|
||||
}
|
||||
|
||||
$column_array[$colname] = array();
|
||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
||||
}
|
||||
|
||||
if( ! empty($constraints))
|
||||
{
|
||||
foreach($constraints as $col => $const)
|
||||
{
|
||||
$column_array[$col]['constraint'] = $const;
|
||||
}
|
||||
}
|
||||
|
||||
// Join column definitons together
|
||||
$columns = array();
|
||||
foreach($column_array as $n => $props)
|
||||
{
|
||||
$str = "{$n} ";
|
||||
$str .= (isset($props['type'])) ? "{$props['type']} " : "";
|
||||
$str .= (isset($props['constraint'])) ? $props['constraint'] : "";
|
||||
|
||||
$columns[] = $str;
|
||||
}
|
||||
|
||||
// Generate the sql for the creation of the table
|
||||
$sql = "CREATE TABLE \"{$name}\" (";
|
||||
$sql .= implode(", ", $columns);
|
||||
$sql .= ")";
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Database-specific SQL for dropping a table
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user