[Zope-DB] max(<fieldname>)

Hout, Eric van den ericvdhout@levob.nl
Wed, 31 Oct 2001 10:26:42 +0100


Thnax, this worked. However I still am not able to use it as a auto-number
function. (remember I'm a newby :-) ). When someone enters a new db record
in a form, I want to automatically raise the Primary key by 1. Where can I
do this addition? 

Do I need to use a hidden formfield and calculate with Javascript or
something? I'm hoping there's a more intelligent way to do this.

Kind regards.

> -----Oorspronkelijk bericht-----
> Van: Matthew T. Kromer [mailto:matt@zope.com]
> Verzonden: maandag 29 oktober 2001 13:30
> Aan: Hout, Eric van den
> CC: 'zope-db@zope.org'
> Onderwerp: Re: [Zope-DB] max(<fieldname>)
> 
> 
> 
> On Monday, October 29, 2001, at 06:41 AM, Hout, Eric van den wrote:
> 
> > Hi,
> >
> > Can anyone tell me why this:
> >    select nw_id from nieuws
> > does work and this:
> >    select max(nw_id) from nieuws
> > does not?
> >
> > What I am trying to do on a Gadfly DB is to make a primary 
> key "auto"
> > incremental.
> >
> > Anyone knows some info on how to achieve this? The book and 
> the gadfly 
> > docs
> > trell how to create a unique index, but I can't find out how to use 
> > this to
> > "auto create" my Primary key.
> >
> > Help?
> >
> 
> Hi Eric,
> 
> I'm not sure that Gadfly supports any kind of automatic unique key 
> generation BUT, I can suggest why your MAX(nw_id) fails.  When you 
> select something from a Database Adapter, zope tries to name 
> it the same 
> way the result comes back -- in this case as MAX(nw_id) --  
> so instead, 
> if you
> 
> select MAX(nw_id) as nw_id from nieuws
> 
> it should work...
>