Files
utilities/work/recovery-ui/recovery/lib/sfconnect/Connecter.py
T
2025-05-20 09:16:54 -04:00

63 lines
1.9 KiB
Python

"""
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import sqlite3
import psycopg2
from snowflake import connector
class connecter(object):
def __init__(self):
self.cobject = []
def connect(self, sfparams):
user = sfparams[1][1].rstrip()
password = sfparams[1][2]
account = sfparams[1][3]
warehouse = sfparams[1][4]
database = sfparams[1][0]
schema = sfparams[1][5]
try:
conn = connector.connect(
user=user,
password=password,
account=account,
warehouse=warehouse,
database=database,
schema=schema,
)
conn._paramstyle = "qmark"
except Exception as e:
print(f"Unable to connect to schema: {database}.{schema}:")
print(str(e))
else:
print(f"Connected to {database}.{schema} in warehouse: {warehouse}.")
return (database, schema, conn)
def open_sqlite(self, dbfile):
utilconn = sqlite3.connect(dbfile)
utilcur = utilconn.cursor()
return (utilconn, utilcur)
def open_pgsql(self):
try:
conn = psycopg2.connect("dbname='recovery' user='postgres' host='localhost' password='replicate'")
return conn
except:
print(f"Unable to connect to the database")
def __del__(self):
pass