On 5 Feb 2003 at 14:39, Chris Olds wrote:

> I'm working on a calendering/PIM application, and I
> have several independent datasets I need to work
> with (all in the same MK storage).  Can anyone give
> me a recipe for generating surrogate key values? 

I have a couple techniques, depending on usage.
One involves a view "maxids[viewname:S,id:I]",
whose use should be pretty obvious. The downsides 
are (1) remembering to wrap all append / inserts,
(2) remembering to initialize new storages, and (3)
you may eventually have problems with very volatile data.

In apps where I can afford some over head on open,
I'll often use a "...,_isdel:I]" flag. I delete anything
where _isdel is 1 when I open the storage. During
the run, it's safe to use row numbers.

The first technique is good for CGI, the 2nd
for GUIs.

> Since I'm only allowing one opener for the storage,
> I suppose I could get the last key value used by
> sorting the view and giving new rows a key value
> greater than the last value used, but that doesn't
> feel like the best solution - I've spent years
> avoiding just this kind of thing in SQL... 

Why sort it? Scan on open for the maxid, and
maintain that in memory. It's lower overhead, and
doesn't interfere with whatever ordering the app
might want to see or maintain.
 
-- Gordon
http://www.mcmillan-inc.com/

_______________________________________________
metakit mailing list  -  [EMAIL PROTECTED]
http://www.equi4.com/mailman/listinfo/metakit

Reply via email to