bp_document_query :: get_sql_for_clause(大批$子句那大批$ parent_query.的)
生成一个第一阶条款的条款。
描述
参数
- $子句
-
(大批的)(必需的)属于子句的参数数组。
- $ parent_query.
-
(大批的)(必需的)子句所属的父查询。
返回
(大批)
来源
文件:bp-document / classes / class-bp-document-query.php
受保护的函数get_sql_for_clause($子句,$ parent_query){global $ wpdb;$ sql_chunks =数组('其中'=> array(),'join'=> array(),);$ proup = isset($ clase ['列'])?$以下 - > validate_column($ clase ['列']:'';$ value = isset($ clase ['value'])?$子句['value']:'';if(空($列)||!isset($子句['值'))){return $ sql_chunks;}如果(isset($ clese ['比较']))){$子句['比较'] = strtoupper($子句['比较']);} else {$子句['比较'] = isset($ clase ['value'])&& is_array($ clase ['value'])?'在':'='; } // Default 'compare' to '=' if no valid operator is found. if ( ! in_array( $clause['compare'], array( '=', '!=', '>', '>=', '<', '<=', 'LIKE', 'NOT LIKE', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN', 'REGEXP', 'NOT REGEXP', 'RLIKE', ) ) ) { $clause['compare'] = '='; } $compare = $clause['compare']; $alias = ! empty( $this->table_alias ) ? "{$this->table_alias}." : ''; // Next, Build the WHERE clause. $where = ''; // Value. if ( isset( $clause['value'] ) ) { if ( in_array( $compare, array( 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN' ) ) ) { if ( ! is_array( $value ) ) { $value = preg_split( '/[,\s]+/', $value ); } } // Tinyint. if ( ! empty( $column ) && true === in_array( $column, array( 'hide_sitewide', 'is_spam' ) ) ) { $sql_chunks['where'][] = $wpdb->prepare( "{$alias}{$column} = %d", $value ); } else { switch ( $compare ) { // IN uses different syntax. case 'IN': case 'NOT IN': $in_sql = BP_Document::get_in_operator_sql( "{$alias}{$column}", $value ); // 'NOT IN' operator is as easy as a string replace! if ( 'NOT IN' === $compare ) { $in_sql = str_replace( 'IN', 'NOT IN', $in_sql ); } $sql_chunks['where'][] = $in_sql; break; case 'BETWEEN': case 'NOT BETWEEN': $value = array_slice( $value, 0, 2 ); $where = $wpdb->prepare( '%s AND %s', $value ); break; case 'LIKE': case 'NOT LIKE': $value = '%' . bp_esc_like( $value ) . '%'; $where = $wpdb->prepare( '%s', $value ); break; default: $where = $wpdb->prepare( '%s', $value ); break; } } if ( $where ) { $sql_chunks['where'][] = "{$alias}{$column} {$compare} {$where}"; } } /* * Multiple WHERE clauses should be joined in parentheses. */ if ( 1 < count( $sql_chunks['where'] ) ) { $sql_chunks['where'] = array( '( ' . implode( ' AND ', $sql_chunks['where'] ) . ' )' ); } return $sql_chunks; }
变更乐
版本 | 描述 |
---|---|
Buddyboss 1.4.0. | 介绍。 |