[Typo3-dev] Strange MYSQL behaviour / type casting with boolean
Robert Lemke
robert at typo3.org
Sun Oct 16 11:59:13 CEST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi folks,
I just stumbled over a very strange behaviour while working on the new TER.
It first appeared after I did an upgrade of my Kubuntu so I suspect it has
to do with either the MySQL (4.0.24) or PHP (5.0.5-2ubuntu1) version.
Imagine the following situation: I want to update a DB record with a field
"clearcacheonload" which contains "1" if cache should be cleared and
otherwise "0".
The table is defined like this:
CREATE TABLE tx_ter_extensiondetails (
...
clearcacheonload tinyint(4) DEFAULT '0' NOT NULL,
...
);
Now, the value I want to put into that field arrives via SOAP, the type is
"boolean". I update the table with this PHP code:
$extensionDetailsRow = array (
...
'clearcacheonload' => $clearCacheOnLoad;
...
);
$this->cObj->DBgetInsert('tx_ter_extensiondetails', $pid,
$extensionDetailsRow, implode (',',array_keys($extensionDetailsRow)),
TRUE);
Imagine $clearCacheOnLoad is (boolean) TRUE, then what I see in the database
afterwards is (integer) 0 ! However, if I change the code like this:
$extensionDetailsRow = array (
...
'clearcacheonload' => (boolean)$clearCacheOnLoad ? 1 : 0;
...
);
... the result is like expected, I see an integer 1 in the database.
Has anyone seen a similar behaviour or can you reproduce that with other
PHP / MySQL versions?
Cheers,
robert
PS: I'm really glad that I'm running unit tests regularly, otherwise I'd
never have spotted that bug!
- --
Robert Lemke
TYPO3 Association - Research & Development
Member of the board
http://association.typo3.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDUiR3Du+3qCHvGSIRAmKhAJwJdKdZsUgL8ECRAkvG3Fdqkp32TgCfQ3zT
Gz5Tak6fHfN4wxMUuNxUZPc=
=CJ55
-----END PGP SIGNATURE-----
More information about the TYPO3-dev
mailing list