Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Conversation

settermjd
Copy link

When attempting to use both columns() and values() together to set the columns and value for an insert object, and when passing non-associative arrays to both, as seems logically correct to be able to do,
the generated SQL query has the numeric keys of the values array overwrite the columns set from the array passed to columns().

What I would expect is that the two were properly combined. This minor
fix does that, and leaves the remaining functionality in place. For example, I'd expect that if I had the following:

$this->insert
    ->into('foo')
    ->columns(['col1', 'col2', 'col3'])
    ->values(['val1', 'val2', 'val3']);

That the generated SQL would be:

INSERT INTO foo ("col1", "col2", "col3") VALUES("val1", "val2", "val3");

Without this patch, the generated SQL would be:

INSERT INTO foo ("0", "1", "2") VALUES("val1", "val2", "val3");

When attempting to use both columns() and values() together to set the
columns and value for an insert object, and when passing non-associative
arrays to both, as seems logically correct to be able to do,
the generated SQL query has the numeric keys of the values array
overwrite the columns set from the array passed to columns().
What I would expect is that the two were properly combined. This minor
fix does that, and leaves the remaining functionality in place.
/**
* Simple test for an associative array
* @link http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential
* @param $arr
Copy link
Contributor

Choose a reason for hiding this comment

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

@param array $arr

@weierophinney weierophinney added this to the 2.7.1 milestone Apr 12, 2016
@weierophinney weierophinney self-assigned this Apr 12, 2016
@weierophinney
Copy link
Member

Nice patch, @settermjd ! Thanks!

@weierophinney weierophinney merged commit 5a26129 into zendframework:master Apr 12, 2016
weierophinney added a commit that referenced this pull request Apr 12, 2016
…columns-and-values-methods-are-used

Refactor Insert::values() method to properly merge values with columns
weierophinney added a commit that referenced this pull request Apr 12, 2016
weierophinney added a commit that referenced this pull request Apr 12, 2016
weierophinney added a commit that referenced this pull request Apr 12, 2016
@settermjd
Copy link
Author

Not a problem at all @weierophinney. I'm aiming to be more active this year. Thanks for the feedback @samsonasik

@settermjd settermjd deleted the feature/fix-generated-sql-when-columns-and-values-methods-are-used branch May 2, 2016 07:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants