I'm a newbie to SQLAlchemy, so please excuse me if this is common knowledge.

Using the sqlite backend, I'm creating custom functions and then running
queries with them. I started by using the connection's create_function
method, and then running the query with the session.execute method.

        self.session = self.SessionClass()
        search_string = """SELECT * FROM records
                        WHERE memory_id=:id AND get_concordance(source)"""
        concordance_func = make_concordance_func(query)
        conn = self.session.bind.connect()
        conn.connection.create_function("get_concordance",
                                        1,
                                        concordance_func)

        rows = [dict(x) for x in self.session.execute(search_string,
dict(id=id))]
        
        return cPickle.dumps(rows)

This worked fine in unit testing, but when I tried it from a cherrypy
instance, it failed semi-randomly. The failure was 
(OperationalError) no such function: get_concordance
It would work for half the queries, and fail for the other half, not always
the same ones.

I assumed that this was due to some threading issue, and changed the execute
method to the connection object. This works:

        # ... same up to here
        rows = [dict(x) for x in conn.execute(search_string, dict(id=id))]
        
        return cPickle.dumps(rows)

What I'd like to find out is:
  (1) What is going on to cause this?
  (2) Is there something horribly wrong with my approach? 
Thanks in advance for any enlightenment.

Regards,
Ryan Ginstrom


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to