Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE » How To » $lock_str FOR UPDATE FOR $tablename with PostgreSQL
$lock_str FOR UPDATE FOR $tablename with PostgreSQL [message #7252] Wed, 06 February 2019 13:55 Go to previous message
pdv is currently offline  pdv
Messages: 15
Registered: January 2019
Junior Member
Hi,

I've run into a problem with the $lock_str "FOR UPDATE OF $tablename" when accessing a PostgreSQL database (on macos). The problem is that if an alias is defined in the FROM-clause, then this alias must be used everywhere. The documentation is clear about this:

Quote:
A substitute name for the FROM item containing the alias. An alias is used for brevity or to eliminate ambiguity for self-joins (where the same table is scanned multiple times). When an alias is provided, it completely hides the actual name of the table or function; for example given FROM foo AS f, the remainder of the SELECT must refer to this FROM item as f not foo. If an alias is written, a column alias list can also be written to provide substitute names for one or more columns of the table.

In std.table.class.inc this line (9165)

$array = $DML->getData($this->dbname_server, $this->tablename, $where);

passes the tablename also if an alias has been used, causing a PostgreSQL-error.

To solve this I've replaced this line by this code:

$table_array = extractTableNames($this->sql_from);
if(empty($table_array) || isset($table_array[$this->tablename])) {
$array = $DML->getData($this->dbname_server, $this->tablename, $where);
} else { // the first key is the alias from the FROM clause
$array = $DML->getData($this->dbname_server, array_search($this->tablename, $table_array), $where);
} //if

which works for the tests I've done sofar.

Regards,

Patrick
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Radicore tutorial point
Next Topic: Multi servers and PostgreSQL
Goto Forum:
  


Current Time: Sun Dec 22 00:29:19 EST 2024

Total time taken to generate the page: 0.00994 seconds