[Zope] zope + sql

Duncan Booth duncan@rcp.co.uk
Tue, 17 Apr 2001 15:10:14 +0100


> Once this is done the values would be passed back to sql and UPDATE
> used to replace the old values.  I'm not quite sure how to do this
> either.  Do you have a loop, where inside the loop the UPDATE is goes
> through each marked record, or do you loop inside the 
> 
> UPDATE tablename set 
>     variable=newvalue
>    where ----loop here with or's------
> 
> Any suggestions or similar examples would be appreciated.
> 
I did something similar a while back. I display the results of the query, and 
each record has an 'approved' field that may be set to 0 or 1.

The SQL method to do this looks like:

Parameters: fldId fldApproved:int=1
Body:
	UPDATE O_Fixtures
	SET fldApproved = <dtml-sqlvar fldApproved type=int>
	<dtml-sqlgroup where required>
	<dtml-sqltest fldId multiple type=int>
	</dtml-sqlgroup>

The form displays each record, and includes one column in the output that 
looks like:
  <dtml-unless fldApproved>
    <td><INPUT type=checkbox name="fldId:List"
      value="&dtml-fldId;"></td>
  </dtml-unless>

The primary key for each database entry is the value fldId. When the form is 
submitted it includes a variable fldId which is a list of the ids of all records to be 
updated. The SQL method will expand to apply the update to a single record or 
all the selected records as appropriate.

for example, if record 2 is selected the SQL looks like this:
     UPDATE O_Fixtures SET fldApproved = 1 where fldId = 2
but if records 2, 3, and 4 are selected the SQL looks like:
     UPDATE O_Fixtures SET fldApproved = 1 where fldId in (2, 3, 4)

-- 
Duncan Booth                                             duncan@dales.rmplc.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
http://dales.rmplc.co.uk/Duncan