return "\$".$this->fix_sql_params_i;
}
+ /**
+ * Detects object parameters and throws exception if found
+ * @param mixed $value
+ * @return void
+ */
+ protected function detect_objects($value) {
+ if (is_object($value)) {
+ throw new coding_exception('Invalid database query parameter value', 'Objects are are not allowed: '.get_class($value));
+ }
+ }
+
/**
* Normalizes sql query parameters and verifies parameters.
* @param string $sql The query or part of it.
// convert table names
$sql = $this->fix_table_names($sql);
- // cast booleans to 1/0 int
+ // cast booleans to 1/0 int and detect forbidden objects
foreach ($params as $key => $value) {
+ $this->detect_objects($value);
$params[$key] = is_bool($value) ? (int)$value : $value;
}
/**
* Executes a general sql query. Should be used only when no other method suitable.
- * Do NOT use this to make changes in db structure, use database_manager::execute_sql() instead!
+ * Do NOT use this to make changes in db structure, use database_manager methods instead!
* @param string $sql query
* @param array $params query parameters
* @return bool true
* (Only MySQL needs this. MySQL things that 1 * -1 = 18446744073709551615
* if the 1 comes from an unsigned column).
*
+ * @deprecated since 2.3
* @param string $fieldname The name of the field to be cast
* @return string The piece of SQL code to be used in your statement.
*/
return $text;
}
- /**
- * Returns the proper SQL to do LIKE in a case-insensitive way.
- *
- * Note the LIKE are case sensitive for Oracle. Oracle 10g is required to use
- * the case insensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-(
- * See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches
- *
- * @deprecated since Moodle 2.0 MDL-23925 - please do not use this function any more.
- * @todo MDL-31280 to remove deprecated functions prior to 2.3 release.
- * @return string Do not use this function!
- * @see sql_like()
- */
- public function sql_ilike() {
- debugging('sql_ilike() is deprecated, please use sql_like() instead');
- return 'LIKE';
- }
-
/**
* Returns the proper SQL to do CONCAT between the elements(fieldnames) passed.
*