Hi !

  The Update, Insert and Delete statements don't return the row
inserted/updated, they only return the number of rows affected by the
statement. If you want to check the new value ot the row inserted, as far as
I know, you must execute another SELECT statement unless the row is an
AUTO_INCREMENT type, where you can check the new value with the
$sth->{insertid}.

     Cheers,

      Daniel
---------------------------------------------------------
Daniel Rios
Center for Genomics and Bioinformatics
Karolinska Institutet
Berzelius v�g 35
171 77 Stockholm, Sweden
phone: +46 (0)8- 728 60 85
fax +46 (0)8- 324826




 mailto:  [EMAIL PROTECTED]


----- Original Message -----
From: "jat" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 29, 2002 4:05 AM
Subject: Update return/locking


> Hi,
>
> I'm extremely new to Perl/DBI, so apologies for the dumb question. I am
> wondering whether DBI returns the affected records with an insert, update
oR
> delete query. It appears to, but I can't access the data. See the code
below
>
> $qry = &Prepare_Query($dbh, "update tblSetup set next_val_id = next_val_id
> +1");
> $qry->execute() || die "error";
> print "no rows = " . $qry->rows() ."\n";  #this correctly prints out the
no
> of rows affected
> while (@data =
> y->fetchrow_array){
> print "\nsome stuff = " . $data[0] }
> *note the Prepare_Query is just the standard prepare with the SQL....
>
> Basically the update works (in the DB) and the script prints out the
correct number of rows that are affected, but i cant 'fetch' any info on the
updated rows, as it says I should run an 'execute before fetch' - maybe
because the rows returned by executing the update are 'null'. Is there any
way to perform this trivial example where I increment a field of a row and
return its value using a single prepare statement? I was hoping to achieve
this by executing the update statement and receiving the affected records.
>
> Alternatively, is there a way to lock an entire table, so that I can do a
two-step process , i.e. select the number, store it, increment it and then
update it - but lock it so that any concurrency issues are avoided?
>
> Thanks for your help.
>
>
>
>

Reply via email to