function finder_placeholder in Finder 6
Turns string placeholders to other types in keyword queries, if required.
By default finder's queries use a string placeholder ('%s') with no regard for pgsql peculiarities when creating an SQL condition for searches. By putting such conditions through this function, this is a common place to do string manipulation on the condition to ensure compatibility with the database.
Parameters
$match: The SQL condition string.
$table: The name of the table this condition is from.
$field: The name of the field this condition is against.
$insert_value: Insert the value into the query instead of the placeholder.
Return value
The modified SQL condition string.
2 calls to finder_placeholder()
- finder_find_query in ./
finder.module - Build basic finder query arrays.
- finder_views_plugin_display_finder::query in modules/
finder_views/ includes/ finder_views_plugin_display_finder.inc
File
- ./
finder.module, line 1329 - The finder module.
Code
function finder_placeholder($match, $table, $field, $insert_value = FALSE) {
global $db_type;
$object_schema = drupal_get_schema($table);
$type = $object_schema['fields'][$field]['type'];
$placeholder = db_type_placeholder($type);
if ($insert_value !== FALSE) {
switch ($placeholder) {
case '%d':
if ($insert_value > PHP_INT_MAX) {
$precision = ini_get('precision');
@ini_set('precision', 16);
$insert_value = sprintf('%.0f', $insert_value);
@ini_set('precision', $precision);
}
else {
$insert_value = (int) $insert_value;
}
$match = str_replace('%d', $insert_value, $match);
break;
case "'%s'":
$match = str_replace('%s', db_escape_string($insert_value), $match);
break;
case '%n':
$insert_value = trim($insert_value);
$insert_value = is_numeric($insert_value) && !preg_match('/x/i', $insert_value) ? $insert_value : '0';
$match = str_replace('%n', $insert_value, $match);
break;
case '%%':
$match = str_replace('%%', '%', $match);
break;
case '%f':
$match = str_replace('%f', (double) $insert_value, $match);
break;
case '%b':
$match = str_replace('%b', db_encode_blob($insert_value), $match);
break;
}
}
if ($placeholder != "'%s'") {
if (strpos($match, 'LIKE') === FALSE) {
$match = str_replace('%s', $placeholder, $match);
$match = str_replace("'", "", $match);
}
elseif ($db_type == 'pgsql') {
// It is also assumed that $match contains 'LIKE' here.
$match = '::text' . str_replace('LIKE', 'ILIKE', $match);
}
}
return $match;
}