Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #51399 > unrolled thread

RE: sqlite3 version lacks instr

Started byPeter Otten <__peter__@web.de>
First post2013-07-28 21:14 +0200
Last post2013-07-28 21:14 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  RE: sqlite3 version lacks instr Peter Otten <__peter__@web.de> - 2013-07-28 21:14 +0200

#51399 — RE: sqlite3 version lacks instr

FromPeter Otten <__peter__@web.de>
Date2013-07-28 21:14 +0200
SubjectRE: sqlite3 version lacks instr
Message-ID<mailman.5202.1375038868.3114.python-list@python.org>
Joseph L. Casale wrote:

>> Has anyone encountered this and utilized other existing functions
>> within the shipped 3.6.21 sqlite version to accomplish this?
> 
> Sorry guys, forgot about create_function...

Too late, I already did the demo ;)

>>> import sqlite3
>>> db = sqlite3.connect(":memory:")
>>> cs = db.cursor()
>>> cs.execute('select instr("the quick brown fox", "brown")').fetchone()[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
sqlite3.OperationalError: no such function: instr
>>> def instr(a, b):
...     return a.find(b) + 1 # add NULL-handling etc.
... 
>>> db.create_function("instr", 2, instr)
>>> cs.execute('select instr("the quick brown fox", "brown")').fetchone()[0]
11
>>> cs.execute('select instr("the quick brown fox", "red")').fetchone()[0]
0

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web