473,388 Members | 1,385 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

userdefined exceptions in mysql

Hi ,

We are trying to convert stored procedures from mssql to mysql as a part of db migration, and we are facing the following issue.

In mssql , business exceptions can be raised by using RAISERROR function as given below
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.NEXT_SEQ_VAL(@seqName VARCHAR(100),@increment int = 1)
  2. AS
  3. BEGIN
  4.   DECLARE @NSN int,
  5.   @TRIES int
  6.  
  7.   IF @increment < 1
  8.   BEGIN
  9.     RAISERROR('increment parameter must be > 0', 16, 1)
  10.     RETURN -1
  11.   END
  12. SELECT @NSN = SEQUENCE_INDEX FROM SEQUENCE_GEN WHERE SEQUENCE_NAME = @seqName
  13.   --PRINT 'NSN=' + ISNULL(convert(varchar,@NSN),'NULL')
  14.   IF @NSN IS NULL
  15. BEGIN
  16.     --PRINT 'INSERT SEQUENCE_GEN ROW FOR ' + @seqName
  17.     INSERT INTO SEQUENCE_GEN(SEQUENCE_NAME,SEQUENCE_INDEX) VALUES (@seqName,1)
  18.     SET @NSN = 1
  19.   END
  20. RETURN @NSN
  21. END
  22.  
for migrating the above code to mysql i have three doubts
1.how can i set the default value for increment parameter to 1.
2.how can i raise a business exception like above.
3.as i know procedures does not return any value but function will return values,then
in the above code return -1 is doing what?and how can i do the same in mysql.
please do the need full as soon as possible.

Thanks in advance,

Vijaya.
Jul 28 '08 #1
1 4415
Atli
5,058 Expert 4TB
Hi.
To answer your questions:
  1. You can't. MySQL (unfortunetly) does not support default values for procedure parameters. All parameters declared must be passed.
  2. MySQL does not yet provide a method of calling a custom error, such as the MSSQL RaiseError function. In the 5.x versions, you must "provoke" and error by using syntax that would cause an error. Like say, calling a procedure that doesn't exist, which would cause an error that your client could catch.
  3. That's correct, procedures do not return values, but functions do. The syntax for both is very similar tho so it shouldn't be a problem to convert your procedure into a function. Check out the manual to see the differences.
Jul 28 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Hector Villafuerte | last post by:
Hi, I have been using Python 2.3.4 with MySQL 4.0.16-max-nt (through MySQLdb) for months. Today this messages showed up: Exception exceptions.AttributeError: "'NoneType' object has no attribute...
2
by: Ramza Brown | last post by:
This mysql_error doesnt give me an error below, but when I run it at the global scope it does give me errors. I went ahead and checked for mysql_error(), but normally I dont have to, why? ...
2
by: parez | last post by:
Hi All! This is the first time i am tryin to write a sql server 2000 function. I need to clean up some of my stored procedures.. Can any one please give me skeleton for a userdefined function...
3
by: Daniel Lidström | last post by:
Hello, I want to have a class that contains only a collection of another class. For example: public __gc class Alignment { public: Alignment(); ... };
1
by: Olimpio | last post by:
Hi, Someone knows about. How can i create exceptions or display messages in triggers, as the commands "raiserror" and "Print" in sqlserver ? Thanks, Olimpio.
6
by: newlearner | last post by:
Hi, i know we can wirte a userdefined callback function.. I had a try for a long time though i feel im near but not able to coin out the exact thing. can any body tell me about a user defined...
0
by: =?Utf-8?B?a3Jpc2huYQ==?= | last post by:
Hi i am getting the following error while using XMLSerializer XmlSerializer ser = new XmlSerializer(typeof(Person)); ERROR: Unable to generate a temporary class (result=1). error CS0266: Cannot...
0
by: WebCM | last post by:
PDO offers 3 modes of displaying errors: - silent mode - no errors - warnings - Warning: - exceptions - Exception: Which of them is the fastest and the most adequate for applications like CMS...
2
by: SnehaAgrawal | last post by:
Does anyone know how to call a UserDefined Function written in SQL 2000 from program(I mean I am writing code in VB.net)..I know how to call it from a stored proc. but don't know how to call from my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.