Database - normalize values #806

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
3 participants
@juzna
Contributor

juzna commented Oct 8, 2012

Bug: database values are not properly normalized to valid php types.

When column in a mysql db is of type bit(1), it's then fetched as binary, i.e. \0 or \1, instead of booleans (false or true) - tested on PHP 5.3.16.
On PHP 5.4.7 numeric strings are returned ("0" or "1").

The biggest problem in 5.3 is that these binary strings evaluate to true in conditions! Thus if ($row->flag) always matches.

I don't know how to fix this atm, so at least attaching a simple test case. Suggestions or comments welcomed.

@juzna

This comment has been minimized.

Show comment
Hide comment
@juzna

juzna Oct 8, 2012

Contributor

The problem is probably in PDO, because PDOStatement::getColumnMeta doesn't return native_type for bit column:

Here is the output for long and bit columns:

array(7) {
   native_type => "LONG" (4)
   flags => array(0)
   table => "bittest" (7)
   name => "id" (2)
   len => 11
   precision => 0
   pdo_type => 2
}

array(6) {
   flags => array(1) [
      0 => "not_null" (8)
   ]
   table => "bittest" (7)
   name => "flag" (4)
   len => 1
   precision => 0
   pdo_type => 2
}
Contributor

juzna commented Oct 8, 2012

The problem is probably in PDO, because PDOStatement::getColumnMeta doesn't return native_type for bit column:

Here is the output for long and bit columns:

array(7) {
   native_type => "LONG" (4)
   flags => array(0)
   table => "bittest" (7)
   name => "id" (2)
   len => 11
   precision => 0
   pdo_type => 2
}

array(6) {
   flags => array(1) [
      0 => "not_null" (8)
   ]
   table => "bittest" (7)
   name => "flag" (4)
   len => 1
   precision => 0
   pdo_type => 2
}
@juzna

This comment has been minimized.

Show comment
Hide comment
@juzna

juzna Oct 8, 2012

Contributor

It's probably PDO's problem - https://bugs.php.net/bug.php?id=63244

Contributor

juzna commented Oct 8, 2012

It's probably PDO's problem - https://bugs.php.net/bug.php?id=63244

@enumag

This comment has been minimized.

Show comment
Hide comment
@enumag

enumag Oct 12, 2012

Contributor

Yeah it's a PDO bug. I know about it for a long time now. While you are at it could you please also fix tinyint? NDB returns a string instead of an integer for tinyint.

Contributor

enumag commented Oct 12, 2012

Yeah it's a PDO bug. I know about it for a long time now. While you are at it could you please also fix tinyint? NDB returns a string instead of an integer for tinyint.

@enumag

This comment has been minimized.

Show comment
Hide comment
@enumag

enumag Oct 12, 2012

Contributor

By the way is there some other way to determine mysql type of a column except PDOStatement::getColumnMeta? I think that would be a better way to solve this.

Contributor

enumag commented Oct 12, 2012

By the way is there some other way to determine mysql type of a column except PDOStatement::getColumnMeta? I think that would be a better way to solve this.

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