fixed bug in getting primary key name if the table is in a different
schema to the current one * check current schema and set prefix to table if needed * check that if cursor is null we do not try to get any data but return false
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?
|
||||
// $Id: class_test.php 4793 2014-01-07 02:51:59Z gullevek $
|
||||
// $Id: class_test.php 4831 2014-01-20 03:27:10Z gullevek $
|
||||
$DEBUG_ALL = 1;
|
||||
$PRINT_ALL = 1;
|
||||
$DB_DEBUG = 1;
|
||||
@@ -78,7 +78,7 @@
|
||||
}
|
||||
|
||||
$status = $basic->db_exec("INSERT INTO foo (test) VALUES ('FOO TEST ".time()."') RETURNING test");
|
||||
print "DIREC INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id."<br>";
|
||||
print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id."<br>";
|
||||
print "DIRECT INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
|
||||
$basic->db_prepare("ins_foo", "INSERT INTO foo (test) VALUES ($1)");
|
||||
$status = $basic->db_execute("ins_foo", array('BAR TEST '.time()));
|
||||
@@ -86,7 +86,7 @@
|
||||
print "PREPARE INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
|
||||
|
||||
# async test queries
|
||||
$basic->db_exec_async("SELECT test FROM foo, (SELECT pg_sleep(10)) as sub WHERE foo_id IN (27, 50, 67, 44, 10)");
|
||||
/* $basic->db_exec_async("SELECT test FROM foo, (SELECT pg_sleep(10)) as sub WHERE foo_id IN (27, 50, 67, 44, 10)");
|
||||
echo "WAITING FOR ASYNC: ";
|
||||
$chars = array('|', '/', '-', '\\');
|
||||
while (($ret = $basic->db_check_async()) === true)
|
||||
@@ -116,7 +116,7 @@
|
||||
flush();
|
||||
}
|
||||
print "<br>END STATUS: ".$ret." | PK: ".$basic->insert_id."<br>";
|
||||
print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>";
|
||||
print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."<br>"; */
|
||||
|
||||
$to_db_version = '9.1.9';
|
||||
print "VERSION DB: ".$basic->db_version()."<br>";
|
||||
@@ -126,6 +126,16 @@
|
||||
print "DB Version bigger than $to_db_version: ".$basic->db_compare_version('>='.$to_db_version)."<br>";
|
||||
print "DB Version bigger $to_db_version: ".$basic->db_compare_version('>'.$to_db_version)."<br>";
|
||||
|
||||
// search path check
|
||||
$q = "SHOW search_path";
|
||||
$cursor = $basic->db_exec($q);
|
||||
$data = $basic->db_fetch_array($cursor)['search_path'];
|
||||
print "RETURN DATA FOR search_path: ".$data."<br>";
|
||||
// print "RETURN DATA FOR search_path: ".$basic->print_ar($data)."<br>";
|
||||
// insert something into test.schema_test and see if we get the PK back
|
||||
$status = $basic->db_exec("INSERT INTO test.schema_test (contents, id) VALUES ('TIME: ".time()."', ".rand(1, 10).")");
|
||||
print "OTHER SCHEMA INSERT STATUS: ".$status." | PK NAME: ".$basic->pk_name.", PRIMARY KEY: ".$basic->insert_id."<br>";
|
||||
|
||||
// print error messages
|
||||
print $basic->print_error_msg();
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
/********************************************************************
|
||||
* $HeadURL: svn://svn/development/core_data/php/www/libs/Class.DB.IO.inc $
|
||||
* $LastChangedBy: gullevek $
|
||||
* $LastChangedDate: 2014-01-08 15:03:09 +0900 (Wed, 08 Jan 2014) $
|
||||
* $LastChangedRevision: 4818 $
|
||||
* $LastChangedDate: 2014-01-20 12:27:10 +0900 (Mon, 20 Jan 2014) $
|
||||
* $LastChangedRevision: 4831 $
|
||||
*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2000/11/23
|
||||
@@ -369,9 +369,9 @@
|
||||
$this->class_info['db_io']=array(
|
||||
'class_name' => 'DB IO',
|
||||
'class_version' => '4.1.0',
|
||||
'class_revision' => '$LastChangedRevision: 4818 $',
|
||||
'class_revision' => '$LastChangedRevision: 4831 $',
|
||||
'class_created' => '2000-11-23',
|
||||
'class_last_changed' => '$LastChangedDate: 2014-01-08 15:03:09 +0900 (Wed, 08 Jan 2014) $',
|
||||
'class_last_changed' => '$LastChangedDate: 2014-01-20 12:27:10 +0900 (Mon, 20 Jan 2014) $',
|
||||
'class_author' => 'Clemens Schwaighofer'
|
||||
);
|
||||
}
|
||||
@@ -677,7 +677,7 @@
|
||||
}
|
||||
// for DEBUG, only on first time ;)
|
||||
if ($this->db_debug)
|
||||
$this->_db_debug('db', $this->query, 'db_exec', 'Q');
|
||||
$this->_db_debug('db', $this->query, '_db_prepare_exec', 'Q');
|
||||
// import protection, md5 needed
|
||||
$md5 = md5($this->query);
|
||||
// if the array index does not exists set it 0
|
||||
@@ -1667,5 +1667,5 @@ $this->debug('ExecuteData', 'ERROR in STM['.$stm_name.'|'.$this->prepare_cursor[
|
||||
}
|
||||
} // end if db class
|
||||
|
||||
// $Id: Class.DB.IO.inc 4818 2014-01-08 06:03:09Z gullevek $
|
||||
// $Id: Class.DB.IO.inc 4831 2014-01-20 03:27:10Z gullevek $
|
||||
?>
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
/*********************************************************************
|
||||
* $HeadURL: svn://svn/development/core_data/php/www/libs/db_pgsql.inc $
|
||||
* $LastChangedBy: gullevek $
|
||||
* $LastChangedDate: 2013-12-12 18:53:03 +0900 (Thu, 12 Dec 2013) $
|
||||
* $LastChangedRevision: 4743 $
|
||||
* $LastChangedDate: 2014-01-20 12:27:10 +0900 (Mon, 20 Jan 2014) $
|
||||
* $LastChangedRevision: 4831 $
|
||||
*********************************************************************
|
||||
* AUTHOR: Clemens "Gullevek" Schwaighofer (www.gullevek.org)
|
||||
* CREATED: 2003/04/09
|
||||
@@ -231,15 +231,19 @@
|
||||
{
|
||||
if ($table)
|
||||
{
|
||||
// read from table the PK name
|
||||
// slower version
|
||||
/* $q = "SELECT c.column_name ";
|
||||
$q .= "FROM information_schema.table_constraints tc ";
|
||||
$q .= "JOIN information_schema.constraint_column_usage AS ccu USING (constraint_schema, constraint_name) ";
|
||||
$q .= "JOIN information_schema.columns AS c ON c.table_schema = tc.constraint_schema AND tc.table_name = c.table_name AND ccu.column_name = c.column_name ";
|
||||
$q .= "WHERE constraint_type = 'PRIMARY KEY' and tc.table_name = '".$table."'";
|
||||
// check if schema set is different from schema given, only needed if schema is not empty
|
||||
$table_prefix = '';
|
||||
if ($schema)
|
||||
$q .= " AND c.table_schema = '".$schema."'"; */
|
||||
{
|
||||
$q = "SHOW search_path";
|
||||
$cursor = $this->_db_query($q);
|
||||
$search_path = $this->_db_fetch_array($cursor)['search_path'];
|
||||
if ($search_path != $schema)
|
||||
{
|
||||
$table_prefix = $schema.'.';
|
||||
}
|
||||
}
|
||||
// read from table the PK name
|
||||
// faster primary key get
|
||||
$q = "SELECT pg_attribute.attname AS column_name, format_type(pg_attribute.atttypid, pg_attribute.atttypmod) AS type ";
|
||||
$q .= "FROM pg_index, pg_class, pg_attribute ";
|
||||
@@ -247,7 +251,7 @@
|
||||
$q .= ", pg_namespace ";
|
||||
$q .= "WHERE ";
|
||||
// regclass translates the OID to the name
|
||||
$q .= "pg_class.oid = '".$table."'::regclass AND ";
|
||||
$q .= "pg_class.oid = '".$table_prefix.$table."'::regclass AND ";
|
||||
$q .= "indrelid = pg_class.oid AND ";
|
||||
if ($schema)
|
||||
{
|
||||
@@ -258,7 +262,10 @@
|
||||
$q .= "pg_attribute.attnum = any(pg_index.indkey) ";
|
||||
$q .= "AND indisprimary";
|
||||
$cursor = $this->_db_query($q);
|
||||
return $this->_db_fetch_array($cursor)['column_name'];
|
||||
if ($cursor)
|
||||
return $this->_db_fetch_array($cursor)['column_name'];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -382,5 +389,5 @@
|
||||
}
|
||||
}
|
||||
|
||||
// $Id: db_pgsql.inc 4743 2013-12-12 09:53:03Z gullevek $
|
||||
// $Id: db_pgsql.inc 4831 2014-01-20 03:27:10Z gullevek $
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user