Thank you very much!

Actually, i needed it to replace sqlite lower function, because it
only understands upper/lower case for 7-bit Latin characters.

One more question: where should this code be executed? I tried in
place where db object is created - and it didn't work. But it worked
in controller method just before i use sql select statement.


On Dec 1, 11:17 pm, Tzury Bar Yochay <[EMAIL PROTECTED]> wrote:
> On Dec 1, 3:28 pm, andrei <[EMAIL PROTECTED]> wrote:
>
> > I need an ability to add my own sqlite functions in python. I've found
> > this snippet for python sqlite.http://snippets.dzone.com/posts/show/538
>
> > How can be this code  applied to webpy db connection class?
>
> There you go
>
> # Your Code
>
> import sqlite3 as db
>
> conn = db.connect(":memory")
> conn.create_function("sign", 1, lambda val: val and (val > 0 and 1 or
> -1))
> cur = conn.cursor()
> cur.execute("select 1, -1")
> print cur.fetchall()
> cur.execute("select sign(1), sign(-1), sign(0), sign(-99), sign(99)")
> print cur.fetchall()
> conn.close()
>
> # webpy
>
> import web
> db = web.database(dbn="sqlite", db=":memory:")
> db._db_cursor().connection.create_function("sign", 1, lambda val: val
> and (val > 0 and 1 or -1))
> print db._db_cursor().execute("select sign(1), sign(-1), sign(0), sign
> (-99), sign(99)").fetchall()
> print db.query("select sign(1), sign(-1), sign(0), sign(-99), sign
> (99)").list()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" 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/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to