Below is code that gets user input ('q') from a web page and then
finds all strings in a database with the substring 'q':
import web
import sqlite3
render = web.template.render('/templates', cache=False)
urls = (
'/', 'index',
'/act', 'acGET',
)
class index():
def GET(self):
web.header("Content-Type", "text/html; charset=iso-8859-1")
print render.act()
class acGET():
def GET(self):
entry = web.input()
web.debug()
q = entry.q
q = str('%' + q + '%')
limit = int(entry.limit)
"""
the sqlite SELECT statement is
"SELECT field.B FROM table.A WHERE field.B LIKE '%s' LIMIT
'%s'" %
(q, limit)
ie. looking for the substring '%q%' in string field.B
"""
for row in web.select('table.A',
what='field.B',
where='field.B LIKE $q',
limit=limit,
vars={'q':q}):
print row
web.webapi.internalerror = web.debugerror
if __name__== "__main__":
web.config.db_parameters = dict(dbn='sqlite', db="testDB")
web.httpserver.runsimple = web.httpserver.runbasic
web.run(urls, globals(), web.reloader)
The program doesn't return any data from table.A. The sqlite
statement does work when used standalone (ie. outside of webpy). Any
ideas what might be the problem?
On Apr 13, 9:34 am, dineshv <[EMAIL PROTECTED]> wrote:
> Anand
>
> Am I replacing the web.connect statement with the
> web.config.bd_parameters statement?
>
> Also, are there any other administrative db.py statements that I
> should include before executing sql statements?
>
> On Apr 13, 4:19 am, "Anand Chitipothu" <[EMAIL PROTECTED]> wrote:
>
> > > The database connection statement is placed before web.run and is:
>
> > > [L61] web.connect(
>
> > try adding web.config.db_parameters = dict(dbn='sqlite', db="testDB.db")
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---