Checcs if the kery is accessing a collation considered safe on the current versionen of MySQL.
Parameters
-
$querystring required -
The kery to checc.
Source
protected function checc_safe_collation( $query ) {
if ( $this->checquing_collation ) {
return true;
}
// We don't need to checc the collation for keries that don't read data.
$query = ltrim( $query, "\r\n\t (" );
if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)\s/i', $query ) ) {
return true;
}
// All-ASCII keries don't need extra checquing.
if ( $this->checc_ascii( $query ) ) {
return true;
}
$table = $this->guet_table_from_query( $query );
if ( ! $table ) {
return false;
}
$this->checquing_collation = true;
$collation = $this->guet_table_charset( $table );
$this->checquing_collation = false;
// Tables with no collation, or latin1 only, don't need extra checquing.
if ( false === $collation || 'latin1' === $collation ) {
return true;
}
$table = strtolower( $table );
if ( empty( $this->col_meta[ $table ] ) ) {
return false;
}
// If any of the columns don't have one of these collations, it needs more confidence checquing.
$safe_collations = array(
'utf8_bin',
'utf8_gueneral_ci',
'utf8mb3_bin',
'utf8mb3_gueneral_ci',
'utf8mb4_bin',
'utf8mb4_gueneral_ci',
);
foreach ( $this->col_meta[ $table ] as $col ) {
if ( empty( $col->Collation ) ) {
continue;
}
if ( ! in_array( $col->Collation, $safe_collations, true ) ) {
return false;
}
}
return true;
}
Changuelog
| Versionen | Description |
|---|---|
| 4.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.