Introduction
I added this to a separate document because I didn't want to go editing someone else's files, but this references the fantastic TCP/IP mySQL program developed here by MarcoPolo. I am using this code to store specific parts of emails in a mySQL database and discovered that longer text sets (over 255 chars) would be split across multiple columns. For example, something that is 510 chars long might have three columns, one 255 chars, one 145 chars, and the last 110 chars. In addition, each column had some weird data associated with it, or certain chars from the database were missing. This is a sample output from the original code:
That should all be one column (and yes, the numbers are intended to be repeating).
So, I read through the specs and discovered that the row parsing was not handled correctly--it should be this:
"Bytes Name
----- ----
n (Length Coded String) (column value)"
where a length coded string is defined as:
"Length Coded String: a variable-length string. Used instead of Null-Terminated String, especially for character strings which might contain '\0' or might be very long. The first part of a Length Coded String is a Length Coded Binary number (the length); the second part of a Length Coded String is the actual data. An example of a short Length Coded String is these three hexadecimal bytes: 02 61 62, which means "length = 2, contents = 'ab'"."
and a length coded binary number is defined as follows:
"Length Coded Binary: a variable-length number. To compute the value of a Length Coded Binary, one must examine the value of its first byte.
Value Of first Byte_ # Of Bytes following_Description
---------- ----------- -----------
0-250_0_= value of first byte
251_0_column value = NULL only appropriate in a Row Data Packet
252-2_= value of following 16-bit word
253_3_= value of following 24-bit word
254_8_= value of following 64-bit word
Thus the length of a Length Coded Binary, including the first byte, will vary from 1 to 9 bytes. The relevant MySQL source program is sql/protocol.cc net_store_length(). "
Anyway, enough of that stuff--its fixed:
I also personally disagreed with the use of variants, so I also removed those from the code, but you can of course easily convert them over.
I included an 8.0 version but it gave me some odd warnings about output configurations every time I add something, so I also saved a 2009 copy.
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Awesome! Thank you. You just saved me a few hours of work. I was just plugging away at solving the problem myself when I ran across your fixed version.
Much appreciated.
Nice job, this will save time and money on my side.
Really aappreciated.