Importing a csv file to sqllite3 using python functional programmingHow do I copy a file in Python?Save PL/pgSQL output from PostgreSQL to a CSV fileHow to import other Python files?How to import CSV file data into a PostgreSQL table?Find all files in a directory with extension .txt in PythonImporting files from different folderHow do you append to a file in Python?In Node.js, how do I “include” functions from my other files?Pandas writing dataframe to CSV fileHow to import an SQL file using the command line in MySQL?
Output visual diagram of picture
Center page as a whole without centering each element individually
PTIJ: Which Dr. Seuss books should one obtain?
Capacitor electron flow
How to test the sharpness of a knife?
Make a Bowl of Alphabet Soup
Why is "la Gestapo" feminine?
Did I make a mistake by ccing email to boss to others?
What properties make a magic weapon befit a Rogue more than a DEX-based Fighter?
Do I have to take mana from my deck or hand when tapping this card?
Friend wants my recommendation but I don't want to give it to him
Are hand made posters acceptable in Academia?
How to preserve electronics (computers, ipads, phones) for hundreds of years?
1 John in Luther’s Bibel
Not hide and seek
Why didn’t Eve recognize the little cockroach as a living organism?
What is it called when someone votes for an option that's not their first choice?
Strange behavior in TikZ draw command
Is there a distance limit for minecart tracks?
Why does the frost depth increase when the surface temperature warms up?
Sort with assumptions
"Oh no!" in Latin
Does capillary rise violate hydrostatic paradox?
Is divisi notation needed for brass or woodwind in an orchestra?
Importing a csv file to sqllite3 using python functional programming
How do I copy a file in Python?Save PL/pgSQL output from PostgreSQL to a CSV fileHow to import other Python files?How to import CSV file data into a PostgreSQL table?Find all files in a directory with extension .txt in PythonImporting files from different folderHow do you append to a file in Python?In Node.js, how do I “include” functions from my other files?Pandas writing dataframe to CSV fileHow to import an SQL file using the command line in MySQL?
I know there are some other posts out there, but I was not able to find the specific question I had in mind.
I'm using US_baby_names csv file. and want to import this csv file line by line into sqlite3 as a table.
I'm able to create the table called storage.
I'm then trying to read lines in the csv file and put it into that table, but I must be doing something wrong.
import sqlite3 as sql
from sqlite3 import Error
import csv
def CreateConnection ( dbFileName ):
try:
conn = sql.connect(dbFileName)
return conn
except Error as e:
print(e)
return None
def CreateNew( dbConnection, new):
sql = """INSERT INTO storage (dat, Id, Name, Year, group, subgroup, Count)
VALUES (?,?,?,?,?,?,?)"""
try:
cursor = dbConnection.cursor()
cursor.execute(sql, new)
return cursor.lastrowid
except Error as e:
print(e)
def Main():
database = "storage.db"
dbConnection = CreateConnection(database)
with open('storage.csv', 'rb') as fin:
dr = csv.DictReader(fin)
to_db = [(i['dat'], i['Id'], i['Name'], i['Year'], i['group'], i['subgroup'], i['Count'])
for i in dr]
cursor.executemany(CreateNew(sql, to_db))
dbConnection.close()
if __name__ == "__main__":
Main()
I believe my cursor.executemany is wrong, but I'm not able to figure out what else to do..
Thanks
python csv import sqlite3
add a comment |
I know there are some other posts out there, but I was not able to find the specific question I had in mind.
I'm using US_baby_names csv file. and want to import this csv file line by line into sqlite3 as a table.
I'm able to create the table called storage.
I'm then trying to read lines in the csv file and put it into that table, but I must be doing something wrong.
import sqlite3 as sql
from sqlite3 import Error
import csv
def CreateConnection ( dbFileName ):
try:
conn = sql.connect(dbFileName)
return conn
except Error as e:
print(e)
return None
def CreateNew( dbConnection, new):
sql = """INSERT INTO storage (dat, Id, Name, Year, group, subgroup, Count)
VALUES (?,?,?,?,?,?,?)"""
try:
cursor = dbConnection.cursor()
cursor.execute(sql, new)
return cursor.lastrowid
except Error as e:
print(e)
def Main():
database = "storage.db"
dbConnection = CreateConnection(database)
with open('storage.csv', 'rb') as fin:
dr = csv.DictReader(fin)
to_db = [(i['dat'], i['Id'], i['Name'], i['Year'], i['group'], i['subgroup'], i['Count'])
for i in dr]
cursor.executemany(CreateNew(sql, to_db))
dbConnection.close()
if __name__ == "__main__":
Main()
I believe my cursor.executemany is wrong, but I'm not able to figure out what else to do..
Thanks
python csv import sqlite3
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39
add a comment |
I know there are some other posts out there, but I was not able to find the specific question I had in mind.
I'm using US_baby_names csv file. and want to import this csv file line by line into sqlite3 as a table.
I'm able to create the table called storage.
I'm then trying to read lines in the csv file and put it into that table, but I must be doing something wrong.
import sqlite3 as sql
from sqlite3 import Error
import csv
def CreateConnection ( dbFileName ):
try:
conn = sql.connect(dbFileName)
return conn
except Error as e:
print(e)
return None
def CreateNew( dbConnection, new):
sql = """INSERT INTO storage (dat, Id, Name, Year, group, subgroup, Count)
VALUES (?,?,?,?,?,?,?)"""
try:
cursor = dbConnection.cursor()
cursor.execute(sql, new)
return cursor.lastrowid
except Error as e:
print(e)
def Main():
database = "storage.db"
dbConnection = CreateConnection(database)
with open('storage.csv', 'rb') as fin:
dr = csv.DictReader(fin)
to_db = [(i['dat'], i['Id'], i['Name'], i['Year'], i['group'], i['subgroup'], i['Count'])
for i in dr]
cursor.executemany(CreateNew(sql, to_db))
dbConnection.close()
if __name__ == "__main__":
Main()
I believe my cursor.executemany is wrong, but I'm not able to figure out what else to do..
Thanks
python csv import sqlite3
I know there are some other posts out there, but I was not able to find the specific question I had in mind.
I'm using US_baby_names csv file. and want to import this csv file line by line into sqlite3 as a table.
I'm able to create the table called storage.
I'm then trying to read lines in the csv file and put it into that table, but I must be doing something wrong.
import sqlite3 as sql
from sqlite3 import Error
import csv
def CreateConnection ( dbFileName ):
try:
conn = sql.connect(dbFileName)
return conn
except Error as e:
print(e)
return None
def CreateNew( dbConnection, new):
sql = """INSERT INTO storage (dat, Id, Name, Year, group, subgroup, Count)
VALUES (?,?,?,?,?,?,?)"""
try:
cursor = dbConnection.cursor()
cursor.execute(sql, new)
return cursor.lastrowid
except Error as e:
print(e)
def Main():
database = "storage.db"
dbConnection = CreateConnection(database)
with open('storage.csv', 'rb') as fin:
dr = csv.DictReader(fin)
to_db = [(i['dat'], i['Id'], i['Name'], i['Year'], i['group'], i['subgroup'], i['Count'])
for i in dr]
cursor.executemany(CreateNew(sql, to_db))
dbConnection.close()
if __name__ == "__main__":
Main()
I believe my cursor.executemany is wrong, but I'm not able to figure out what else to do..
Thanks
python csv import sqlite3
python csv import sqlite3
edited Mar 15 at 22:46
Clueless
asked Mar 7 at 20:10
CluelessClueless
505
505
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39
add a comment |
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39
add a comment |
1 Answer
1
active
oldest
votes
You are almost right with much of your code, but:
- in
cursor.execute(sql, new)
you are passing an iterable,new
, tosqlite3.execute()
(which requires a simple SQL statement), instead ofsqlite3.executemany()
. - Moreover, the result of
CreateNew()
is an integer,lastrowid
, and you pass that result toexecutemany()
. - You must use
Connection.commit()
to save the changes to the database, andConnection.rollback()
to discard them. - You must open the file for the
csv.DictReader
class as a text file, inr
orrt
mode. - Finally, remember that
sqlite3.Connection
is a context manager, so you can use it in awith
statement.
This should be your desired outcome:
import sqlite3 as sql
from sqlite3 import Error
import csv
def create_table(conn):
sql = "CREATE TABLE IF NOT EXISTS baby_names("
"dat TEXT,"
"Id INTEGER PRIMARY KEY,"
"Name TEXT NOT NULL,"
"Year INTEGER NOT NULL,"
"Gender TEXT NOT NULL,"
"State TEXT NOT NULL,"
"Count INTEGER)"
conn.execute(sql)
conn.execute("DELETE FROM baby_names")
def select_all(conn):
for r in conn.execute("SELECT * FROM baby_names").fetchall():
print(r)
def execute_sql_statement(conn, data):
sql = "INSERT INTO baby_names "
"(dat, Id, Name, Year, Gender, State, Count) "
"VALUES (?,?,?,?,?,?,?)"
try:
cursor = conn.executemany(sql, data)
except Error as e:
print(e)
conn.rollback()
return None
else:
conn.commit()
return cursor.lastrowid
def main():
with sql.connect('baby_names.db') as conn, open('US_Baby_Names_right.csv', 'r') as fin:
create_table(conn)
dr = csv.DictReader(fin)
data = [(i['dat'], i['Id'], i['Name'], i['Year'], i['Gender'], i['State'], i['Count']) for i in dr ]
lastrowid = execute_sql_statement(conn, data)
select_all(conn)
main()
I added a create_table()
function just to test my code. I also made up a sample test file as follows:
dat,Id,Name,Year,Gender,State,Count
1,1,John,1998,M,Washington,2
2,2,Luke,2000,M,Arkansas,10
3,3,Carrie,1999,F,Texas,3
The output of the select_all()
function is:
('1',1,'John',1998,'M','Washington',2)
('2',2,'Luke',2000,'M','Arkansas',10)
('3',3,'Carrie',1999,'F','Texas',3)
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052048%2fimporting-a-csv-file-to-sqllite3-using-python-functional-programming%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are almost right with much of your code, but:
- in
cursor.execute(sql, new)
you are passing an iterable,new
, tosqlite3.execute()
(which requires a simple SQL statement), instead ofsqlite3.executemany()
. - Moreover, the result of
CreateNew()
is an integer,lastrowid
, and you pass that result toexecutemany()
. - You must use
Connection.commit()
to save the changes to the database, andConnection.rollback()
to discard them. - You must open the file for the
csv.DictReader
class as a text file, inr
orrt
mode. - Finally, remember that
sqlite3.Connection
is a context manager, so you can use it in awith
statement.
This should be your desired outcome:
import sqlite3 as sql
from sqlite3 import Error
import csv
def create_table(conn):
sql = "CREATE TABLE IF NOT EXISTS baby_names("
"dat TEXT,"
"Id INTEGER PRIMARY KEY,"
"Name TEXT NOT NULL,"
"Year INTEGER NOT NULL,"
"Gender TEXT NOT NULL,"
"State TEXT NOT NULL,"
"Count INTEGER)"
conn.execute(sql)
conn.execute("DELETE FROM baby_names")
def select_all(conn):
for r in conn.execute("SELECT * FROM baby_names").fetchall():
print(r)
def execute_sql_statement(conn, data):
sql = "INSERT INTO baby_names "
"(dat, Id, Name, Year, Gender, State, Count) "
"VALUES (?,?,?,?,?,?,?)"
try:
cursor = conn.executemany(sql, data)
except Error as e:
print(e)
conn.rollback()
return None
else:
conn.commit()
return cursor.lastrowid
def main():
with sql.connect('baby_names.db') as conn, open('US_Baby_Names_right.csv', 'r') as fin:
create_table(conn)
dr = csv.DictReader(fin)
data = [(i['dat'], i['Id'], i['Name'], i['Year'], i['Gender'], i['State'], i['Count']) for i in dr ]
lastrowid = execute_sql_statement(conn, data)
select_all(conn)
main()
I added a create_table()
function just to test my code. I also made up a sample test file as follows:
dat,Id,Name,Year,Gender,State,Count
1,1,John,1998,M,Washington,2
2,2,Luke,2000,M,Arkansas,10
3,3,Carrie,1999,F,Texas,3
The output of the select_all()
function is:
('1',1,'John',1998,'M','Washington',2)
('2',2,'Luke',2000,'M','Arkansas',10)
('3',3,'Carrie',1999,'F','Texas',3)
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
add a comment |
You are almost right with much of your code, but:
- in
cursor.execute(sql, new)
you are passing an iterable,new
, tosqlite3.execute()
(which requires a simple SQL statement), instead ofsqlite3.executemany()
. - Moreover, the result of
CreateNew()
is an integer,lastrowid
, and you pass that result toexecutemany()
. - You must use
Connection.commit()
to save the changes to the database, andConnection.rollback()
to discard them. - You must open the file for the
csv.DictReader
class as a text file, inr
orrt
mode. - Finally, remember that
sqlite3.Connection
is a context manager, so you can use it in awith
statement.
This should be your desired outcome:
import sqlite3 as sql
from sqlite3 import Error
import csv
def create_table(conn):
sql = "CREATE TABLE IF NOT EXISTS baby_names("
"dat TEXT,"
"Id INTEGER PRIMARY KEY,"
"Name TEXT NOT NULL,"
"Year INTEGER NOT NULL,"
"Gender TEXT NOT NULL,"
"State TEXT NOT NULL,"
"Count INTEGER)"
conn.execute(sql)
conn.execute("DELETE FROM baby_names")
def select_all(conn):
for r in conn.execute("SELECT * FROM baby_names").fetchall():
print(r)
def execute_sql_statement(conn, data):
sql = "INSERT INTO baby_names "
"(dat, Id, Name, Year, Gender, State, Count) "
"VALUES (?,?,?,?,?,?,?)"
try:
cursor = conn.executemany(sql, data)
except Error as e:
print(e)
conn.rollback()
return None
else:
conn.commit()
return cursor.lastrowid
def main():
with sql.connect('baby_names.db') as conn, open('US_Baby_Names_right.csv', 'r') as fin:
create_table(conn)
dr = csv.DictReader(fin)
data = [(i['dat'], i['Id'], i['Name'], i['Year'], i['Gender'], i['State'], i['Count']) for i in dr ]
lastrowid = execute_sql_statement(conn, data)
select_all(conn)
main()
I added a create_table()
function just to test my code. I also made up a sample test file as follows:
dat,Id,Name,Year,Gender,State,Count
1,1,John,1998,M,Washington,2
2,2,Luke,2000,M,Arkansas,10
3,3,Carrie,1999,F,Texas,3
The output of the select_all()
function is:
('1',1,'John',1998,'M','Washington',2)
('2',2,'Luke',2000,'M','Arkansas',10)
('3',3,'Carrie',1999,'F','Texas',3)
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
add a comment |
You are almost right with much of your code, but:
- in
cursor.execute(sql, new)
you are passing an iterable,new
, tosqlite3.execute()
(which requires a simple SQL statement), instead ofsqlite3.executemany()
. - Moreover, the result of
CreateNew()
is an integer,lastrowid
, and you pass that result toexecutemany()
. - You must use
Connection.commit()
to save the changes to the database, andConnection.rollback()
to discard them. - You must open the file for the
csv.DictReader
class as a text file, inr
orrt
mode. - Finally, remember that
sqlite3.Connection
is a context manager, so you can use it in awith
statement.
This should be your desired outcome:
import sqlite3 as sql
from sqlite3 import Error
import csv
def create_table(conn):
sql = "CREATE TABLE IF NOT EXISTS baby_names("
"dat TEXT,"
"Id INTEGER PRIMARY KEY,"
"Name TEXT NOT NULL,"
"Year INTEGER NOT NULL,"
"Gender TEXT NOT NULL,"
"State TEXT NOT NULL,"
"Count INTEGER)"
conn.execute(sql)
conn.execute("DELETE FROM baby_names")
def select_all(conn):
for r in conn.execute("SELECT * FROM baby_names").fetchall():
print(r)
def execute_sql_statement(conn, data):
sql = "INSERT INTO baby_names "
"(dat, Id, Name, Year, Gender, State, Count) "
"VALUES (?,?,?,?,?,?,?)"
try:
cursor = conn.executemany(sql, data)
except Error as e:
print(e)
conn.rollback()
return None
else:
conn.commit()
return cursor.lastrowid
def main():
with sql.connect('baby_names.db') as conn, open('US_Baby_Names_right.csv', 'r') as fin:
create_table(conn)
dr = csv.DictReader(fin)
data = [(i['dat'], i['Id'], i['Name'], i['Year'], i['Gender'], i['State'], i['Count']) for i in dr ]
lastrowid = execute_sql_statement(conn, data)
select_all(conn)
main()
I added a create_table()
function just to test my code. I also made up a sample test file as follows:
dat,Id,Name,Year,Gender,State,Count
1,1,John,1998,M,Washington,2
2,2,Luke,2000,M,Arkansas,10
3,3,Carrie,1999,F,Texas,3
The output of the select_all()
function is:
('1',1,'John',1998,'M','Washington',2)
('2',2,'Luke',2000,'M','Arkansas',10)
('3',3,'Carrie',1999,'F','Texas',3)
You are almost right with much of your code, but:
- in
cursor.execute(sql, new)
you are passing an iterable,new
, tosqlite3.execute()
(which requires a simple SQL statement), instead ofsqlite3.executemany()
. - Moreover, the result of
CreateNew()
is an integer,lastrowid
, and you pass that result toexecutemany()
. - You must use
Connection.commit()
to save the changes to the database, andConnection.rollback()
to discard them. - You must open the file for the
csv.DictReader
class as a text file, inr
orrt
mode. - Finally, remember that
sqlite3.Connection
is a context manager, so you can use it in awith
statement.
This should be your desired outcome:
import sqlite3 as sql
from sqlite3 import Error
import csv
def create_table(conn):
sql = "CREATE TABLE IF NOT EXISTS baby_names("
"dat TEXT,"
"Id INTEGER PRIMARY KEY,"
"Name TEXT NOT NULL,"
"Year INTEGER NOT NULL,"
"Gender TEXT NOT NULL,"
"State TEXT NOT NULL,"
"Count INTEGER)"
conn.execute(sql)
conn.execute("DELETE FROM baby_names")
def select_all(conn):
for r in conn.execute("SELECT * FROM baby_names").fetchall():
print(r)
def execute_sql_statement(conn, data):
sql = "INSERT INTO baby_names "
"(dat, Id, Name, Year, Gender, State, Count) "
"VALUES (?,?,?,?,?,?,?)"
try:
cursor = conn.executemany(sql, data)
except Error as e:
print(e)
conn.rollback()
return None
else:
conn.commit()
return cursor.lastrowid
def main():
with sql.connect('baby_names.db') as conn, open('US_Baby_Names_right.csv', 'r') as fin:
create_table(conn)
dr = csv.DictReader(fin)
data = [(i['dat'], i['Id'], i['Name'], i['Year'], i['Gender'], i['State'], i['Count']) for i in dr ]
lastrowid = execute_sql_statement(conn, data)
select_all(conn)
main()
I added a create_table()
function just to test my code. I also made up a sample test file as follows:
dat,Id,Name,Year,Gender,State,Count
1,1,John,1998,M,Washington,2
2,2,Luke,2000,M,Arkansas,10
3,3,Carrie,1999,F,Texas,3
The output of the select_all()
function is:
('1',1,'John',1998,'M','Washington',2)
('2',2,'Luke',2000,'M','Arkansas',10)
('3',3,'Carrie',1999,'F','Texas',3)
edited Mar 7 at 21:06
answered Mar 7 at 20:38
A. SematA. Semat
584
584
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
add a comment |
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
Thank you, your comments made it easy to see my mistakes! I really appreciate it
– Clueless
Mar 7 at 21:18
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55052048%2fimporting-a-csv-file-to-sqllite3-using-python-functional-programming%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Using a function to open a database connection and return the connection is a bad idea. Use a context manager. You're passing a function that executes a database transaction to executemany, which isn't going to work at all
– pistolpete
Mar 7 at 20:39