sqlobject-discuss

I remember reading that SO does not support multi column keys, but does
that mean explicitly at the database level?
I am working with some legacy tables that do not have any explicit
primary keys defined for a table but they do have implicit keys, in the
sense that they are good about unique values, though in some cases those
keys are multivalued.
My problem is, for a class like this:
class Acct(SQLObject):
trsAcctNo = StringCol(length=7, dbName='TRS_ACCT_NO')
trsSeqNo = StringCol(length=6, dbName='TRS_SEQ_NO')
trsSeqSub = StringCol(length=2, dbName='TRS_SEQ_SUB')
trsAmt = FloatCol(dbName='TRS_AMT')
The true primary key is the concatenation of the first the fields.
I am really just interested in queries, so creating tables via SO
doesn't matter to me and even updates aren't so important in this case.
Could I do something like override the getter for the id column and
return the concatenation of the first 3 fields? Maybe like:
def _get_id(self):
return self.trsAcctNo+self.trsSeqNo+self.trsSeqSub
And if I did this, what would I specify for the idName in the sqlmeta class?
As it stands now, because the column I specify as the id column is not a
unique column by itself, I get the same row over and over when I run a
Acct.select().
An alternative approach would be to create a view of the table at the
database level with all of the same fields, but add a single column
which would be the 3 columns colmbined as a single field primary key.
Regards,
Aaron

On Tue, Oct 31, 2006 at 11:57:26AM -0600, Aaron Bostick wrote:
> Could I do something like override the getter for the id column and
> return the concatenation of the first 3 fields?
I am afraid the idea of single-value id is built so deep in SQLObject
it would be hard to combat it with any simple measure.
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ phd@...
Programmers don't die, they just GOSUB without RETURN.

Could you override the get() method?
So normally myTable.get() expects an integer and gets the object.
If you can override that then you can pass it your really key...
But I think maybe this gets too complicated.
Perhaps you should just make a new method which knows how to do the query
you are looking for.
You probably also want to create a unique index on the fields that make up
the key.
--
Rick
On Tue, 31 Oct 2006, Oleg Broytmann wrote:
> On Tue, Oct 31, 2006 at 11:57:26AM -0600, Aaron Bostick wrote:
>> Could I do something like override the getter for the id column and
>> return the concatenation of the first 3 fields?
>
> I am afraid the idea of single-value id is built so deep in SQLObject
> it would be hard to combat it with any simple measure.
>
> Oleg.
>

Oleg,
I figured as much, but its ok because I was able to create a simple
SELECT * view with one additional derived field that acts as the SO ID
field and it seems to work ok!
On a side note, I was able to get the sybaseconnection.py code to work
with Sybase ASA by changing some of the SQL in that file. The system
tables change a lot it seems when moving from ASA to ASE.
It is working for me ok so far though I know some things are still
broke, specifically the fromDatabase introspection piece. I declare
everything so I didn't do that part.
Would you like me to post my file here?
Oleg Broytmann wrote:
> On Tue, Oct 31, 2006 at 11:57:26AM -0600, Aaron Bostick wrote:
>> Could I do something like override the getter for the id column and
>> return the concatenation of the first 3 fields?
>
> I am afraid the idea of single-value id is built so deep in SQLObject
> it would be hard to combat it with any simple measure.
>
> Oleg.
Regards,
Aaron