maroph icon

Create/Connect SQLite Database

maroph | PRO | 11/05/19 12:00:25 PM UTC | 0 ⭐ | 323 👁️ | Never ⏰ | []
Python |

740 B

|

None

|

0 👍

/

0 👎

#!/usr/bin/env python3
#
# Source: SQLite Python: Creating a New Database
# https://www.sqlitetutorial.net/sqlite-python/creating-database/
#
import sqlite3
from sqlite3 import Error
 
def create_connection(db_file):
    """ create a database connection to a SQLite database """
    con = None
    try:
        if db_file != "":
            # use a file based database
            conn = sqlite3.connect(db_file)
        else:
            # use a in-memory database
            conn = sqlite3.connect(':memory:')
        print(sqlite3.version)
    except Error as e:
        print(e)
    finally:
        if conn:
            conn.close()
 
if __name__ == '__main__':
    #create_connection("./pythonsqlite.db")
    create_connection("")

Comments