New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrects NULL export values. #93

Merged
merged 2 commits into from Sep 14, 2018

Conversation

2 participants
@antigenius
Copy link
Contributor

antigenius commented Sep 12, 2018

The code that exports a search-replace command as SQL creates a prepared
statement where all columns values are assumed to be strings. Normally
this is fine as MySQL/MariaDB will do the conversion work at import.
However, in some cases, a column may allow nulls in a numeric field.
In this instance, the call to prepare will translate a null value into
null string. Importing will then fail as null string is not a numeric
value.

This patch replaces the original code that assumed strings for all bind
parameters. Each column value is iterated over and inspected. If the
value is not NULL, the value is added to the $values array and a bind
parameter, %s is added to a substituions array. If the value causes
is_null to return true, only 'NULL' is added to the substituions
array.

The code then evaluates as it did previously, with a join call
creating a string from the substitutions array and appending that string
to the larger SQL query.

This closes #82.

Corrects NULL export values.
The code that exports a search-replace command as SQL creates a prepared
statement where all columns values are assumed to be strings. Normally
this is fine as MySQL/MariaDB will do the conversion work at import.
However, in some cases, a column may allow nulls in a numeric field.
In this instance, the call to `prepare` will translate a null value into
null string. Importing will then fail as null string is not a numeric
value.

This patch replaces the original code that assumed strings for all bind
parameters. Each column value is iterated over and inspected. If the
value is not NULL, the value is added to the `$values` array and a bind
parameter, `%s` is added to a substituions array. If the value causes
`is_null` to return true, only 'NULL' is added to the substituions
array.

The code then evaluates as it did previously, with a `join` call
creating a string from the substitutions array and appending that string
to the larger SQL query.

This closes #82.
$subs = array();
foreach( $row_fields as $field_value ) {
if ( is_null($field_value) ) {

This comment has been minimized.

@schlessera

schlessera Sep 13, 2018

Member

Please use the following construct here:

if ( null === $field_value ) {
@schlessera

This comment has been minimized.

Copy link
Member

schlessera commented Sep 13, 2018

Thanks for the pull-request, @antigenius. I have only a very minor gripe, and then the PR can be merged.

Updates NULL detection.
As per @schlessera's request.
@antigenius

This comment has been minimized.

Copy link
Contributor

antigenius commented Sep 13, 2018

You're welcome, @schlessera! My sysadmin found this issue after running into some trouble. Happy to help! PR updated. 😄

@schlessera schlessera added this to the 2.0.1 milestone Sep 14, 2018

@schlessera schlessera merged commit 95dee3d into wp-cli:master Sep 14, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@antigenius antigenius deleted the antigenius:null-export-fix branch Sep 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment