13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Working with databaseshttp://www.zetcode.com/wxpython/databases/and the key is incremented automatically by one. <strong>The</strong>implementation of the autoincrement feature may differ amongRDMSs. In the next example we will show how it is done in SQLitedatabase.sqlite> create table books(id integer primary key autoincrement not null, name text, ausqlite> insert into books (name, author) values ('anna karenina', 'leo tolstoy');sqlite> insert into books (name, author) values ('father goriot', 'honore de balzac');sqlite> select * from books;1|anna karenina|leo tolstoy2|father goriot|honore de balzacsqlite><strong>The</strong> keyword autoincrement is used to create autoincrementalprimary key in SQLite.Security considerationsIt is possible but insecure to pass parameters this way.bookname = 'atlante illustrato di filosofia'bookauthor = 'ubaldo nicola'cur.execute("insert into books(name, author) values ('%s', '%s')" % (bookname, bookauthIt is vulnerable to attacks. <strong>The</strong>se attacks are called SQL injections.Don't do this.>>> import sqlite3 as lite>>> print lite.paramstyleqmark<strong>The</strong> python Database API specification lists these possible parameterstyle passings:qmarknumericnamedformatpyformatPython SQLite API uses the qmark (question mark) quoting. <strong>The</strong>previous example rewritten in qmark style:bookname = 'atlante illustrato di filosofia'bookauthor = 'ubaldo nicola'cur.execute('insert into books(name, author) values (?, ?)', (bookname, bookauthor))TODO blob9 de 12 27/04/2008 1:06

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!