Skip to content
Snippets Groups Projects
sandbox_sqlite.py 933 B
Newer Older
import os
import sqlite3
from pathlib import Path
from sqlite3 import Error
cwd = Path(os.path.dirname(os.path.abspath(__file__)))
Clemens Berteld's avatar
Clemens Berteld committed
spatialite_path = 'D:/Uni/Master/01_SS2021/Automatisierte_Geodatenprozessierung/temperaturverteilung/dataacquisition/mod_spatialite-5.0.1-win-amd64'
os.environ['PATH'] = spatialite_path + ';' + os.environ['PATH']


def create_connection(db_file):
    """ create a database connection to a SQLite database """
    try:
        conn = sqlite3.connect(db_file)
Clemens Berteld's avatar
Clemens Berteld committed
        conn.enable_load_extension(True)
        conn.load_extension("mod_spatialite")
Clemens Berteld's avatar
Clemens Berteld committed
        return conn
Clemens Berteld's avatar
Clemens Berteld committed
connection = create_connection('temperatures.db')    # ':memory:' for saving in RAM

try:
    c = connection.cursor()
    # c.execute("CREATE TABLE test (id INTEGER);")
    # c.execute("select * from test;")
    print(c.fetchall())
except Error as e:
    print(e)