mysql_errorno() and a more complete error description

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jes

    mysql_errorno() and a more complete error description

    Hi

    Is there any way to construct a more meaningful error description so
    that it can be displayed to the user

    Eg. Table Country - Fields Country Code and Country Name - Both
    fields are unique and code is the primary key.

    I would like to display something like 'Country code already exists'.

    Current display will be 'Duplicate entry 'AA' for key 1'

    Is it possible to change key 1 with the name of the field generating
    the error ?

    Thanks

  • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

    #2
    Re: mysql_errorno() and a more complete error description

    Jes wrote:
    Current display will be 'Duplicate entry 'AA' for key 1'
    >
    Is it possible to change key 1 with the name of the field generating
    the error ?
    Do proper error checking before running the SQL query.


    Cheers,
    --
    ----------------------------------
    Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

    This tagline is SHAREWARE! To register, send me $10

    Comment

    • Jerry Stuckle

      #3
      Re: mysql_errorno() and a more complete error description

      Jes wrote:
      Hi
      >
      Is there any way to construct a more meaningful error description so
      that it can be displayed to the user
      >
      Eg. Table Country - Fields Country Code and Country Name - Both
      fields are unique and code is the primary key.
      >
      I would like to display something like 'Country code already exists'.
      >
      Current display will be 'Duplicate entry 'AA' for key 1'
      >
      Is it possible to change key 1 with the name of the field generating
      the error ?
      >
      Thanks
      >
      >
      No, MySQL won't do that for you. If you want something like this, you
      can either check for duplicates before the insert like Iván suggested,
      or parse the error message yourself.

      Checking for duplicates before doing an INSERT is OK, but ensure you
      LOCK TABLE so someone else doesn't get in between your SELECT and your
      INSERT (uncommon, but it does happen!).

      Alternatively, after you get the duplicate key back, do a SELECT for a
      match of Country Code OR Country Name and check the row(s) which come
      back to see which is a duplicate.

      Alternatively, keep track of which index refers to which column and test
      in your code. I like this least of all :-)

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Jes

        #4
        Re: mysql_errorno() and a more complete error description

        On Oct 7, 10:22 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        Jes wrote:
        Hi
        >
        Is there any way to construct a more meaningful error description so
        that it can be displayed to the user
        >
        Eg. Table Country -  Fields Country Code and Country Name - Both
        fields are unique and code is the primary key.
        >
        I would like to display something like 'Country code already exists'.
        >
        Current display will be 'Duplicate entry 'AA' for key 1'
        >
        Is it possible to change key 1 with the name of the field generating
        the error ?
        >
        Thanks
        >
        No, MySQL won't do that for you.  If you want something like this, you
        can either check for duplicates before the insert like Iván suggested,
        or parse the error message yourself.
        >
        Checking for duplicates before doing an INSERT is OK, but ensure you
        LOCK TABLE so someone else doesn't get in between your SELECT and your
        INSERT (uncommon, but it does happen!).
        >
        Alternatively, after you get the duplicate key back, do a SELECT for a
        match of Country Code OR Country Name and check the row(s) which come
        back to see which is a duplicate.
        >
        Alternatively, keep track of which index refers to which column and test
        in your code.  I like this least of all :-)
        >
        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstuck...@attgl obal.net
        =============== ===- Hide quoted text -
        >
        - Show quoted text -
        Thanks to all

        Comment

        Working...