Skip to content

Instantly share code, notes, and snippets.

@G10DRAS
Last active June 29, 2018 10:36
Show Gist options
  • Save G10DRAS/cca27e0911445cfe7aa78f7cc7b061e0 to your computer and use it in GitHub Desktop.
Save G10DRAS/cca27e0911445cfe7aa78f7cc7b061e0 to your computer and use it in GitHub Desktop.
SQLite Script
import sqlite3
def Main():
try:
con = sqlite3.connect('sqlite.db')
cur = con.cursor()
cur.executescript("""DROP TABLE IF EXISTS Animal;
CREATE TABLE Animal(Id INT, Name TEXT, Price INT);""")
cur.execute("INSERT INTO Animal VALUES(1, 'Cat', 400)")
cur.execute("INSERT INTO Animal VALUES(2, 'Dog', 600)")
cur.execute("INSERT INTO Animal VALUES(3, 'Rabbit', 200)")
cur.execute("INSERT INTO Animal VALUES(4, 'Bird', 60)")
pets = ((3, 'Rabbit', 200),
(4, 'Bird', 60),
(5, 'Goat', 500))
cur.executemany("INSERT INTO Animal VALUES(?, ?, ?)", pets)
con.commit()
cur.execute("SELECT * FROM Animal")
data = cur.fetchall()
for row in data:
print(row)
except sqlite3.Error:
if con:
con.rollback()
finally:
if con:
con.close()
if __name__ == '__main__':
Main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment