sql update & $loop

basement_addict
Posts: 78
Joined: Mon Nov 19, 2001 5:20 pm

sql update & $loop

Post by basement_addict »

hi,
when i do an update statement and there is an error like "Update would generate non-unique row" even though the insert failed $loop still gets set to 1. i would expect $loop == affected rows. inserts seem to work fine ($loop=0)

here is a simple example which creates the table,index and sample data.



<A NAME=updateloop PUBLIC>
<sql "create table danstest(id counter,val varchar(5));"></sql>
<sql "create unique index idx_dantest on danstest(id,val)"></sql>
<$id=(counter)>
<sql "insert into danstest values($id,'dan');"></sql>
$loop<br>
<$id2=(counter)>
<sql "insert into danstest values($id2,'don');"></sql>
$loop<br>
<sql "insert into danstest values($id2,'mike');"></sql>
$loop<br>
<$loop=0> <!--clear loop here and insert duplicate on purpose-->
<sql "update danstest set val='don' where val='mike';"></sql>
$loop<br> <!-- this $loop is 1 -->
</A>




this is the output:

<!-- Texis RDBMS Copyright (c) 1992 - 2000 Thunderstone - EPI, Inc. -->
<!-- Texis Web Script Copyright (c) 1996 - 2000 Thunderstone - EPI, Inc. -->

1<br>
1<br>
1<br>
<!-- 178 /vtx/test:16: Update would generate non-unique row -->
1<br>
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

sql update & $loop

Post by mark »

Update returns every row matching the condition, updated or not. You could check the returned value against what you're trying to change it to or capture putmsg and look for that message.