Not getting expected MySQL error

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

    Not getting expected MySQL error



    I am inserting values into a row.. works OK

    If I try to insert a value into a row that doesnt exist (using where)
    it always returns true the same as if it did work

    I want to update rows that have one unique field.. if the row doesnt
    exists it should return 0 rows updated.. I then create the row...

    But it always returns 1 even when I update a row that doesnt exist..
    How do I get an error or a false return?

    Any help appreciated :)


  • Jon Kraft

    #2
    Re: Not getting expected MySQL error

    KIPAX <mail@notareale mailaddy.com> wrote:
    [color=blue]
    > I am inserting values into a row.. works OK
    >
    > If I try to insert a value into a row that doesnt exist (using where)
    > it always returns true the same as if it did work[/color]

    You can't use WHERE in an INSERT statement. Doesn't make sense either.
    [color=blue]
    > I want to update rows that have one unique field.. if the row doesnt
    > exists it should return 0 rows updated.. I then create the row...
    >
    > But it always returns 1 even when I update a row that doesnt exist..
    > How do I get an error or a false return?[/color]

    Use mysql_affected_ rows() after the UPDATE statement - this returns 0 if
    no record was updated.

    HTH;
    JOn

    Comment

    • Pedro Graca

      #3
      Re: Not getting expected MySQL error

      KIPAX wrote:[color=blue]
      > I want to update rows that have one unique field.. if the row doesnt
      > exists it should return 0 rows updated.. I then create the row...[/color]

      you can try the (non-standard) REPLACE command


      It does a DELETE and a INSERT for rows that exist
      and a INSERT for rows that don't already exist.
      --
      --= my mail box only accepts =--
      --= Content-Type: text/plain =--
      --= Size below 10001 bytes =--

      Comment

      • KIPAX

        #4
        Re: Not getting expected MySQL error

        On 11 Dec 2003 11:24:30 GMT, Jon Kraft <jon@jonux.co.u k> wrote:

        [color=blue][color=green]
        >> I am inserting values into a row.. works OK
        >>
        >> If I try to insert a value into a row that doesnt exist (using where)
        >> it always returns true the same as if it did work[/color]
        >
        >You can't use WHERE in an INSERT statement. Doesn't make sense either.[/color]

        I am not.. I am trying to insert values into existing rows. But if
        row doesnt exist then i was expecting it to let me know.. I would then
        use a normal insert to create a new unique row.. the where was only
        used to insert into an existing row.
        [color=blue]
        >Use mysql_affected_ rows() after the UPDATE statement - this returns 0 if
        >no record was updated.[/color]


        Thats the ticket... Thanks :)


        Comment

        Working...