-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
44 lines (34 loc) · 1006 Bytes
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import os
import sqlite3
import pyodbc
import sys
import preferences
import connect
class Database:
def __init__(self, db_type: str, server: str, username: str, password: str):
self.db_type = db_type
self.server = server
self.username = username
self.password = password
def get_connection(self):
if self.db_type == "mssql":
# conn = pyodbc.connect(f"DSN={self.server}"
# return conn
return connect.get_cursor()
elif self.db_type == "sqlite3":
conn = sqlite3.connect(self.server)
return conn.cursor()
# def get_cursor(self):
# conn = self.get_connection()
# cur = conn.cursor()
# return cur
if __name__ == "__main__":
sql = """
SELECT TOP 10 *
FROM sec.sr_instructor i
"""
msdb = Database("mssql", "EDW", "NETID\cqoverly", "12rover12")
cur = msdb.get_connection()
cur.execute(sql)
for r in cur:
print(r)