From: Matthew M. <ma...@tu...> - 2002-11-07 12:49:02
|
This bug was posted to sourceforge. ------------------------------------------------------- When using sqlInsert to insert a row into the database if the insert fails then the sequence table still gets incremented. ------------------------------------------------------- I didn't know the best way to fix it so I sent a question to the php news board. ------------------------------------------------------- Hello, I am using nextId in an insert function. I run $id = $db->nextId; $db->query("insert into foo (id_column_name, something) values ($id, $somethingValue)"); Works great. But if there is an error, say there isn't a 'something' column, my sequence table still gets incremented. I don't recall if MySQL auto_increment had the same behavior. My questions are: Should I even worry about it? If I should, is there a $db->prevId() or do I have to decrement it myself on the query error? Thanks, Matt ------------------------------------------------------------------ I was wondering if anyone else had any ideas. If we create our own prevId function, we might have to change the way some of the functions access query. When any of the sql functions call query, it will, by default, exit if there is an error. Now at one point I thought this could be a problem, so there is a tag that lets the function continue and just return a FALSE instead. To utilize a prevId function, the query would always need to told not to exit on an error. It would instead return FALSE to sqlInsert which would then, in turn, decrement the sequence. Why I am going over all this if it is just a one parameter change? Well, maybe the query function should NEVER exit. Instead, maybe the sql functions should handle the errors personally. We could, if we wanted, have the sql function report simple error messages to standard users (Contact your administrator) and detailed messages to admins (Here is the sql error and here is all the data I received and here is what module was running). Please talk amongst yourselves. I will let you know if I hear anything from the news list. Matt Matthew McNaney Internet Systems Architect Electronic Student Services Email: ma...@tu... URL: http://phpwebsite.appstate.edu Phone: 828-262-6493 ICQ: 141057403 |
From: Adam M. <ad...@tu...> - 2002-11-07 14:58:08
|
You should be able to just decrement the sequence table on an error. Adam > This bug was posted to sourceforge. > ------------------------------------------------------- > When using sqlInsert to insert a row into the database > if the insert fails then the sequence table still gets > incremented. > ------------------------------------------------------- > > I didn't know the best way to fix it so I sent a question to the php > news board. > > ------------------------------------------------------- > Hello, > > I am using nextId in an insert function. > > I run > $id = $db->nextId; > $db->query("insert into foo (id_column_name, something) values ($id, > $somethingValue)"); > > Works great. But if there is an error, say there isn't a 'something' > column, my sequence table still gets incremented. > > I don't recall if MySQL auto_increment had the same behavior. > > My questions are: > Should I even worry about it? > If I should, is there a $db->prevId() or do I have to decrement it > myself on the query error? > > Thanks, > Matt > ------------------------------------------------------------------ > > I was wondering if anyone else had any ideas. > > If we create our own prevId function, we might have to change the > way some of the functions access query. > > When any of the sql functions call query, it will, by default, exit if > there is an error. > > Now at one point I thought this could be a problem, so there is a tag > that lets the function continue and just return a FALSE instead. > > To utilize a prevId function, the query would always need to told not to > exit on an error. It would instead return FALSE to sqlInsert which would > then, in turn, decrement the sequence. > > Why I am going over all this if it is just a one parameter change? > > Well, maybe the query function should NEVER exit. Instead, maybe the sql > functions should handle the errors personally. We could, if we wanted, > have the sql function report simple error messages to standard users > (Contact your administrator) and detailed messages to admins (Here is > the sql error and here is all the data I received and here is what > module was running). > > Please talk amongst yourselves. I will let you know if I hear anything > from the news list. > > Matt > > Matthew McNaney > Internet Systems Architect > Electronic Student Services > Email: ma...@tu... > URL: http://phpwebsite.appstate.edu > Phone: 828-262-6493 > ICQ: 141057403 > > > > > ------------------------------------------------------- > This sf.net email is sponsored by: See the NEW Palm > Tungsten T handheld. Power & Color in a compact size! > http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en > _______________________________________________ > Phpwebsite-developers mailing list > Php...@li... > https://lists.sourceforge.net/lists/listinfo/phpwebsite-developers --------------------------------- Adam Morton Developer - Electronic Student Services http://phpwebsite.appstate.edu Founder - ASU Linux Users Group http://alug.appstate.edu |
From: Matthew M. <ma...@tu...> - 2002-11-07 15:54:34
|
> You should be able to just decrement the sequence table on an error. Like so? $id = $this->db->nextID(); if (!$core->sqlInsert($valueArray, $tableName)) $this->prevId($tableName); As I said, that won't current work as the sqlInsert will exit when it hits the $core->query() function. FALSE is never returned so the decrement never happens. I can change sqlInsert so that it tells query to acknowledge the error with a FALSE return and NOT exit however. That is the quick fix. The question is should we do this or wait for the Pear team to acknowledge it? Matthew McNaney Internet Systems Architect Electronic Student Services Email: ma...@tu... URL: http://phpwebsite.appstate.edu Phone: 828-262-6493 ICQ: 141057403 |