Skip to content

Conversation

bjoernhaeuser
Copy link
Collaborator

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

@julien-duponchelle
Copy link
Owner

Tested with python 2.7 and python 3
Merged

Thanks a lot

@bjoernhaeuser
Copy link
Collaborator Author

Sorry, but where are the commits? ;)

@julien-duponchelle
Copy link
Owner

Ho i forgot again to push

@lxyu
Copy link
Contributor

lxyu commented Jul 3, 2014

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?

@bjoernhaeuser
Copy link
Collaborator Author

How do you know that the value was a TINYINT(1)?

@lxyu
Copy link
Contributor

lxyu commented Jul 4, 2014

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.

@lxyu
Copy link
Contributor

lxyu commented Jul 4, 2014

It's always easy to translate a number to bool in apps. In this data layer, let's expose the original data.

@lxyu lxyu mentioned this pull request Jul 7, 2014
lxyu added a commit to lxyu/python-mysql-replication that referenced this pull request Jul 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants