Files
utilities/work/suspended_check/sql/Queries.py
T
2025-05-20 09:16:54 -04:00

86 lines
2.7 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 configparser
from base64 import b64decode
from encodings import utf_8
class sfquery(object):
def __init__(self):
self.cobject = []
def retrieve(self, options):
queries = {}
queries["check_suspended"] = options["check_suspended"]
return queries
def generate_query(
options,
schema,
tablename,
start_date,
end_date,
use_daterange,
database_name,
columnlist,
):
if use_daterange == "0":
query = (
options["get_data"]
.replace("r_impacted_tables.SCHEM", schema)
.replace("r_impacted_tables.TBL", tablename)
.replace("startdate", start_date)
.replace("sfenv", database_name)
.replace("v_column_list", columnlist)
)
else:
query = (
options["get_daterange"]
.replace("r_impacted_tables.SCHEM", schema)
.replace("r_impacted_tables.TBL", tablename)
.replace("startdate", start_date)
.replace("enddate", end_date)
.replace("sfenv", database_name)
.replace("v_column_list", columnlist)
)
return query
def generate_minusquery(object, minustable, data_columns, fromtable, totable):
query = (
object.replace("minustable", minustable)
.replace("v_column_list", ",".join(data_columns))
.replace(
"fromsfenv.r_impacted_tables.SCHEM.r_impacted_tables.TBL", fromtable
)
.replace("tosfenv.r_impacted_tables.SCHEM.r_impacted_tables.TBL", totable)
)
return query
def generate_recoveryquery(
object, recovertable, columnlist, fromtable, minustable, whereclause
):
query = (
object.replace("recoverytable", recovertable)
.replace("v_column_list", columnlist)
.replace(
"fromsfenv.r_impacted_tables.SCHEM.r_impacted_tables.TBL", fromtable
)
.replace("minustable", minustable)
.replace("columnlist", whereclause)
)
return query
def __del__(self):
pass