Click here to Skip to main content
15,889,830 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have created a stored procedure with using some handlers 1062 handler and 1264 handler
1062 handler working fine.but 1264 handler is not working.After creating sp and while executing

--showing 1062 error correct

call insert_article_tags_2(1,1)


--it is not showing out of range errror
call insert_article_tags_2(155555555555555,1877777755555555555)

why please help me on this.thanks in advance.

What I have tried:

SQL
DELIMITER $$
CREATE PROCEDURE insert_article_tags_2(IN article_id INT, IN tag_id INT)
BEGIN
 
 declare exit handler for sqlexception
 select 'sql exception invoked';
 
 
 DECLARE EXIT HANDLER FOR 1062 
 
        SELECT 'MySQL error code 1062 invoked';
        
 DECLARE EXIT HANDLER FOR 1264

	SELECT 'Out of range exception';


 -- insert a new record into article_tags
 INSERT INTO article_tags(article_id,tag_id)
   VALUES(article_id,tag_id);
    
END
Posted
Updated 27-Aug-17 23:01pm
v4

1 solution

It depends from where you are calling
call insert_article_tags_2(155555555555555,1877777755555555555)
The passed arguments are beyond the values that can be hold by a 32-bit integer (the used type for SQL INT). The language / shell or from where you are calling it may just truncate the passed arguments:
155555555555555 = 8D7A19A1B8E3 hex
That may be truncated to
19A1B8E3 hex = 430029027
which is a valid value.
 
Share this answer
 
Comments
Member 13153537 28-Aug-17 5:05am    
thanks for the reply.i am calling mysql workbench itself.what i want is if i pass those values(155555555555555,1877777755555555555) i want the out of range error.What have i created above using handler 1264.
Jochen Arndt 28-Aug-17 5:20am    
I don't know how MySQL Workbench parses and handles the input. But in your case the Workbench itself should (at least) generate a warning that the input numbers are truncated.

Just a guess what is happening:
The Workbench is parsing the input and converts the numbers from text to numeric values.

If the Workbench supports 64-bit numbers, it should issue a warning, cast the numbers to 32 bit (INT) and passes them.

If the Workbench does not support 64-bit numbers, it should check the input for large values itself and throw an error.

In all cases it is a problem of the Workbench that finally passes a (valid) 32-bit INT to MySQL so that MySQL never gets an invalid value.

You might test it with a value between 2147483647 and 4294967295. These are invalid signed INTs but valid unsigned integers and might get passed through by the Workbench.
Member 13153537 28-Aug-17 5:28am    
workbench throwing error when i passing these values like this call insert_article_tags_2(4300290271,4300290271) Error Code: 1264. Out of range value for column 'article_id' at row 1

i want show this error instead of mysql showing error.I am handling this error using this
DECLARE EXIT HANDLER FOR 1264
SELECT 'Out of range exception'
Jochen Arndt 28-Aug-17 5:45am    
I'm sorry, but I still don't get it now what kind of error is shown when (values) by which (SQL or Workbench).

If you call the procedure with numeric INT values (not text), there will be never an out of range error from SQL because all possible 32-bit INT values are valid.

To get the error generated by SQL, you have to pass it as text so that SQL does the conversion (untested):
call insert_article_tags_2('155555555555555','1877777755555555555')
Member 13153537 28-Aug-17 5:55am    
Anyway thanks for the help.But this doesn't solve my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900