PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, July 17, 2022

[FIXED] How can I inform sqlalchemy to raise an error whenever MySQL throws a warning?

 July 17, 2022     mysql, mysql-python, python, sqlalchemy, warnings     No comments   

Issue

I want to modify sqlalchemy settings to raise an exception on warnings.

For example, when I insert a larger amount of data in a field than the defined column length, mysql will truncate the data, insert the truncated data into the field and issue a warning.

Instead of the warning, I would like sqlalchemy to raise an appropriate error on behalf of mysql.


Solution

To turn the “oh by the way I mangled your data” warnings into errors, set an appropriate server mode for MySQL. With SQLAlchemy, you should choose ANSI, as you probably don't have to worry about your old queries being compatible with some brokenMySQL-specific behavior.

See the SQLAlchemy docs on how to do it.


(Also consider using a database that's strict by default. Postgres comes to mind.)



Answered By - Petr Viktorin
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing