I’m working on an existing database implementation (SQL and MySQL). Right now I need to change the datatype of one column from smallint to mediumint. While this wouldn’t be a problem, the problem is the way updates are handled in the implementation.
On each start the program executes a simple MySQL statement (like SELECT xyz FROM 'tablename') to test if an update is needed. If the statement throws an error (like on the example when ‘xyz’ doesn’t exist) the update itself is executed (in the example, ‘xyz’ would be created).
So what I need is a statement that throws an error if the datatype of the column is smallint. I can only thing of writing an integer bigger than 65535 into the database but this isn’t an option of course.
If there is no such possibility and I actual need to change the way updates are handled, is there an easy way to check if the datatype of column ‘xyz’ is smallint?
Thanks.
Handling flow control (logic) using exceptions is bad design: Exceptions are for “the exceptional”.
Consider changing your design to not require exceptions. For example, query the catalog to find out what you need:
It seems that everything you need to know can be found in the
information_schematables.