Skip to content

Instantly share code, notes, and snippets.

@gb103
Created January 6, 2021 10:52
Show Gist options
  • Save gb103/29aab274e447e5fa4fd16e7dda5291b8 to your computer and use it in GitHub Desktop.
Save gb103/29aab274e447e5fa4fd16e7dda5291b8 to your computer and use it in GitHub Desktop.
Create People table
import sqlite3
from sqlite3 import Error
def create_connection(db_file):
""" create a database connection to the SQLite database
specified by db_file
:param db_file: database file
:return: Connection object or None
"""
conn = None
try:
conn = sqlite3.connect(db_file)
return conn
except Error as e:
print(e)
return conn
def create_table(conn, create_table_sql):
""" create a table from the create_table_sql statement
:param conn: Connection object
:param create_table_sql: a CREATE TABLE statement
:return:
"""
try:
c = conn.cursor()
c.execute(create_table_sql)
except Error as e:
print(e)
def main():
database = "/Users/gaurav.bansal1/Desktop/image-detection/FaceBase.db"
sql_create_projects_table = """ CREATE TABLE IF NOT EXISTS People (
ID text PRIMARY KEY,
Name text NOT NULL,
Age text NOT NULL,
Gender text NOT NULL,
CR text NOT NULL
); """
# create a database connection
conn = create_connection(database)
# create tables
if conn is not None:
# create projects table
create_table(conn, sql_create_projects_table)
# create tasks table
# create_table(conn, sql_create_tasks_table)
else:
print("Error! cannot create the database connection.")
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment