[Opensource] Accessing auto-inc key fields after add()
Michael Rimov
rimovm at centercomp.com
Thu Nov 7 14:13:27 PST 2002
At 12:58 PM 11/7/2002 -0600, you wrote:
>Someone correct me if I'm wrong, but I don't think you'll want to use
>auto-inc if you need to access the number without doing a query afterwards.
>Use the NextNumber object instead:
>
>(out of the Expresso How-to guide)
>import com.jcorporate.expresso.core.dbobj.NextNumber;
>NextNumber myNext = NextNumber.getInstance();
>int uniqNum = (int)myNext.getNext(request.getDBName(), yourDBObj, "id");
>yourDBObj.setField("id", uniqNum);
>yourDBObj.add();
addField() of type "auto-inc" directly uses NextNumber and its use is done
automatically. So if you have field type autoinc... the field IS
automatically calculated in add(), and after the add(), you can use a
normal getField() to retrieve the value assigned to the autoinc file.
So actually, you never have to use NextNumber directly at all.
HTH!
-Mike
More information about the Opensource
mailing list