Add support for TINYINT(1) to bool() Mapping by bjoernhaeuser · Pull Request #16 · julien-duponchelle/python-mysql-replication (original) (raw)
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 andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation7 Commits1 Checks0 Files changed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})
Hey,
we discussed this on the mailing list. Here it is! The Values will be piped through the bool()
function. Therefore everything > 0 is True
.
The other changes are cosmetic ones, introduced by my PyCharm-IDE.
Thanks in advance
Björn
Tested with python 2.7 and python 3
Merged
Thanks a lot
Sorry, but where are the commits? ;)
Ho i forgot again to push
I just come across a problem when I try to replicate from mysql binlog to postgresql. Postgresql seperate smallint from boolean, so this conversion broke the replication, since the column type and column value changed.
The problem here is, the mapping changed the original value, and I don't think it's correct. The bool()
process could be easily done in the application layer, while the replication should expose the original value stored in database.
Any thoughts on this?
How do you know that the value was a TINYINT(1)?
TINYINT(1):
a very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.
BOOL:
A value of zero is considered false. Nonzero values are considered true
So it's actually a number, sometimes we store a number in TINYINT(1)
, and convert it to BOOL
will lost this.
Check this example:
mysql> create table b (i tinyint(1));
mysql> insert into b values (42);
mysql> select * from b;
+------+
| i |
+------+
| 42 |
+------+
mysql> create table c (i boolean);
mysql> insert into c values (20);
mysql> select * from c;
+------+
| i |
+------+
| 20 |
+------+
There's no BOOLEAN
in mysql, it's only number.
It's always easy to translate a number to bool in apps. In this data layer, let's expose the original data.
lxyu mentioned this pull request
lxyu added a commit to lxyu/python-mysql-replication that referenced this pull request