2006/1/24, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> Greetings,
>
> This is a two part question. I'm trying to see how I can rewrite an
> existing ColdFusion app with TurboGears. I need to query a MySQL
> database table with a FULL TEXT INDEX. I can't see how to do this from
> the SQLObject documentation. Example SQL query:
>
> select
>     columna
>    ,columnb
> from
>    mytable
> where
>     match(columna) against ("some string")

You can build any sql expression that is not present by default with sqlbuilder:

from sqlobject.sqlbuilder import SQLExpression, sqlrepr

class FullTextSearch(SQLExpression):
    def __init__(self, column, string):
        self.column = column
        self.string = string

    def __sqlrepr__(self, db):
        return "MATCH (%s) AGAINST (%s)" % (sqlrepr(self.column, db),
sqlrepr(self.string, db))


Than you can use it as any other expression:

query = FullTextSearch(MyTable.q.columna, 'some string')
results = MyTable.select(query)

>
> Second, if this type of thing is not possible with SQLObject, is there
> a recommended method to run this SQL or should I just do it the
> "normal" way of connecting to MySQL with MySQLdb and executing the SQL
> that way?

I am trying to use SQLObject as much as possible. For complex  queries
you can also use SQLConstant:

from sqlobject.sqlbuilder import SQLConstant, sqlrepr

MyTable.select(SQLConstant('''match(columna) against ("%s")''' %
sqlrepr('some string')))



--
Ksenia

Reply via email to