pageCount.py, text of pageCount.py, text of pageCount.html, text of pageCountReset.html.
dbdemo.py, text of dbdemo.py, text of login.html, text of logout.html, text of query.html, text of result.html.
Standalone Python program demonstrating database queries:
test.py,
test.py output
NOTE: See web.py Resources Section below for how to avoid SQL injection
attacks when using db.query().
Exercise: Modify the following todo app to add this functionality:
todo.py, text of todo.py, text of todo.html, schema for original todo table.
If necessary, use these SQL commands to drop the original todo table and todo id sequence from your database:
drop sequence todo_id_seq; drop table todo;Look below for resources.
todos = list(db.query('select * from todo order by id asc;'))This is useful if you want to iterate through the list more than once; an iterable object can be iterated through only once.
def query(query_string, vars = {}): return list(db.query(query_string, vars))You can then do something along these lines:
queryString = 'select * from Users where username = $name' varsDict = { 'name' : input.name } result = query(queryString, varsDict)and web.py will handle escaping the user input.