|
@@ -29,55 +29,67 @@ class DsnConfig:
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-class DatabaseInspect:
|
|
|
|
|
- _cursor: pyodbc.Cursor = None
|
|
|
|
|
- _sqlalchemy_engine: Engine = None
|
|
|
|
|
-
|
|
|
|
|
- def __init__(self, dsn: DsnConfig, source=False):
|
|
|
|
|
- self.dsn = dsn
|
|
|
|
|
- self.type = "SOURCE" if source else "DEST"
|
|
|
|
|
-
|
|
|
|
|
@property
|
|
@property
|
|
|
- def conn_string(self) -> str:
|
|
|
|
|
- if self.dsn.driver == "mssql":
|
|
|
|
|
|
|
+ def conn_string_pyodbc(self) -> str:
|
|
|
|
|
+ if self.driver == "mssql":
|
|
|
return ";".join(
|
|
return ";".join(
|
|
|
[
|
|
[
|
|
|
"Driver={SQL Server Native Client 11.0}",
|
|
"Driver={SQL Server Native Client 11.0}",
|
|
|
- f"Server={self.dsn.server}",
|
|
|
|
|
- f"Database={self.dsn.database}",
|
|
|
|
|
- f"Uid={self.dsn.user}",
|
|
|
|
|
- f"Pwd={self.dsn.password}",
|
|
|
|
|
|
|
+ f"Server={self.server}",
|
|
|
|
|
+ f"Database={self.database}",
|
|
|
|
|
+ f"Uid={self.user}",
|
|
|
|
|
+ f"Pwd={self.password}",
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
- if self.dsn.driver == "mysql":
|
|
|
|
|
- return f"mysql+pymysql://{self.dsn.user}:{self.dsn.password}@{self.dsn.server}/{self.dsn.database}?charset=utf8mb4"
|
|
|
|
|
|
|
+ if self.driver == "mysql":
|
|
|
|
|
+ return f"mysql+pymysql://{self.user}:{self.password}@{self.server}/{self.database}?charset=utf8mb4"
|
|
|
return ";".join(
|
|
return ";".join(
|
|
|
[
|
|
[
|
|
|
"Driver={PostgreSQL Unicode}",
|
|
"Driver={PostgreSQL Unicode}",
|
|
|
- f"Server={self.dsn.server}",
|
|
|
|
|
|
|
+ f"Server={self.server}",
|
|
|
"Port=5432",
|
|
"Port=5432",
|
|
|
- f"Database={self.dsn.database}",
|
|
|
|
|
- f"Uid={self.dsn.user}",
|
|
|
|
|
- f"Pwd={self.dsn.password}",
|
|
|
|
|
|
|
+ f"Database={self.database}",
|
|
|
|
|
+ f"Uid={self.user}",
|
|
|
|
|
+ f"Pwd={self.password}",
|
|
|
]
|
|
]
|
|
|
)
|
|
)
|
|
|
- # f"DSN={self.dsn.server};UID={self.dsn.user};PWD={self.dsn.password}"
|
|
|
|
|
|
|
+ # f"DSN={self.server};UID={self.user};PWD={self.password}"
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def conn_string_sqlalchemy(self) -> str:
|
|
def conn_string_sqlalchemy(self) -> str:
|
|
|
- if self.dsn.driver == "mssql":
|
|
|
|
|
|
|
+ if self.driver == "mssql":
|
|
|
return (
|
|
return (
|
|
|
- f"mssql+pyodbc://{self.dsn.user}:{self.dsn.password}@{self.dsn.server}/{self.dsn.database}?"
|
|
|
|
|
|
|
+ f"mssql+pyodbc://{self.user}:{self.password}@{self.server}/{self.database}?"
|
|
|
"driver=SQL+Server+Native+Client+11.0"
|
|
"driver=SQL+Server+Native+Client+11.0"
|
|
|
)
|
|
)
|
|
|
- if self.dsn.driver == "mysql":
|
|
|
|
|
- return f"mysql+pymysql://{self.dsn.user}:{self.dsn.password}@{self.dsn.server}/{self.dsn.database}?charset=utf8mb4"
|
|
|
|
|
- return f"pyodbc://{self.dsn.user}:{self.dsn.password}@{self.dsn.server}/{self.dsn.database}?driver={self.dsn.driver}"
|
|
|
|
|
|
|
+ if self.driver == "mysql":
|
|
|
|
|
+ return f"mysql+pymysql://{self.user}:{self.password}@{self.server}/{self.database}?charset=utf8mb4"
|
|
|
|
|
+ return f"pyodbc://{self.user}:{self.password}@{self.server}/{self.database}?driver={self.driver}"
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def bcp_conn_params(self) -> str:
|
|
|
|
|
+ return f"-S {self.server} -d {self.database} -U {self.user} -P {self.password}"
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class DatabaseInspect:
|
|
|
|
|
+ _cursor: pyodbc.Cursor = None
|
|
|
|
|
+ _sqlalchemy_engine: Engine = None
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self, dsn: DsnConfig, source=False):
|
|
|
|
|
+ self.dsn = dsn
|
|
|
|
|
+ self.type = "SOURCE" if source else "DEST"
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def conn_string(self) -> str:
|
|
|
|
|
+ return self.dsn.conn_string_pyodbc
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def conn_string_sqlalchemy(self) -> str:
|
|
|
|
|
+ return self.dsn.conn_string_sqlalchemy
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def bcp_conn_params(self) -> str:
|
|
def bcp_conn_params(self) -> str:
|
|
|
- return f"-S {self.dsn.server} -d {self.dsn.database} -U {self.dsn.user} -P {self.dsn.password}"
|
|
|
|
|
|
|
+ return self.dsn.bcp_conn_params
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def cursor(self) -> pyodbc.Cursor:
|
|
def cursor(self) -> pyodbc.Cursor:
|