Re: Using .capitalize() in Insert Statement
Gerhard Häring <[email protected]>
| Newsgroups | gmane.comp.python.db.pysqlite.user |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Rich Shepard wrote:
> I ran up against a difference in the case of initial letters that
> prevented equality tests to fail. Since I discovered the existence of the
> .capitalize() string function (makes the first letter uppercase and the rest
> lowercase), is there any reason why I cannot use it in an insert statement?
No, of course you can:
cur.execute("insert into foo(bar) values (?)", ("xyz".capitalize(),))
I don't think there's a SQL function capitalize, but you can of course
create one:
>>> from pysqlite2 import dbapi2 as sqlite
>>> import string
>>> con = sqlite.connect(":memory:")
>>> con.create_function("capitalize", 1, string.capitalize)
>>> con.execute("select capitalize('foo')").fetchone()
(u'Foo',)
>>>
- -- Gerhard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFF0FhAdIO4ozGCH14RAnVbAKCjG4JB4jWY6EQwaFdBodgp2YJ4LwCfb/0E
UmnEYoS5L+gDr3WXcTdiM5g=
=IFnb
-----END PGP SIGNATURE-----