Skip to content
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

Primary key with value 0 #13

Closed
simara-esports opened this issue Jun 17, 2014 · 2 comments
Closed

Primary key with value 0 #13

simara-esports opened this issue Jun 17, 2014 · 2 comments
Labels

Comments

@simara-esports
Copy link

Hi,

if there is a row with value "0" in primary key column, the field won't appear in the result.
It is overwritten (or can overwrite other row).
The problem is here: https://github.com/nette/database/blob/master/src/Database/Table/Selection.php#L506
quickfix:

$this->rows[($primary || $primary === "0" || $primary === 0) ? $primary : $key] = $row;

But i'm not sure how clear is this solution.

@hrach hrach added the 1-bug label Oct 18, 2014
@mdjimy
Copy link

mdjimy commented Mar 16, 2015

Yes, the solution you have proposed should work just fine (to solve yours problem). Maybe little bit modified to:

...
$primary = $row->getSignature(FALSE);
$usedPrimary &= $primary || $primary === '0';
$this->rows[$primary || $primary === '0' ? $primary : $key] = $row;
...

But, I've found out, that problem is more complex, than it may seem!
Lets work with a table which have composite (multi-column) primary key, where atleast one of primary columns is of type datetime, date, time, timestamp or interval.

Then an exception is thrown due to fact, that method getSignature tries to convert given DateTime or DateInterval object to string, but those objects don't have __toString method.

I have already prepared bug fix, but before I'll create pull request I have to write some test cases :)

@dg
Copy link
Member

dg commented Sep 21, 2015

Fixed c377bf6

@dg dg closed this as completed Sep 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants