Posted By

MartinJanda on 06/28/10


Tagged

db python webpy


Versions (?)

web.py db insert


 / Published in: Python
 

URL: http://webpy.org/cookbook/insert

  1. Once the database is defined as such, performing insert can be performed like this:
  2.  
  3. # Insert an entry into table 'mytable'
  4. sequence_id = db.insert('mytable', firstname="Bob",lastname="Smith",joindate=web.SQLLiteral("NOW()"))
  5.  
  6. The insert statement takes the following keyword arguments:
  7.  
  8. tablename seqname
  9. _test
  10. **values
  11. tablename
  12.  
  13. The name of the table in your database to which you would like to add data to.
  14. seqname
  15.  
  16. An optional argument, the default value is None. Set seqname to the ID if it's not the default, or to False.
  17. _test
  18.  
  19. The _test variable lets you see the SQL produced by the statement:
  20.  
  21. results = db.select('mytable', offset=10, _test=True)
  22. ><sql: 'SELECT * FROM mytable OFFSET 10'>
  23.  
  24. **values
  25.  
  26. A set of named arguments that represent the fields in your table. If values are not given, the database may create default values or issue a warning.

Report this snippet  

You need to login to post a comment.