Skip to main content

MSSQL to MySQL

To day i was struggling to catch a error inside a stored procedure using MySQL. Faced lot of difficulties and still not found good result. There is no equal function in MySql to RAISERROR in MSSQL.

As a solution for this what we can we do is, we can call a function as this way
CALL RaiseError();

There for because of the none existence of this function this will be raise an error.
So it is very logical..:-)

So procedure will be work very fine.....Great...

Example:

DROP PROCEDURE IF EXISTS `dbname`.`procedureName` $$
CREATE DEFINER=`root`@`%` PROCEDURE `edbname`.`procedureName`(
pId bigint,
pName varchar(50)

BEGIN

IF EXISTS
(SELECT
1
FROM
tableName
WHERE
((Id = pId)
)
THEN

UPDATE
tableName
SET
Name = pName,

WHERE
(Id = pId);

ELSE
CALL RaiseError();
/*There is no RaiseError metho in MySql.
Because of that reason here call nonexistent method which is 'RaiseError()'.There for this will produce an error*/

END IF;

END $$

DELIMITER ;

Comments

Popular posts from this blog

The transaction is in doubt

Sometimes you may get this error when you use transaction scope . The transaction is in doubt I also got this error recently and able to find the reason for it. That is because of the some of the readers had not properly disposed. Actually in this case you can use Using keyword to overcome this. Exception : System.Transactions.TransactionInDoubtException was unhandled by user code Message="The transaction is in doubt." Solution : using (reader) { }

Dead Code Problem

Problem Actually this problem occurred when i was doing integration two projects. [Phase1 and phase2 of a project] . Phase 2 is developed on top of the phase1. Parallel phase1 had changed lot . Mean time those were working on phase2 has commented existing phase 1 code without comments . Phase 1 and phase 2 merged with some conflicts. So we commented such places with the descriptive comment . After merged the result code base has merged those phase 2 commented parts. Also there was some of already dead code in phase 1. So it is difficult to understand weather this is actual dead code or commented one from phase 2. Mistake Had left dead dead code and missing comments . Lesson learned Normally developers leave dead code in their original code with the mind of future purpose. But this not a good habit to continue.As long as you use source control ,earlier code may exist. Problem will occur if you are not using such version control. In such a situation you can keep dead code with des