![]() ![]() We used the column mode and turned on the headers. Note that we modified the way the data is displayed in the console. Let's see what we've done so far using sqlite command shell:Įnter SQL statements terminated with a " "ġ|Learning Python|Mark Lutz|$36.19|Jul 6, 2013Ģ|Two Scoops of Django: Best Practices For Django 1.6|Daniel Greenfeld|$34.68|Feb 1, 2014ģ|Python Cookbook|David Beazley|$30.29|May 29, 2013Ĥ|The Quick Python Book|Naomi R. > cursor.executemany('''INSERT INTO books(title, author, price, year) VALUES(?,?,?,?)''', books) > books = [(title4,author4, price4, year4), If we need to insert several users, we can use executemany and a list with the tuples: VALUES(:title, :author, :price, :year)''', But this time, we'll do it another way: passing a dictionary using the ":keyname" placeholder: If we have more books to insert, we can continue. The values of the Python variables are passed inside a tuple. Never use string operations or concatenation to make your queries because is very insecure. Note: If we need values from Python variables it is recommended to use the "?" placeholder. > cursor.execute('''INSERT INTO books(title, author, price, year) > title2 = 'Two Scoops of Django: Best Practices For Django 1.6' title TEXT, author TEXT, price TEXT, year TEXT) > cursor.execute('''CREATE TABLE books(id INTEGER PRIMARY KEY, In this example we are going to insert two books in the database, their information will stored in python variables. ![]() To insert data we use the cursor to execute the query. INSERT - Inserting Data into the Database ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |