Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    20

    Unanswered: 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?

  2. #2
    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;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •