Inserting into and retrieving from binary string column
See original GitHub issueHello,
I have a table MyKeys with a column that is a binary string of length 16 bytes:
CREATE TABLE MyKeys (id INT AUTO_INCREMENT PRIMARY KEY, myKey BINARY(16))
Now I create an ArrayBuffer of size 16 bytes:
var myBuffer = new ArrayBuffer(16);
Now I want to insert it into the table:
con.query('INSERT INTO MyKeys (myKey) VALUES (?)', [myBuffer],function (err, data) {});
However that is causing an error:
ER_WRONG_VALUE_COUNT_ON_ROW: Column count doesn’t match value count at row 1
sql: “INSERT INTO MyKeys (myKey) VALUES ()”
So it looks like myBuffer is not being sent to MySQL at all.
Any suggestions would be much appreciated. Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How can I insert arbitrary binary data into a VARCHAR column?
Save this answer. Show activity on this post. The short answer is that it shouldn't be possible to insert values with invalid UTF8...
Read more >11.3.3 The BINARY and VARBINARY Types
The BINARY and VARBINARY types are similar to CHAR and VARCHAR , except that they store binary strings rather than nonbinary strings.
Read more >Inserting binary string at an offset to exsting data in a Text type ...
Is it possible to insert binary data in an existing text column, into existing binary data (text type) stored in there, to an...
Read more >How do I identify the column(s) responsible for "String or ...
String or binary data would be truncated in table 'tempdb.dbo.x', column 'a'. Truncated value: 'f'. The statement has been terminated. Until you can...
Read more >String & Binary Data Types - Snowflake Documentation
Data Types for Binary Strings. BINARY. VARBINARY. Internal Representation. Binary Examples in Table Columns. String Constants.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Seems to be working now. Thanks a million, @sidorares & @dougwilson
An
ArrayBuffer
cannot be read directly, as you need to overlay some kind of view over it to read. The Node.jsBuffer
is a view into anArrayBuffer
. You can create a Buffer view of an ArrayBuffer usingBuffer.from(myArrayBuffer)