Using Postgresql database, using double quotes causes errors in db queries
| Project: | Page Title |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
This function in page_title.module uses double quotes to quote the %s
function page_title_load_title($id, $type) {
return db_result(db_query('SELECT page_title FROM {page_title} WHERE type = "%s" AND id = %d', $type, $id));
}
Postgresql (I'm running 8.3) doesn't like this and thinks %s is referring to a column not a value. I found an explanation here: http://tf-b4rt.berlios.de/forum/index.php?action=printpage;topic=279.0
Changing the function by using single quotes eliminates the issue:
function page_title_load_title($id, $type) {
return db_result(db_query('SELECT page_title FROM {page_title} WHERE type = \'%s\' AND id = %d', $type, $id));
}
The double quotes cause the following result:
* warning: pg_query() [function.pg-query]: Query failed: ERROR: column "node" does not exist LINE 1: SELECT page_title FROM page_title WHERE type = "node" AND id... ^ in /web/vhosts/drupal-6.14/includes/database.pgsql.inc on line 139.
* user warning: query: SELECT page_title FROM page_title WHERE type = "node" AND id = 1 in /web/vhosts/drupal-6.14/sites/all/modules/page_title/page_title.module on line 350.
This issue may occur in other queries as well.
