On Mar 1, 2007, at 9:31 PM, Ken Dibble wrote:

>>         Quick question: is the primary key for the table actually  
>> named
>> 'pkid'? Or did you just copy that from the example?
>
> pkid is the actual name of the primary key. The grid picks it up no  
> problem.

        OK, I see the problem. You start out by adding the correct fields to  
the definition:

biz = dabo.biz.dBizobj(conn)
biz.DataSource = "musSongs"
biz.KeyField = "pkid"
biz.addField("pkid")
biz.addField("songname")
biz.addField("compdate")

        But then you circumvent this by writing your SQL directly:

self.PrimaryBizobj.UserSQL = "select songname from musSongs where  
pkid = " + myPK

        You now only have the 'songname' field in your cursor, since you  
told it that's all you wanted. The cursor still thinks it has a PK  
field, since you set that originally, so when it tries to maintain  
its record pointer to the record with the same PK it was on before it  
requeried itself, it throws the error:

    File "C:\Program Files\Dabo Runtime\dabo\biz\dBizobj.py", line  
852, in _moveToPK
    File "C:\Program Files\Dabo Runtime\dabo\db\dCursorMixin.py",  
line 1379, in moveToPK
    File "C:\Program Files\Dabo Runtime\dabo\db\dCursorMixin.py",  
line 1362,in _getRecordByPk
KeyError: 'pkid'

        Note the call stack: the bizobj is calling moveToPK in its cursor,  
which is trying to do that in its _getRecordByPk() method. Of course,  
there is no PK in its records, since you explicitly did not include it.

        The problem, of course, is the use of UserSQL; it exists to allow  
you to completely control your query environment. If you set it, all  
of the automatic SQL building stuff is bypassed, since you've taken  
responsibility for yourself.

        A better choice, IMO, would be to not mess with UserSQL at all, and  
instead continue to work with the SQL Builder code. In this  
particular case, you want to find a record based on PK. I would  
approach it like this: set the where clause to take a parameter, and  
then pass the desired value when you need it. Example:

biz.setWhere("pkid = %s")

#User enters '123' as the PK and clicks
biz.setParams(self.keyBox.Value)
self.requery()

#User enters '876' as the PK and clicks
biz.setParams(self.keyBox.Value)
self.requery()

        I hope this helps.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to