From ba2833b81e1205844db2bf3feb08585923bd9c3e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 6 Nov 2017 11:46:14 +0100 Subject: [PATCH] Bugfixing pp_lib/import_pdnsdata.py --- pp_lib/import_pdnsdata.py | 61 ++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/pp_lib/import_pdnsdata.py b/pp_lib/import_pdnsdata.py index c9ae462..2788b69 100644 --- a/pp_lib/import_pdnsdata.py +++ b/pp_lib/import_pdnsdata.py @@ -553,38 +553,39 @@ class ImportPdnsdataApp(PpConfigApplication): if not self.simulate: tgt_cursor.execute(sql) - LOG.debug("Get max. Zone Template Permission Id ...") - sql = "SELECT MAX(id) AS max_id FROM perm_templ_items" - if self.verbose > 1: - LOG.debug("SQL: {}".format(sql)) - tgt_cursor.execute(sql) - result = tgt_cursor.fetchone() - if self.verbose > 3: - LOG.debug("Got max Zone Template Permission Id:\n{}".format(pp(result))) - if result[0] is not None: - max_id = int(result[0]) - else: - max_id = 0 - sql = "SELECT SETVAL('perm_templ_items_id_seq', %s)" - LOG.debug("Setting curval of perm_templ_items_id_seq to {} ...".format(max_id)) - if self.verbose > 1: - LOG.debug("SQL: {}".format(sql)) - if not self.simulate: - tgt_cursor.execute(sql, (max_id, )) + if self.tgt_db_is_poweradmin: + LOG.debug("Get max. Zone Template Permission Id ...") + sql = "SELECT MAX(id) AS max_id FROM perm_templ_items" + if self.verbose > 1: + LOG.debug("SQL: {}".format(sql)) + tgt_cursor.execute(sql) + result = tgt_cursor.fetchone() + if self.verbose > 3: + LOG.debug("Got max Zone Template Permission Id:\n{}".format(pp(result))) + if result[0] is not None: + max_id = int(result[0]) + else: + max_id = 0 + sql = "SELECT SETVAL('perm_templ_items_id_seq', %s)" + LOG.debug("Setting curval of perm_templ_items_id_seq to {} ...".format(max_id)) + if self.verbose > 1: + LOG.debug("SQL: {}".format(sql)) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) - sql = "SELECT SETVAL('zone_templ_records_id_seq', 0)" - LOG.debug("Setting curval of zone_templ_records_id_seq to {} ...".format(0)) - if self.verbose > 1: - LOG.debug("SQL: {}".format(sql)) - if not self.simulate: - tgt_cursor.execute(sql, (max_id, )) + sql = "SELECT SETVAL('zone_templ_records_id_seq', 0)" + LOG.debug("Setting curval of zone_templ_records_id_seq to {} ...".format(0)) + if self.verbose > 1: + LOG.debug("SQL: {}".format(sql)) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) - sql = "SELECT SETVAL('zones_id_seq', 0)" - LOG.debug("Setting curval of zones_id_seq to {} ...".format(0)) - if self.verbose > 1: - LOG.debug("SQL: {}".format(sql)) - if not self.simulate: - tgt_cursor.execute(sql, (max_id, )) + sql = "SELECT SETVAL('zones_id_seq', 0)" + LOG.debug("Setting curval of zones_id_seq to {} ...".format(0)) + if self.verbose > 1: + LOG.debug("SQL: {}".format(sql)) + if not self.simulate: + tgt_cursor.execute(sql, (max_id, )) LOG.debug("Commiting changes ...") self.tgt_connection.commit() -- 2.39.5