It's not a very useful warning in that it tells me where the warning happens, but not what the warning actually is. Since the statement executes successfully and correctly, I would like to suppress this warning. Even better, correct the problem so that no warning is generated.
I'm suspicious that the warning has to do with type mismatches in bound expressions. My SQL looks like this:
The types of the variables are: int, int, varchar, int, varchar. Since MySQLdb uses the 'format' systax for SQL placeholders, I originally tried %d, %d, %s, %d, %s. This generated exceptions complaining INT required. Only by changing all the placeholders to %s can I get by without an exception being raised. However, I get these warnings instead.
How can I find out what I am actually being warned about? How can I adjust my SQL and/or code to avoid the warning entirely?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Second, ALWAYS use %s for the placeholder. Always. You should always do this because the value that is going in there is always a string. Even if you are passing something that isn't a string, it is converted to a string and quoted and/or escaped as necessarily.
Third, this particular warning message is generated by MySQL. On an INSERT statement, this is most likely due to truncation.
"Warnings can occur under any of the following conditions:
* Inserting NULL into a column that has been declared NOT NULL.
* Setting a numeric column to a value that lies outside the column's range.
* Assigning a value such as '10.34 a' to a numeric column.
* Inserting a string into a string column (CHAR, VARCHAR, TEXT, or BLOB) that exceeds the column's maximum length.
* Inserting a value into a date or time column that is illegal for the column type.
Without your schema, and the data which causes the warning, it is pointless to speculate on what is happening.
MySQL-4.1 has SHOW WARNINGS, which provides more specific information:
You lead me to the problem: unbeknownst to me, it seems the schema was changed. One of my varchar columns was changed to an enum. The value that I was attempting to insert was now inappropriate. Once corrected, the warning diappeared.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
MySQLdb is sending a warning to stderr in my program:
/usr/lib/python2.3/site-packages/cse/Database.py:201: Warning: Records: 8 Duplicates: 0 Warnings: 8
It's not a very useful warning in that it tells me where the warning happens, but not what the warning actually is. Since the statement executes successfully and correctly, I would like to suppress this warning. Even better, correct the problem so that no warning is generated.
I'm suspicious that the warning has to do with type mismatches in bound expressions. My SQL looks like this:
The types of the variables are: int, int, varchar, int, varchar. Since MySQLdb uses the 'format' systax for SQL placeholders, I originally tried %d, %d, %s, %d, %s. This generated exceptions complaining INT required. Only by changing all the placeholders to %s can I get by without an exception being raised. However, I get these warnings instead.
How can I find out what I am actually being warned about? How can I adjust my SQL and/or code to avoid the warning entirely?
First, read this:
http://docs.python.org/lib/module-warnings.html
Second, ALWAYS use %s for the placeholder. Always. You should always do this because the value that is going in there is always a string. Even if you are passing something that isn't a string, it is converted to a string and quoted and/or escaped as necessarily.
Third, this particular warning message is generated by MySQL. On an INSERT statement, this is most likely due to truncation.
http://dev.mysql.com/doc/mysql/en/insert.html
"Warnings can occur under any of the following conditions:
Without your schema, and the data which causes the warning, it is pointless to speculate on what is happening.
MySQL-4.1 has SHOW WARNINGS, which provides more specific information:
http://dev.mysql.com/doc/mysql/en/show-warnings.html
Excellent, thank you Andy.
You lead me to the problem: unbeknownst to me, it seems the schema was changed. One of my varchar columns was changed to an enum. The value that I was attempting to insert was now inappropriate. Once corrected, the warning diappeared.