diff options
Diffstat (limited to 'includes/database.inc')
-rw-r--r-- | includes/database.inc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/includes/database.inc b/includes/database.inc index 053228310..ee60b80d9 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -445,5 +445,47 @@ function db_field_names($fields) { } /** + * Given a Schema API field type, return the correct %-placeholder to + * embed in a query to be passed to db_query along with a value from a + * column of the specified type. + * + * @param $type + * The Schema API type of a field. + * @return + * The placeholder string to embed in a query for that type. + */ +function _db_type_placeholder($type) { + switch ($type) { + case 'varchar': + case 'text': + case 'datetime': + return '\'%s\''; + + case 'numeric': + // For 'numeric' values, we use '%s', not '\'%s\'' as with + // string types, because numeric values should not be enclosed + // in quotes in queries (though they can be, at least on mysql + // and pgsql). Numerics should only have [0-9.+-] and + // presumably no db's "escape string" function will mess with + // those characters. + return '%s'; + + case 'serial': + case 'int': + return '%d'; + + case 'float': + return '%f'; + + case 'blob': + return '%b'; + } + + // There is no safe value to return here, so return something that + // will cause the query to fail. + return 'unsupported type '. $type . 'for _db_type_placeholder'; +} + +/** * @} End of "defgroup schemaapi". */ |