record id: is there a way to get a record's ID?

42 views
Skip to first unread message

berry

unread,
May 21, 2012, 9:32:29 AM5/21/12
to buzhug
is there an ID to a record anyway?
is there a way to get a record object's ID ?
if not - i have to maintain my own IDs. Is there a auto-increment-
unique-ID mechanism?

Pierre Quentel

unread,
May 22, 2012, 3:17:11 AM5/22/12
to buz...@googlegroups.com
Hi,

Yes, records have a record id set by the engine, accessible by their attribute __id__. It is an auto-incremented integer. I realize that it's not very clear in the documentation, I'm going to update it

- Pierre

berry

unread,
May 23, 2012, 3:36:27 AM5/23/12
to buzhug
thanks a lot!

(btw: this name is a bit inconsistent with "normal" field names, i
think.
it is consistent with python's internal ID, yes, but database IDs
should have a "public interface", so i'd vote for something like
"rec.record_id", "rec.id", or even "rec.buzhug_record_id"...

anyway __id__ is good enough once it's documented :)

Pierre Quentel

unread,
May 23, 2012, 4:03:43 PM5/23/12
to buz...@googlegroups.com

Le mercredi 23 mai 2012 09:36:27 UTC+2, berry a écrit :
thanks a lot!

(btw: this name is a bit inconsistent with "normal" field names, i
think.
it is consistent with python's internal ID, yes, but database IDs
should have a "public interface", so i'd vote for something like
"rec.record_id", "rec.id", or even "rec.buzhug_record_id"...

anyway __id__ is good enough once it's documented :)


I updated the documentation page on sourceforge (quick reference page)

I chose __id__ and __version__ to make the distinction between fields managed by the engine and fields defined by the programmer, in the same way as Python defines many methods of built-in types with double leading and trailing underscores

Best wishes
Pierre

berry

unread,
May 23, 2012, 8:54:36 PM5/23/12
to buzhug
so..

what's the efficient way to select by a field that's in another table?
( i prefer not to itereate on ALL records )

e.g.

parent_db= Base('t1').create( ('name', str) )
child_db= Base('t2').create( ('name', str), ('parent', parent_db ) )
parent_db.insert( name='jean')
parent_db.insert( name='jacques')
parent_db.insert( name='paul')
parent_db.insert( name='philip')
parent_db.insert( name='anne')
parent_db.insert( name='marie')
child_db.insert(name='itsik1', parent_db[3] )
children = child_db.select( ['name'] , parent=parent_db[3] )
...
ValueError: If argument is a list, only 2 values
should be passed (found 3)

?
Reply all
Reply to author
Forward
0 new messages