Hi Chris,

My response to what you <CO> wrote me on Wednesday, February 5, 2003 at 2:39 PM:

Why not always append and get the next key with:
nextkey = v[-1].key + 1

or have you already rejected this?

-- 
 /\_/\    Jerry McRae       \|||/       mail safely: The Bat! 1.60q
(~o o~)                     (. .)
 )'Y'(   _______________-o00-(_)-00o-___________________________
(     ) / If I had a nickel for every time Windows crashes... Oh yea, I do!
          --Bill Gates

========== your original message below ==========
From: Chris Olds
To:   [EMAIL PROTECTED]
on:   2:39:11 PM
re:   [Metakit] Q: rowids?

wise words:

CO> I'm working on a calendering/PIM application, and I have several independent
CO> datasets I need to work with (all in the same MK storage).  Can anyone give me
CO> a recipe for generating surrogate key values?  Since I'm only allowing one
CO> opener for the storage, I suppose I could get the last key value used by
CO> sorting the view and giving new rows a key value greater than the last value
CO> used, but that doesn't feel like the best solution - I've spent years avoiding
CO> just this kind of thing in SQL...

CO> To make this concrete, here's how it would look in Python:

CO>   import metakit as mk
CO>   db = mk.storage()
CO>   v = db.getas("contact[key:I,name:S,address:S,city:S,state:S,zip:I]")
CO>   nextkey = 1
CO>   if v:
CO>     nextkey = v.sort(v.key)[-1]+1

CO> and then any inserts into the view would use the current value of nextkey and
CO> increment it (all of this is actually in a class that keeps all of the ugly
CO> stuff hidden, so the keeping track part isn't as bad as it looks here).

CO> I don't want to use the row numbers returned when I add a row, because then
CO> I'd be up a creek if I ever deleted a row (which I don't expect to do a lot
CO> of, but I don't want to preclude).

CO> So - is there a better way?

CO>     /cco

CO> --
CO> GPG Key Fingerprint: B375 A4E7 752B DB8C 4359  852E C3CF BF64 379A E9B2
CO> Debian Project (http://www.debian.org)
CO> _______________________________________________
CO> metakit mailing list  -  [EMAIL PROTECTED]
CO> http://www.equi4.com/mailman/listinfo/metakit

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

Reply via email to