Skip to content

Commit

Permalink
minor coding tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Sep 14, 2022
1 parent a402a50 commit 03ca040
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/wp-includes/sqlite/class-wp-pdo-engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public function query( $statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, ...$fet
case 'set':
$this->return_value = false;
break;

case 'foundrows':
$_column = array( 'FOUND_ROWS()' => '' );
$column = array();
Expand All @@ -369,13 +370,15 @@ public function query( $statement, $mode = PDO::ATTR_DEFAULT_FETCH_MODE, ...$fet
$this->found_rows_result = null;
}
break;

case 'insert':
if ( $this->can_insert_multiple_rows ) {
$this->execute_insert_query_new( $statement );
} else {
$this->execute_insert_query( $statement );
}
break;

case 'create':
$this->return_value = $this->execute_create_query( $statement );
break;
Expand Down Expand Up @@ -616,14 +619,12 @@ private function flush() {
*/
private function prepare_engine( $query_type = null ) {
if ( stripos( $query_type, 'create' ) !== false ) {
$engine = new WP_SQLite_Create_Query();
} elseif ( stripos( $query_type, 'alter' ) !== false ) {
$engine = new WP_SQLite_Alter_Query();
} else {
$engine = new WP_PDO_SQLite_Driver();
return new WP_SQLite_Create_Query();
}

return $engine;
if ( stripos( $query_type, 'alter' ) !== false ) {
return new WP_SQLite_Alter_Query();
}
return new WP_PDO_SQLite_Driver();
}

/**
Expand Down Expand Up @@ -771,7 +772,6 @@ private function execute_query( $statement ) {
private function extract_variables() {
if ( 'create' === $this->query_type ) {
$this->prepared_query = $this->rewritten_query;

return;
}

Expand Down Expand Up @@ -997,13 +997,16 @@ private function parse_multiple_inserts( $values ) {
$part .= $token;
}
break;

case "'":
$literal = ! $literal;
$part .= $token;
break;

default:
$part .= $token;
break;

}
}
if ( ! empty( $part ) ) {
Expand Down Expand Up @@ -1226,10 +1229,7 @@ private function set_error( $line, $function, $message ) {
);
$this->error_messages[] = $message;
$this->is_error = true;
if ( $wpdb->suppress_errors ) {
return false;
}
if ( ! $wpdb->show_errors ) {
if ( $wpdb->suppress_errors || ! $wpdb->show_errors ) {
return false;
}
error_log( "Line $line, Function: $function, Message: $message" );
Expand Down Expand Up @@ -1338,6 +1338,7 @@ private function convert_to_index_object() {
$_columns['Column_name'] = $col_name;
}
break;

case 'index':
$_columns['Non_unique'] = 1;
if ( stripos( $row->sql, 'unique' ) !== false ) {
Expand All @@ -1349,6 +1350,7 @@ private function convert_to_index_object() {
}
$_columns['Key_name'] = $row->name;
break;

}
$_columns['Table'] = $row->tbl_name;
$_columns['Collation'] = null;
Expand All @@ -1364,8 +1366,7 @@ private function convert_to_index_object() {
preg_match( '/WHERE\\s*(.*)$/im', $this->queries[0], $match );
list($key, $value) = explode( '=', $match[1] );
$key = trim( $key );
$value = preg_replace( "/[\';]/", '', $value );
$value = trim( $value );
$value = trim( preg_replace( "/[\';]/", '', $value ) );
foreach ( $_results as $result ) {
if ( ! empty( $result->$key ) && is_scalar( $result->$key ) && stripos( $value, $result->$key ) !== false ) {
unset( $_results );
Expand All @@ -1375,6 +1376,7 @@ private function convert_to_index_object() {
}
}
}

$this->results = $_results;
}

Expand All @@ -1384,22 +1386,15 @@ private function convert_to_index_object() {
* @access private
*/
private function convert_result_check_or_analyze() {
$results = array();
$_columns = array(
'Table' => '',
'Op' => 'analyze',
'Msg_type' => 'status',
'Msg_text' => 'Table is already up to date',
);
if ( 'check' === $this->query_type ) {
$_columns = array(
$is_check = 'check' === $this->query_type;
$_results[] = new WP_SQLite_Object_Array(
array(
'Table' => '',
'Op' => 'check',
'Op' => $is_check ? 'check' : 'analyze',
'Msg_type' => 'status',
'Msg_text' => 'OK',
);
}
$_results[] = new WP_SQLite_Object_Array( $_columns );
'Msg_text' => $is_check ? 'OK' : __( 'Table is already up to date' ),
)
);
$this->results = $_results;
}

Expand Down

0 comments on commit 03ca040

Please sign in to comment.