Browse files

Page was damaged

  • Loading branch information...
1 parent 75ad793 commit 37258cae5192b123ef2853841dbab47fa8541229 @sitnin sitnin committed with anandology Sep 18, 2009
Showing with 8 additions and 36 deletions.
  1. +8 −36 cookbook/delete.md
View
44 cookbook/delete.md
@@ -5,45 +5,17 @@ title: db.delete
# db.delete
-##Problem:
+### Problem
-You want to delete data from a database
+You want to delete data that's been entered into a database.
-##Solution:
+### Solution
-With version 0.3, databases are defined like this:
-
- db = web.database(dbn='postgres', db='mydata', user='dbuser', pw='')
-
-Once the database is defined as such, performing deletes can be performed like this:
+ import web
- # Delete all entries from table 'mytable'
- db.delete('mytable', where="1=1")
-
-Note that you have to pass a "where" clause, even if you want to delete everything. This is a safety mechanism so you don't accidentally delete all of your data.
-
-This function returns the number of rows is has removed from the database.
-
-The delete statement takes the following keyword arguments:
-
-* where
-* vars
-* _test
-
-
-###where
-The where variable lets you pass where clauses to the SQL delete, such as:
-
- db.delete('mytable', where="id>100")
-
-
-###vars
-The vars variable lets you pass correctly escaped data to SQL delete, such as:
-
- db.delete('mytable', where="id>$num", vars={'num': 100})
+ db = web.database(dbn='postgres', db='mydata', user='dbuser', pw='')
+ db.delete('mytable', where="id=10")
-###_test
-The _test variable lets you see the SQL produced by the statement:
+It is also accepts "using" and "vars" parameters.
- results = db.delete('mytable', where="foo=5", _test=True)
- <sql: 'DELETE FROM mytable WHERE foo=5'>
+The delete method returns the number of rows deleted.

0 comments on commit 37258ca

Please sign in to comment.