diff --git a/www/admin/class_test.php b/www/admin/class_test.php index dc992c1b..231518c8 100644 --- a/www/admin/class_test.php +++ b/www/admin/class_test.php @@ -1,5 +1,5 @@ db_exec("INSERT INTO foo (test) VALUES ('FOO TEST ".time()."') RETURNING test"); - print "DIREC INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id."
"; + print "DIRECT INSERT STATUS: $status | PRIMARY KEY: ".$basic->insert_id."
"; print "DIRECT INSERT PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."
"; $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)."
"; # 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 "
END STATUS: ".$ret." | PK: ".$basic->insert_id."
"; - print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."
"; + print "ASYNC PREVIOUS INSERTED: ".print_r($basic->db_return_row("SELECT foo_id, test FROM foo WHERE foo_id = ".$basic->insert_id), 1)."
"; */ $to_db_version = '9.1.9'; print "VERSION DB: ".$basic->db_version()."
"; @@ -126,6 +126,16 @@ print "DB Version bigger than $to_db_version: ".$basic->db_compare_version('>='.$to_db_version)."
"; print "DB Version bigger $to_db_version: ".$basic->db_compare_version('>'.$to_db_version)."
"; + // 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."
"; +// print "RETURN DATA FOR search_path: ".$basic->print_ar($data)."
"; + // 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."
"; + // print error messages print $basic->print_error_msg(); diff --git a/www/libs/Class.DB.IO.inc b/www/libs/Class.DB.IO.inc index 21233527..4da7f12a 100644 --- a/www/libs/Class.DB.IO.inc +++ b/www/libs/Class.DB.IO.inc @@ -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 $ ?> diff --git a/www/libs/db_pgsql.inc b/www/libs/db_pgsql.inc index dd7b6a29..dc7cd073 100644 --- a/www/libs/db_pgsql.inc +++ b/www/libs/db_pgsql.inc @@ -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 $ ?>