real world demo - Firebird

Werner F. Bruhin wrote:

Hi Kenneth,

Attached some updated files which work as far as I can see.

The corrections/changes needed to make it work:
In addperson.py:
- line 119 and 129, wxMessageDialog needs to be wx.MessageDialog
- line 119 and 129 wxOK needs to be wx.OK
- line 95 (in add) change parms = self.parms to parms = {}
This is really just a work around, as kinterbasdb does seems to support setitem, however as all values are set in parms it does not really make a difference as far as I could see.

In manageperson.py:
- line 75 (in close) change from self.Close(1) to self.Destroy(), as self is a wxDialog it needs to be destroyed otherwise program will not close correctly (e.g. in Boa the task will still show on its Tasks tab).

In utilities.py:
Both updateperson and enterperson show three coding styles, I am not sure if this is worth the potential confusion.

All is attached, inclusive the db as a zip file.

See you
Werner

<snip...>

Werner,

why do you want to show People bad Programming style?
Please stick with the best Solution - use the Drivers capability to
quote the Params for you!
e.g.:
   parmtuple = (fname, lname, profession, salutation)
   stmt = 'insert into persons (fname,lname,profession,salutation) values (?, ?, ?, ?)'
   c.execute(stmt, parmtuple)

I really do not understand why People at all try to do it the hard way.

Uwe

Werner F. Bruhin wrote:

Uwe wrote:

Please stick with the best Solution - use the Drivers capability to
quote the Params for you!
e.g.:
  parmtuple = (fname, lname, profession, salutation)

Show me how! fname etc. are not variables in "updateperson" and "enterperson" they are keys in the dict parms.

You could make them into local variables, if you wish:

    dct = {'fname':'Franz', 'lname':'Schubert','profession':'composer','salutation':'Maestro'}
    locals().update(dct)
    parmtuple = (fname, lname, profession, salutation)

or do the same thing explicitly:

    fname = dct['fname']
    lname = dct['lname']
    ....
    parmtuple = (fname, lname, profession, salutation)

or you could extract from the dict directly into a tuple:

    parmtuple = tuple([dct[k] for k in ('fname', 'lname', 'profession', 'salutation')])

(in Python 2.4 the square brackets are unnecessary)

or do the same thing, more explicitly:

    parmtuple =
    for key in ('fname', 'lname', 'profession', 'salutation'):
        parmtuple.append(dct[key])
    parmtuple = tuple(parmtuple)

and of course you could wrap that up in a function, and reuse it more easily:

    def ptuple(dct, *keys):
        pt = tuple([dct[k] for k in keys])
        return pt

    parmtuple = ptuple(dct, 'fname', 'lname', 'profession', 'salutation')

which might be your best bet, since it's short and readable.

-- Graham