[Zope-DB] Database Data
Dieter Maurer
dieter@handshake.de
Thu, 22 May 2003 20:26:37 +0200
Lindstrom Greg - glinds wrote at 2003-5-21 12:31 -0500:
> I am using Zope 2.6, mySQL 3.23 with the eGenix myODBC DB adaptor (which I
> love!) on Windows 98 and have the following questions.
>
> 1. How can I retrieve data from a database query when I know there is only
> 1 row to be returned (for example, I have a "users" table)? Currently, I am
> using a <dtml-in...> loop and I feel a little silly.
The result behaves like a sequence.
You use subscription syntax to access the elements of a sequence,
like "seq[0]", "seq[1]", ....
Your concrete case might look like:
<dtml-let
queryResult=query
firstHit="queryResult[0]"
>
....
</dtml-let>
or
<dtml-let firstHit="query()[0]">
....
</dtml-let>
> 2. Can I use the <dtml-sqlgroup> with joins? For example
>
> SELECT n.name, a.city FROM Names n, Addresses a <dtml-sqlgroup
> where>
> <dtml-sqltest myKey col=n.myKey op=eq type=string>
> <dtml-and>
> n.myKey = a.myKey
> </dtml-sqlgroup>
Yes.
> I can't figure out how to do the n.myKey = a.myKey, and I will be
> doing a lot of joins.
It will work as you wrote it above.
Dieter