mysql+seaside squeak beginners question

Bob Arning arning at charm.net
Thu Jul 18 14:13:08 UTC 2002


On Thu, 18 Jul 2002 15:44:02 +0200 Ragnar Hojland Espinosa <ragnar at linalco.com> wrote:
>I'm using the mysql driver with seaside (nice tool indeed).  Basically I
>want to print the fname column from the people table.  Being new to
>smalltalk it took me a bit to figure out how to do this, but my solution
>looks extremelly wasteful.

What, in particular, strikes you as wasteful?

>Is there a way to optimize the companies method?  Even if i throw it as a
>new method of ExDB (JdmStatement with overloaded new which executes a
>JdmConnection and createStatement) it looks awful.
>
>
>Heres what I have
>
>* in ExListCompanyLine:
>
>addHandlers
>  (template elementNamed: 'name')
>     keyPath: 'company.fname'
>
>html
>^ '[name]'
>
>
>* and in ExListCompanies:
>
>companies
>| r c a |
>r _ (ExDB new) executeQuery: 'select fname,lname from people'.
>c _ r columns collect: [:col | col name].
>a _ OrderedCollection new.
>[r next] whileTrue:
>[ | d |
>        d _ Dictionary new.
>        c collect: [ :col |
>                "value _ r valuedName: col."
>                d at: col put: (r valueNamed: col).
>        ].
>        a addLast: d.
>].
>^ a

Here are a few thoughts:
==========
        c collect: [ :col |
                "value _ r valuedName: col."
                d at: col put: (r valueNamed: col).
        ].

in addition to doing what you want it to do is also building a new collection (that's what #collect: does). Since you make no use of the value returned from #collect:, #do: would be a bit more efficient.
==========
One thought that has occurred to me in the past when doing this kind of thing is that repeating the Dictionary of name->value mappings for each row is a bit wasteful. It might be nice instead to have some sort of TwoDimensionalResult object that would store the name of a column only once (mapping it to an integer) and then storing each row as an array indexed by that integer. For all I know, the <r> in your code may be capable of doing this or could be extended to do so. This object could respond to messages like

	result atColumn: 'lastName' andRow: 23

	result forColumn: 'lastName' do: [ :lastName | ... ]

	result collectColumn: 'firstName'

	result firstThreeColumnsDo: [ :firstname :middleName :lastName | ... ]

This last one seems particularly handy to me, although tough to generalize for larger numbers of columns.

==========

Cheers,
Bob



More information about the Squeak-dev mailing list