Created
July 2, 2019 16:37
-
-
Save devmnj/6ae4f1acf999b4b720a60ef512289970 to your computer and use it in GitHub Desktop.
Python SQlite - insertion with tuples and List
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
con = sqlite3.connect('mydb.sqlite') | |
con.execute("CREATE TABLE IF NOT EXISTS users(id INTEGER ,name TEXT, ecode TEXT);") | |
con.execute("CREATE TABLE IF NOT EXISTS employees(id INTEGER PRIMARY KEY,ename TEXT, eid INTEGER);") | |
empnames = [ | |
('jhon', 1), | |
('martin', 2), | |
('dev', 3) | |
] | |
companies = [ | |
('Foo', 12), | |
('Bar', 7), | |
('Moo', 99), | |
] | |
comp='SAMSUNG' | |
comp_id=7006 | |
# argument must be touple | |
# if one parameter place additional coma | |
con.execute("INSERT INTO users (id) VALUES (?)", (comp_id,)) | |
con.execute("INSERT INTO users (name,id) VALUES (?,?)", (comp,comp_id)) | |
con.executemany("INSERT or ignore INTO employees (ename,id) VALUES (?,?)", empnames) | |
con.commit() | |
# I think this will help you | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment