If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to supress errors?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-06, 17:43
Morthane Morthane is offline
Registered User
 
Join Date: Jan 2006
Posts: 20
How to supress errors?

Is there a way to tell MySQL to temporarily supress/ignore reporting specific error conditions?

---------------------------------------------

I am connecting to a MySQL 5.0 database via C#. Due to the nature of the program, the C# code will end up sending requests to insert duplicate data in the database, which raises MySQL error #1062, which in turn causes an OdbcException in C#.

To combat this, I use stored procedures that trap the error via a custom handler:
Code:
DECLARE EXIT HANDLER FOR 1062
BEGIN
	SELECT 'Attempted to insert duplicate data information';
END;
This tells C# that "-1 rows were affected" instead of causing an error. However, doing things in this way will only allow me to do one INSERT reliably per procedure (if the first INSERT fails, the procedure jumps to the handler, avoids the second INSERT, etc). So any solutions?
Reply With Quote
  #2 (permalink)  
Old 02-14-06, 17:28
Morthane Morthane is offline
Registered User
 
Join Date: Jan 2006
Posts: 20
Found it myself

ANSWER:

Code:
IF NOT EXISTS (select [col] from [table] where [col] = [value]) THEN
insert into [table] ([col]) values ([value]);
END IF;
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On