Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update read_int #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Update read_int #170

wants to merge 1 commit into from

Conversation

BmdOnline
Copy link

The offset is missing in the calculation.
For example, the MySQL error code returned is false.

The offset is missing in the calculation.
For example, the MySQL error code returned is false.
@ChuckBell
Copy link
Owner

Please specify what version of MySQL you used to test this change.

@BmdOnline
Copy link
Author

Hi,
I used this version :

mysql Ver 15.1 Distrib 10.5.9-MariaDB, for Linux (x86_64) using readline 5.1

But it's not related to MySQL version.
It's a typo in your code,
You forget to apply offset in buffer.

@BmdOnline
Copy link
Author

To be more specific, I'm trying to catch MySQL errors.

For example, try this query when the table arduino doesn't exists:
char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";
You will get this error :
Error: 57 = Table 'test_arduino.hello_arduino' doesn't exist.

According to MySQL reference, it should be:
Error: 1146 = Table 'test_arduino.hello_arduino' doesn't exist.

Buffer, in this case, is :
39:00:00:01:FF:7A:04:23:....

Error code is at and 5th position.
57 is decimal conversion of buffer starting at position 0 : 39:00
1146 is decimal conversion of buffer starting at position 5 : 7A:04

In parse_error_packet from MySQL_Packet.cpp, you're right when writing:

  Bytes                       Name
  -----                       ----
  1                           field_count, always = 0xff
  2                           errno
  1                           (sqlstate marker), always '#'
  5                           sqlstate (5 characters)
  n                           message

And when you're doing :
Serial.print(read_int(5, 2));

Everything seems good, but read_int always return first bytes, not Nth ones (5th in this case).

I haven't checked other usages of read_int.

References
About error codes, from MySQL and MariaDB :
https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
https://mariadb.com/docs/reference/cs10.5/error-codes/
https://mariadb.com/kb/en/mariadb-error-codes/
https://docs.oracle.com/cd/E19078-01/mysql/mysql-refman-5.0/error-handling.html

About decoding error packet, from MySQL and MariaDB :
https://dev.mysql.com/doc/dev/mysql-server/8.0.11/page_protocol_basic_err_packet.html
https://mariadb.com/kb/en/err_packet/

@ChuckBell
Copy link
Owner

Yes, I am well aware of the error packet and I will review your suggestions to ensure it is compatible with Oracle MySQL. I do (can) not make changes to support anything else, hence my guarded questions. I will reply back later this week. Thanks!

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.

2 participants