Hi I'm running a postgres 8.3 database with the finder module. If doing a search on an integer field, I'm searching on node id, I get an error.

Here's the query that throws an error:
SELECT COUNT(*) FROM node node WHERE node.type IN ('repair_order') AND node.status = 1 AND (node.nid LIKE '%8%')

But if I cast the nid as text it works:
SELECT COUNT(*) FROM node node WHERE node.type IN ('repair_order') AND node.status = 1 AND (node.nid::text LIKE '%8%')

So perhaps type casting could be added to the module to support postgres? I can't imagine it would cause any problems with mySQL...
Thanks for the great module!

CommentFileSizeAuthor
#1 finder_typecast.patch1.64 KBRedocbew

Comments

Redocbew’s picture

Component: Finder Node » Code
StatusFileSize
new1.64 KB

First Contributed Patch!

Added a helper function to determine database type and include explicit typecasting if required

danielb’s picture

Thanks for bringing my attention to this. I am sure this problem will be in a couple other places too, so I will carefully review where this is and get back to you.

danielb’s picture

I am going to make this change to finder_placeholder(), I believe it will have the same effect and won't require me to update all the query calls in different places

/**
 * Turns string placeholders to other types if needed.
 */
function finder_placeholder($match, $table, $field) {
  global $db_type;
  $object_schema = drupal_get_schema($table);
  $type = $object_schema['fields'][$field]['type'];
  $placeholder = db_type_placeholder($type);
  if ($placeholder != "'%s'" && strpos($match, 'LIKE') === FALSE) {
    $match = str_replace('%s', $placeholder, $match);
    $match = str_replace("'", "", $match);
  }
  if ($db_type == 'pgsql' && $placeholder != "'%s'" && strpos($match, 'LIKE') !== FALSE) {
    $match = '::text'. $match;
  }
  return $match;
}
danielb’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.