I've simplified my code for the purpose of explaining the problem I'm having.
I've got a table in MySQL 5.7 with a BIT(10) column. I've written a stored procedure which performs an INSERT.
BEGIN
INSERT INTO mytable (mycolumn) VALUES (mybinary);
END
In Go, I simply want to invoke this stored procedure. For example:
rows, err := db.Query("CALL my_proc(?)", "1110110101");
However, I get the following error from MySQL:
Error 1406: Data too long for column 'mycolumn' at row 1
I think I know the cause for this error. MySQL is receiving the binary number as a string. Strings are stored using a lot more bits. So when it converts the string to bits its getting multiple bits per character so it's too long. In MySQL I'm aware you can escape a string to show it is binary like this:
INSERT INTO mytable (mycolumn) VALUES (b'1110110101');
But in the stored procedure above, how can I escape the string (as the string variable 'mybinary') to bits (while keeping it as prepared statement)?
Thanks