Forum Moderators: coopster
When I exported the database to a .csv file, I get 0's for unchecked and 1's for checked boxes. In my Mysql table, I'm using the enumerated data type for the corresponding fields ('y','n'). It appears that what's happening is that when I upload the .csv file to Mysql, I get the first enumerated selection on all fields imported.
So what is the right way to go from Access Yes/No checkboxes to the Mysql enumerated data type?
when I upload the .csv file to Mysql, I get the first enumerated selection on all fields imported.
So you are getting a 'y' for every entry? That's odd, I would have expected you to get the empty string (numerical value zero) for every entry since neither '0' nor '1' are present in the list of allowed values. I'm assuming you are using LOAD DATA to get the table populated?
Anyway, I guess one of the easiest ways to do this would be to CREATE your TABLE originally with the column set to, oh, perhaps type BOOL. Import your data, then ALTER TABLE to MODIFY the column to type ENUM. Example:
CREATE TABLE testenum (nbr TINYINT UNSIGNED, val BOOL);
INSERT INTO testenum VALUES (1, '0');
INSERT INTO testenum VALUES (2, '1');
INSERT INTO testenum VALUES (3, '');
SELECT nbr, val FROM testenum;
+-----+-----+
¦ nbr ¦ val ¦
+-----+-----+
¦ 1 ¦ 0 ¦
¦ 2 ¦ 1 ¦
¦ 3 ¦ 0 ¦
+------+----+
SELECT nbr, val+0 FROM testenum;
+------+-------+
¦ nbr ¦ val+0 ¦
+------+-------+
¦ 1 ¦ 0 ¦
¦ 2 ¦ 1 ¦
¦ 3 ¦ 0 ¦
+------+-------+
ALTER TABLE testenum MODIFY val ENUM('y','n') NOT NULL;
SELECT nbr, val FROM testenum;
+-----+-----+
¦ nbr ¦ val ¦
+-----+-----+
¦ 1 ¦ ¦
¦ 2 ¦ y ¦
¦ 3 ¦ ¦
+-----+-----+
SELECT nbr, val+0 FROM testenum;
+------+-------+
¦ nbr ¦ val+0 ¦
+------+-------+
¦ 1 ¦ 0 ¦
¦ 2 ¦ 1 ¦
¦ 3 ¦ 0 ¦
+------+-------+