Skip to content

Commit

Permalink
Merge pull request #98 from IBM/fix/not_authorized_to_QADBFDEP
Browse files Browse the repository at this point in the history
Fix no authority to QADBFDEP
  • Loading branch information
TongkunZhang authored May 19, 2022
2 parents 8931389 + 88cba68 commit 94805d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion makei/crtfrmstmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,12 @@ def get_physical_dependencies(obj: str, lib: str, include_self: bool, job: Optio
if job is None:
job = IBMJob()

dep_files, _ = job.run_sql(f"Select DBFFDP, DBFLDP From QSYS.QADBFDEP Where DBFLIB='{lib}' and DBFFIL='{obj}'")
# Run DSPDBR command and save the result into a file
job.run_cl(f"DSPDBR FILE({lib}/{obj}) OUTPUT(*OUTFILE) OUTFILE(QTEMP/DEPOUT)")
# Query from the file to get the dependencies
dep_files, _ = job.run_sql(f"SELECT WHREFI, WHRELI from QTEMP.DEPOUT")
# For PF without deps, the result will be [(' ', ' ')], so filter it
dep_files = list(filter(lambda t: t[0].strip() and t[1].strip(), dep_files))
result = list(map(lambda dep_file: (dep_file[0].strip(), dep_file[1].strip(), "FILE"), dep_files))
if include_self:
result.append((obj, lib, "FILE"))
Expand Down
8 changes: 4 additions & 4 deletions makei/ibm_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ def __del__(self):

def run_cl(self, cmd: str, ignore_errors: bool = False, log: bool = False):
if log:
print(f"▶️ {cmd}")
print(f"> {cmd}")
with closing(self.conn.cursor()) as cursor:
try:
cursor.callproc("qsys2.qcmdexc", [cmd])
return True
except Exception as e:
if not ignore_errors:
print(f" {cmd}")
print(f"[FAILED] {cmd}")
raise
return False

def run_sql(self, sql, ignore_errors=False, log: bool = False):
with closing(self.conn.cursor()) as cursor:
try:
if log:
print(f"🔎 {sql}")
print(f"[QUERY] {sql}")
cursor.execute(sql)
try:
column_names = [column[0] for column in cursor.description]
Expand All @@ -55,7 +55,7 @@ def run_sql(self, sql, ignore_errors=False, log: bool = False):
return (rows, column_names)
except Exception as e:
if not ignore_errors:
print(f" {sql}")
print(f"[FAILED] {sql}")
raise

def _dump_results_to_dict(self, results: Tuple[List[str], List[List[Any]]]):
Expand Down

0 comments on commit 94805d6

Please sign in to comment.