Skip to content

Conversation

@aristath
Copy link
Member

@aristath aristath commented Dec 14, 2022

Summary

Fixes #599

In addition to the above fix, I encountered some other notices when testing various plugins:

PHP Notice:  Undefined property: stdClass::$name in class-perflab-sqlite-pdo-engine.php on line 1338
PHP Notice:  Undefined property: stdClass::$type in class-perflab-sqlite-pdo-engine.php on line 1339
PHP Notice:  Undefined property: stdClass::$notnull in class-perflab-sqlite-pdo-engine.php on line 1340
PHP Notice:  Undefined property: stdClass::$pk in class-perflab-sqlite-pdo-engine.php on line 1341
PHP Notice:  Undefined property: stdClass::$dflt_value in class-perflab-sqlite-pdo-engine.php on line 1342

This PR adds some additional checks to ensure that $row is an object, and the properties exist before using them.

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

@aristath aristath added [Type] Bug An existing feature is broken [Focus] Database labels Dec 14, 2022
@aristath aristath added this to the 1.8.0 milestone Dec 14, 2022
@aristath aristath requested a review from OllieJones as a code owner December 14, 2022 08:17
@aristath aristath changed the title SQLite fix: Check if properties exist before using them SQLite bugfixes Dec 14, 2022
*/
function _real_escape( $str ) {
return SQLite3::escapeString( $str );
return addslashes( $str );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that fixes #599

Comment on lines +1338 to +1356
if ( ! is_object( $row ) ) {
continue;
}
if ( property_exists( $row, 'name' ) ) {
$_columns['Field'] = $row->name;
}
if ( property_exists( $row, 'type' ) ) {
$_columns['Type'] = $row->type;
}
if ( property_exists( $row, 'notnull' ) ) {
$_columns['Null'] = $row->notnull ? 'NO' : 'YES';
}
if ( property_exists( $row, 'pk' ) ) {
$_columns['Key'] = $row->pk ? 'PRI' : '';
}
if ( property_exists( $row, 'dflt_value' ) ) {
$_columns['Default'] = $row->dflt_value;
}
$_results[] = new Perflab_SQLite_Object_Array( $_columns );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some additional defensive coding to ensure there are no errors.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aristath Great work!

@felixarntz felixarntz changed the title SQLite bugfixes Fix SQLite notices related to undefined properties Dec 14, 2022
Copy link
Member

@mukeshpanchal27 mukeshpanchal27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aristath Now everything is good with import.

@mukeshpanchal27 mukeshpanchal27 merged commit 2a7f89a into trunk Dec 15, 2022
@mukeshpanchal27 mukeshpanchal27 deleted the fix/sqlite-undefined-prop branch December 15, 2022 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite module: Notices thrown during WordPress import

4 participants