gcdb::strip_invalid_text_from_query()
最后更新于:2021-11-26 09:05:24
gcdb::strip_invalid_text_from_query( string$query)Strips any invalid characters from the query.
参数
- $query
-
(string) (Required) Query to convert.
响应
(string|GC_Error) The converted query, or a GC_Error object if the conversion fails.
源文件
文件: gc-includes/gc-db.php
protected function strip_invalid_text_from_query( $query ) {
// We don't need to check the collation for queries that don't read data.
$trimmed_query = ltrim( $query, "rnt (" );
if ( preg_match( '/^(?:SHOW|DESCRIBE|DESC|EXPLAIN|CREATE)s/i', $trimmed_query ) ) {
return $query;
}
$table = $this->get_table_from_query( $query );
if ( $table ) {
$charset = $this->get_table_charset( $table );
if ( is_gc_error( $charset ) ) {
return $charset;
}
// We can't reliably strip text from tables containing binary/blob columns.
if ( 'binary' === $charset ) {
return $query;
}
} else {
$charset = $this->charset;
}
$data = array(
'value' => $query,
'charset' => $charset,
'ascii' => false,
'length' => false,
);
$data = $this->strip_invalid_text( array( $data ) );
if ( is_gc_error( $data ) ) {
return $data;
}
return $data[0]['value'];
}