On Thu, May 21, 2009 at 4:27 PM, JohnMc <maruadventu...@gmail.com> wrote:

>
> I have a query constructed as follows --
>
> qy = dbhlx((dbhlx.contact.lastname[0].upper() >= request.args[0]) &
> (dbhlx.contact.lastname[0].upper() <= request.args[1]))
>
> I get a "object is not unindexable" error. So I presume that means
> that the lastname in the query cannot be sliced?


maybe this will help:

a Query is a way, from python, to generate SQL.    SQL doesn't do slices.
You have to get the data into Python context, then slice.

So -

result = db( where_clause).select(select_clause)

will translate / generate an SQL query, and should be built up so that it
makes sense to the DB:

SELECT lastname, firstname, address, id  from contact
WHERE lastname ....

Of course, a value from the Python side can be generated;  so you can slice
it (since it is Python side data at this point);  but contact.lastname is
not - it is the data your are trying to fetch, but do not have yet...

Given this, something like this is more appropriate for your example:

...(dbhlx.contact.lastname >= request.args[0].upper()) &

> (dbhlx.contact.lastname <= request.args[1].upper())


AND it's also probably not what you want...

So lay out what you want, and design the "best" way to get there ;-)



> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to