Fixed bug closing connections to sql server
This commit is contained in:
parent
8928c3e307
commit
6161ea2c3e
5 changed files with 91 additions and 70 deletions
|
|
@ -115,7 +115,13 @@ def get_session():
|
||||||
if os.path.isfile(path_cookie):
|
if os.path.isfile(path_cookie):
|
||||||
|
|
||||||
with open(path_cookie) as f:
|
with open(path_cookie) as f:
|
||||||
s=json.loads(f.read())
|
|
||||||
|
json_txt=f.read()
|
||||||
|
|
||||||
|
if(json_txt).strip()!='':
|
||||||
|
s=json.loads(json_txt)
|
||||||
|
else:
|
||||||
|
s={'token': cookie}
|
||||||
else:
|
else:
|
||||||
s={'token': cookie}
|
s={'token': cookie}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,16 @@ class SqlClass:
|
||||||
# Sql connection
|
# Sql connection
|
||||||
self.conn=None
|
self.conn=None
|
||||||
self.connected=False
|
self.connected=False
|
||||||
#self.connection_method=self.connect_to_db_sql
|
|
||||||
self.caching=False
|
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
|
||||||
|
if self.conn==None:
|
||||||
try:
|
try:
|
||||||
def getconn():
|
def getconn():
|
||||||
return MySQLdb.connect(connection['host'],
|
return MySQLdb.connect(self.connection['host'],
|
||||||
user=connection['user'],
|
user=self.connection['user'],
|
||||||
passwd=connection['password'],
|
passwd=self.connection['password'],
|
||||||
db=connection['db'],
|
db=self.connection['db'],
|
||||||
charset='utf8mb4',
|
charset='utf8mb4',
|
||||||
cursorclass=MySQLdb.cursors.DictCursor)
|
cursorclass=MySQLdb.cursors.DictCursor)
|
||||||
|
|
||||||
|
|
@ -46,13 +47,15 @@ class SqlClass:
|
||||||
|
|
||||||
self.error_connection="Error in connection: %s %s" % (e, v)
|
self.error_connection="Error in connection: %s %s" % (e, v)
|
||||||
|
|
||||||
#return False
|
|
||||||
raise NameError(self.error_connection)
|
raise NameError(self.error_connection)
|
||||||
|
|
||||||
|
|
||||||
#Make def query more simple if not debugging.
|
#Make def query more simple if not debugging.
|
||||||
|
|
||||||
def query(self, sql_query, arguments=[], name_connection="default"):
|
def query(self, sql_query, arguments=[], name_connection="default"):
|
||||||
|
|
||||||
|
self.connect()
|
||||||
|
|
||||||
#if fetch_type=="ASSOC":
|
#if fetch_type=="ASSOC":
|
||||||
#fetch_type=MySQLdb.cursors.DictCursor
|
#fetch_type=MySQLdb.cursors.DictCursor
|
||||||
|
|
||||||
|
|
@ -83,17 +86,19 @@ class SqlClass:
|
||||||
#def fetch(self, cursor):
|
#def fetch(self, cursor):
|
||||||
|
|
||||||
#return cursor.fetchone()
|
#return cursor.fetchone()
|
||||||
"""
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
|
||||||
self.close()
|
if self.conn:
|
||||||
"""
|
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
def close(self, name_connection="default"):
|
def close(self, name_connection="default"):
|
||||||
|
|
||||||
if self.conn:
|
if self.conn:
|
||||||
|
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
#self.conn=False
|
self.conn=None
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,15 +20,16 @@ class SqlClass:
|
||||||
# Sql connection
|
# Sql connection
|
||||||
self.conn=None
|
self.conn=None
|
||||||
self.connected=False
|
self.connected=False
|
||||||
#self.connection_method=self.connect_to_db_sql
|
|
||||||
self.caching=False
|
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
|
||||||
|
if self.conn==None:
|
||||||
try:
|
try:
|
||||||
def getconn():
|
def getconn():
|
||||||
return pymysql.connect(connection['host'],
|
return pymysql.connect(self.connection['host'],
|
||||||
user=connection['user'],
|
user=self.connection['user'],
|
||||||
passwd=connection['password'],
|
passwd=self.connection['password'],
|
||||||
db=connection['db'],
|
db=self.connection['db'],
|
||||||
charset='utf8mb4',
|
charset='utf8mb4',
|
||||||
cursorclass=pymysql.cursors.DictCursor)
|
cursorclass=pymysql.cursors.DictCursor)
|
||||||
|
|
||||||
|
|
@ -47,13 +48,15 @@ class SqlClass:
|
||||||
|
|
||||||
self.error_connection="Error in connection: %s %s" % (e, v)
|
self.error_connection="Error in connection: %s %s" % (e, v)
|
||||||
|
|
||||||
#return False
|
|
||||||
raise NameError(self.error_connection)
|
raise NameError(self.error_connection)
|
||||||
|
|
||||||
|
|
||||||
#Make def query more simple if not debugging.
|
#Make def query more simple if not debugging.
|
||||||
|
|
||||||
def query(self, sql_query, arguments=[], name_connection="default"):
|
def query(self, sql_query, arguments=[], name_connection="default"):
|
||||||
|
|
||||||
|
self.connect()
|
||||||
|
|
||||||
#if fetch_type=="ASSOC":
|
#if fetch_type=="ASSOC":
|
||||||
#fetch_type=pymysql.cursors.DictCursor
|
#fetch_type=pymysql.cursors.DictCursor
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import re
|
||||||
import uuid
|
import uuid
|
||||||
from importlib import import_module, reload
|
from importlib import import_module, reload
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from paramecio.cromosoma.databases.pymysql import SqlClass
|
from paramecio.cromosoma.databases.mysqldb import SqlClass
|
||||||
from paramecio.cromosoma.coreforms import BaseForm, HiddenForm
|
from paramecio.cromosoma.coreforms import BaseForm, HiddenForm
|
||||||
import copy
|
import copy
|
||||||
import traceback
|
import traceback
|
||||||
|
|
@ -141,9 +141,11 @@ class PhangoField:
|
||||||
def create_form(self):
|
def create_form(self):
|
||||||
#self.name, self.default_value,
|
#self.name, self.default_value,
|
||||||
|
|
||||||
self.extra_parameters.insert(0, self.name)
|
final_parameters=copy.copy(self.extra_parameters)
|
||||||
self.extra_parameters.insert(1, self.default_value)
|
|
||||||
form=self.name_form(*self.extra_parameters)
|
final_parameters.insert(0, self.name)
|
||||||
|
final_parameters.insert(1, self.default_value)
|
||||||
|
form=self.name_form(*final_parameters)
|
||||||
form.default_value=self.default_value
|
form.default_value=self.default_value
|
||||||
form.required=self.required
|
form.required=self.required
|
||||||
form.label=self.label
|
form.label=self.label
|
||||||
|
|
@ -240,9 +242,11 @@ class WebModel:
|
||||||
|
|
||||||
def __init__(self, sqlclass, name_field_id="id"):
|
def __init__(self, sqlclass, name_field_id="id"):
|
||||||
|
|
||||||
cached=self.global_cached
|
self.cached=self.global_cached
|
||||||
|
|
||||||
cached_runquery=self.global_cached
|
self.cached_runquery=self.global_cached
|
||||||
|
|
||||||
|
self.type_cache='file'
|
||||||
|
|
||||||
#The name of the table
|
#The name of the table
|
||||||
|
|
||||||
|
|
@ -347,7 +351,7 @@ class WebModel:
|
||||||
|
|
||||||
self.fields[field_model.name].model=self
|
self.fields[field_model.name].model=self
|
||||||
|
|
||||||
self.fields[field_model.name].required=required
|
#self.fields[field_model.name].required=required
|
||||||
|
|
||||||
self.fields[field_model.name].post_register()
|
self.fields[field_model.name].post_register()
|
||||||
|
|
||||||
|
|
@ -1071,6 +1075,8 @@ class WebModel:
|
||||||
|
|
||||||
def create_forms(self, arr_fields=[]):
|
def create_forms(self, arr_fields=[]):
|
||||||
|
|
||||||
|
self.forms={}
|
||||||
|
|
||||||
if len(arr_fields)==0:
|
if len(arr_fields)==0:
|
||||||
arr_fields=list(self.fields.keys())
|
arr_fields=list(self.fields.keys())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,10 @@ for k, v in menu.items():
|
||||||
def home(module='', submodule=''):
|
def home(module='', submodule=''):
|
||||||
|
|
||||||
# A simple boolean used for show or not the code of admin module in standard template
|
# A simple boolean used for show or not the code of admin module in standard template
|
||||||
|
|
||||||
connection=WebModel.connection()
|
connection=WebModel.connection()
|
||||||
|
user_admin=UserAdmin(connection)
|
||||||
|
|
||||||
#Fix, make local variable
|
#Fix, make local variable
|
||||||
|
|
||||||
t=PTemplate(env)
|
t=PTemplate(env)
|
||||||
|
|
@ -81,8 +84,6 @@ def home(module='', submodule=''):
|
||||||
|
|
||||||
#check if login
|
#check if login
|
||||||
|
|
||||||
user_admin=UserAdmin(connection)
|
|
||||||
|
|
||||||
s=get_session()
|
s=get_session()
|
||||||
|
|
||||||
if check_login():
|
if check_login():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue