diff --git a/py/core/doctype/control_panel/control_panel.py b/py/core/doctype/control_panel/control_panel.py index da1786b2ea..b6aecf8f6c 100644 --- a/py/core/doctype/control_panel/control_panel.py +++ b/py/core/doctype/control_panel/control_panel.py @@ -6,7 +6,6 @@ from webnotes.model.doc import Document from webnotes.model.code import get_obj from webnotes import session, form, is_testing, msgprint, errprint -sql = webnotes.conn.sql get_value = webnotes.conn.get_value # ----------------------------------------------------------------------------------------- @@ -19,7 +18,7 @@ class DocType: def on_update(self): # clear cache on save - sql("delete from __SessionCache") + webnotes.conn.sql("delete from __SessionCache") def upload_many(self,form): pass diff --git a/py/core/doctype/custom_field/custom_field.py b/py/core/doctype/custom_field/custom_field.py index 9426c5e52d..124c22228c 100644 --- a/py/core/doctype/custom_field/custom_field.py +++ b/py/core/doctype/custom_field/custom_field.py @@ -5,11 +5,7 @@ from webnotes.utils import cint, cstr, flt, formatdate, now from webnotes.model.doc import Document from webnotes import msgprint, errprint -sql = webnotes.conn.sql - # ----------------------------------------------------------------------------------------- - - class DocType: def __init__(self, d, dl): self.doc, self.doclist = d, dl @@ -17,6 +13,7 @@ class DocType: # Get Fields # ----------- def get_fields_label(self): + sql = webnotes.conn.sql label_name = [] for i in sql("SELECT idx, label FROM tabDocField WHERE parent = '%s' and ifnull(hidden,0) = 0 and fieldname != '%s' order by idx" % (self.doc.dt, cstr(self.doc.fieldname))): i[1] and i[0] and label_name.append(i[1]+' - '+cstr(i[0])) return "\n".join(label_name) @@ -34,6 +31,7 @@ class DocType: # Validate Field # --------------- def validate_field(self): + sql = webnotes.conn.sql if self.doc.__islocal == 1 and sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)): msgprint("%s field already exists in Document : %s" % (self.doc.label, self.doc.dt)) raise Exception @@ -47,6 +45,7 @@ class DocType: # Update Field # ------------- def update_field(self, df, new): + sql = webnotes.conn.sql import webnotes.model sql("update tabDocField set idx = idx + 1, modified = %s where parent = %s and idx > %s", (now(),self.doc.dt, self.idx)) for k in self.doc.fields: @@ -62,6 +61,7 @@ class DocType: # Add Field # ---------- def add_field(self): + sql = webnotes.conn.sql field_exists = sql("select name from tabDocField where parent = %s and (label = %s or fieldname = %s)" , (self.doc.dt, self.doc.label, self.doc.fieldname)) field_exists = field_exists and field_exists[0][0] or '' self.ignore_fields = ['dt','trash_reason','insert_after','index','customfield1','length'] @@ -88,6 +88,7 @@ class DocType: # Trash # ------ def on_trash(self): + sql = webnotes.conn.sql sql("update tabDocField set idx = idx - 1 where parent = %s and idx > %s" , (self.doc.dt, cint((self.doc.insert_after).split(' - ')[1]))) sql("delete from tabDocField where parent = %s and fieldname = %s", (self.doc.dt, self.doc.fieldname)) diff --git a/py/core/doctype/doctype/doctype.py b/py/core/doctype/doctype/doctype.py index ff07ae7031..c24b4aed68 100644 --- a/py/core/doctype/doctype/doctype.py +++ b/py/core/doctype/doctype/doctype.py @@ -2,7 +2,6 @@ import webnotes from webnotes.utils import now, cint -sql = webnotes.conn.sql msgprint = webnotes.msgprint @@ -15,6 +14,7 @@ class DocType: self.doclist = doclist def change_modified_of_parent(self): + sql = webnotes.conn.sql parent_list = sql('SELECT parent from tabDocField where fieldtype="Table" and options="%s"' % self.doc.name) for p in parent_list: sql('UPDATE tabDocType SET modified="%s" WHERE `name`="%s"' % (now(), p[0])) @@ -35,6 +35,7 @@ class DocType: # check if this series is not used elsewhere # def validate_series(self, autoname=None, name=None): + sql = webnotes.conn.sql if not autoname: autoname = self.doc.autoname if not name: name = self.doc.name @@ -73,6 +74,7 @@ class DocType: def on_update(self): + sql = webnotes.conn.sql # make schma changes from webnotes.model.db_schema import updatedb updatedb(self.doc.name) diff --git a/py/core/doctype/search_criteria/search_criteria.py b/py/core/doctype/search_criteria/search_criteria.py index 15cfa703c7..4c1826d745 100644 --- a/py/core/doctype/search_criteria/search_criteria.py +++ b/py/core/doctype/search_criteria/search_criteria.py @@ -49,7 +49,7 @@ class DocType: self.set_module() self.autoname() - sql("update `tabSearch Criteria` set name=%s where name=%s", (self.doc.name, old_name)) + webnotes.conn.sql("update `tabSearch Criteria` set name=%s where name=%s", (self.doc.name, old_name)) def rename_export(self, old_name): diff --git a/py/webnotes/db.py b/py/webnotes/db.py index 30927aadce..adcd3ca09d 100644 --- a/py/webnotes/db.py +++ b/py/webnotes/db.py @@ -124,7 +124,7 @@ class Database: * Execute a `query`, with given `values` * returns as a dictionary if as_dict = 1 * returns as a list of lists (with cleaned up dates and decimals) if as_list = 1 - """ + """ # in transaction validations self.check_transaction_status(query) @@ -340,4 +340,7 @@ class Database: Close my connection """ if self._conn: + self._cursor.close() self._conn.close() + self._cursor = None + self._conn = None diff --git a/py/webnotes/utils/scheduler.py b/py/webnotes/utils/scheduler.py index dbaa3d3656..0787883532 100644 --- a/py/webnotes/utils/scheduler.py +++ b/py/webnotes/utils/scheduler.py @@ -92,9 +92,9 @@ class Scheduler: import webnotes, webnotes.defs, webnotes.db try: + webnotes.conn = None webnotes.conn = webnotes.db.Database(user=db_name, password=webnotes.get_db_password(db_name)) webnotes.session = {'user':'Administrator'} - module = '.'.join(event.split('.')[:-1]) method = event.split('.')[-1]