I get this error :

Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error on or near "cache" at character 13 in /var/www/drupal/includes/database.pgsql.inc on line 45

Fatal error: ERROR: syntax error on or near "cache" at character 13 query: LOCK TABLES cache WRITE in /var/www/drupal/includes/database.pgsql.inc on line 62

Someone could solve this problem ?

Thanks
kinaï

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kinai’s picture

Title: PG_QUERY ERROR » PG_QUERY ERROR - LOCK TABLES - IMPLEMENTATION FAULT.

The SQL Command : LOCK TABLES like used in bootstrap.inc is only specified for MySQL, not for PostgreSQL.
The UNLOCK TABLES SQL command is not implemented in PostgreSQL.

Someone could solve this problem ?

Thanks,
Kinaï

intel352’s picture

this issue still exists, i've verified it on a fresh cvs install w/ pgsql 8

intel352’s picture

i fixed the problem in my installation, by changing the syntax to:

LOCK TABLE {cache}

it's table, not tables. and i dropped the 'write' bit.

furthermore, pgsql does not support the UNLOCK command, so i had to comment the unlock tables command. unless there are more lock/unlock commands elsewhere in the code, this works fine for me.

according to pgsql docs, UNLOCK is automatically performed at transaction end, which is why there is no such command.

Cvbge’s picture

Status: Active » Needs review
FileSize
2.91 KB

The patch adds two functions to lock and unlock tables.

Cvbge’s picture

FileSize
2.8 KB

Updated, without unnecessary changes.

chx’s picture

Status: Needs review » Reviewed & tested by the community

Cvbge says he tested pgsql, I applied to a mysql one, saved system settings and looks OK.

Cvbge’s picture

FileSize
2.81 KB

Worked, yet not worked ...
This version does not use db_query("{$table}" ) syntax. I promise I won't do that again!

Dries’s picture

MySQL is happy with the singular 'LOCK TABLE' (rather than 'LOCK TABLES') which should work with both MySQL and PostgreSQL. Committed that changes to CVS.

Dries’s picture

Status: Reviewed & tested by the community » Fixed
Cvbge’s picture

Status: Fixed » Reviewed & tested by the community

Please rollback your patch and either
a) use syntax LOCK TABLE name (dropping S and WRITE, if you say that mysql support "LOCK")
b) apply my patch.

Postgres does not support WRITE part (as well as S part).
Also locking won't work without starting transaction.

You can do LOCK TABLE name only, but this lock is too excessive and won't allow even SELECTs on locked table.

Cvbge’s picture

FileSize
2.82 KB

Attached updated patch for current head.

Thomas Ilsche’s picture

+1
tested the patch on pgsql, runs as expected.

Cvbge’s picture

FileSize
2.82 KB

Table names are now escaped

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

Cvbge’s picture

A sidenote about escaping table names:

db_escape_string() uses pg__escape_string(), from it's php docs: Escape a string for insertion into a text field. It assumes that it will be in ''. For example it does not esape ";"

mysql's version does addslashes, but it does not escape ";" either.

For postgresql correct way might be to use "" and escape ", but I'd have to check it. Is it worth it?

Anonymous’s picture

Anonymous’s picture

Status: Fixed » Closed (fixed)