Sindbad~EG File Manager

Current Path : /home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/
Upload File :
Current File : //home/numerotech/test-membership.numerotech.com/CommonMembershipApp/core/model/Users.py

from sqlalchemy import create_engine, MetaData, Table, insert, null, select,update,delete,text
from sqlalchemy.sql import and_, or_
from sqlalchemy import asc, desc
from core import app
import json
from .. import engine


class Users():
	def __init__(self):
		try:
			self.meta       = MetaData()
			self.users      = Table("users", self.meta, autoload_with=engine)
		   
		except Exception as e:
			print(e)

	def insert_member(self,data):
		with engine.connect() as conn:
			result = conn.execute(self.users.insert(), data)
			conn.commit()
			pk_id = result.inserted_primary_key[0] if result.inserted_primary_key[0] else None
			return pk_id
		
	def get_member(self,user_id):
		with engine.connect() as conn:
			stmt = select(self.users).where(self.users.c.user_id.in_([user_id]))
			result = conn.execute(stmt).first()
			return result
			
	def get_member_old_user_id(self,old_user_id,society_id):
		with engine.connect() as conn:  
			stmt = select(self.users).where(self.users.c.old_user_id.in_([old_user_id])).where(self.users.c.society_id.in_([society_id]))
			return conn.execute(stmt).first()
			
	def get_autologin_data(self,user_uuid):
		with engine.connect() as conn:     
			stmt = text("select * from users u inner join societies s on s.society_id=u.society_id where u.user_uuid=:user_uuid")
			result = conn.execute(stmt.bindparams(user_uuid=user_uuid)).first()
			if result :
				return dict(result._mapping)
			else:
				return None  

	def get_user_uuid_data(self,user_uuid):
		with engine.connect() as conn:        
			stmt = select(self.users).where(self.users.c.user_uuid.in_([user_uuid]))
			return conn.execute(stmt).first()
			
	def update_member(self,user_id,datas):
		with engine.connect() as conn:    
			stmt = self.users.update().where(self.users.c.user_id.in_([user_id])).values(datas)
			result = conn.execute(stmt)
			conn.commit()
			return result
		
	def search_data(self,search_data,society_id):
		with engine.connect() as conn:
			if society_id == 1:
				stmt = text("SELECT * from users WHERE (full_name LIKE '%"+search_data+"%' OR email LIKE '%"+search_data+"%' OR mobile LIKE '%"+search_data+"%' OR membership_no LIKE '%"+search_data+"%' OR city LIKE '%"+search_data+"%') and member_type_id=1  and society_id=:society_id;")
				# stmt = text("SELECT * from users WHERE (full_name LIKE '%{}%' OR email LIKE '%{}%' OR mobile LIKE '%{}%' OR membership_no LIKE '%{}%' OR city LIKE '%{}%') and member_type_id=1 and society_id=:society_id".format(search_data,search_data,search_data,search_data,search_data))
				
			else:
				stmt = text("SELECT * from users WHERE (full_name LIKE '%"+search_data+"%' OR email LIKE '%"+search_data+"%' OR mobile LIKE '%"+search_data+"%' OR membership_no LIKE '%"+search_data+"%' OR city LIKE '%"+search_data+"%') and member_type_id=1 and society_id=:society_id and is_prosec=1;")
				# stmt = text("SELECT * from users WHERE (full_name LIKE '%{}%' OR email LIKE '%{}%' OR mobile LIKE '%{}%' OR membership_no LIKE '%{}%' OR city LIKE '%{}%') and member_type_id=1 and society_id=:society_id and is_prosec=1".format(search_data,search_data,search_data,search_data,search_data))
				
			results = conn.execute(stmt.bindparams(society_id=society_id)).all()
			return [dict(r._mapping) for r in results] if results else None
			
	def check_email(self,email,society_id):
		with engine.connect() as conn:
			stmt = self.users.select().where(self.users.c.email.in_([email])).where(self.users.c.society_id.in_([society_id]))
			return conn.execute(stmt).first()

	def check_mobile(self,user_id,mobile,society_id):
		with engine.connect() as conn:
			stmt = text("select * from users where user_id <> :user_id and (mobile= :mobile or whatsapp_number=:mobile) and society_id=:society_id;")
			result = conn.execute(stmt.bindparams(user_id=user_id,mobile=mobile,society_id=society_id))
			return result.first()

	def check_whatsapp(self,user_id,whatsapp_number,society_id):
		with engine.connect() as conn:
			stmt = text("select * from users where user_id <> :user_id and (mobile= :whatsapp_number or whatsapp_number=:whatsapp_number) and society_id=:society_id;")
			result = conn.execute(stmt.bindparams(user_id=user_id,whatsapp_number=whatsapp_number,society_id=society_id))
			return result.first()
			
	def check_membership_no(self,user_id,membership_no,society_id):
		with engine.connect() as conn:
			stmt = text("select * from users where user_id <> :user_id and  membership_no=:membership_no and society_id=:society_id ;")
			result = conn.execute(stmt.bindparams(user_id=user_id,membership_no=membership_no,society_id=society_id))
			return result.first()

	def check_email_password(self,email,password,is_admin,society_id):
		with engine.connect() as conn:
			stmt = text("select * from users where email=:email and password=:password  and society_id=:society_id")
			result = conn.execute(stmt.bindparams(email=email,password=password,society_id=society_id))
			results = result.first()
			if results :
				return dict(results._mapping)
			else:
				return None 
			
			
	def count_mobile_num(self,user_id,mobile,society_id):
		with engine.connect() as conn:
			stmt = text("select case when prefix is not null then concat(prefix,full_name) else full_name END as full_name,email,count(*) from users where user_id <>{} and (mobile={} or whatsapp_number={}) and society_id={};".format(user_id,mobile,mobile,society_id))
			result = conn.execute(stmt)
			return result.first()
			

	def count_whatsapp_num(self,user_id,whatsapp_number,society_id):
		with engine.connect() as conn:
			stmt = text("select case when prefix is not null then concat(prefix,full_name) else full_name END as full_name,email, count(*) from users where user_id <>{} and (mobile= {} or whatsapp_number={}) and society_id={};".format(user_id,whatsapp_number,whatsapp_number,society_id))
			result = conn.execute(stmt)
			return result.first()

		# THE BELOW FUCNTION ADDED FOR VERIFY OTP
	def getUserByID(self,user_id):
		with engine.connect() as conn:
			stmt = text("select * from users where  user_id= :user_id;")
			result = conn.execute(stmt.bindparams(user_id=user_id)).first()
			if result :
				return dict(result._mapping)
			else:
				return None
	
	def get_prosec_name(self,user_id):
		with engine.connect() as conn:
			stmt = text("select full_name,prefix,mobile,user_uuid from users where user_id= :user_id;")
			result = conn.execute(stmt.bindparams(user_id=user_id)).first()
			return result
	
	def get_already_pro_sec(self,user_id,ps_type):
		with engine.connect() as conn:
			stmt = text("select reference_id,rs.user_id,us.user_uuid as refer_uuid,us.prefix,us.full_name,us.membership_no,us.email,us.mobile,us.city,type,reference_by,approved_on,rejected_on, u.user_uuid,u.status_id from reference rs inner join users us on us.user_id=rs.reference_by inner join users u on u.user_id = rs.user_id where  rs.user_id=:user_id and type=:ps_type;")
			results = conn.execute(stmt.bindparams(user_id=user_id,ps_type=ps_type)).all()
			return  [dict(r._mapping) for r in results] if results else None

	def get_changes_pro_sec(self,user_id,ps_type):
		with engine.connect() as conn:
			stmt = text("select  reference_id,rs.user_id,prefix,full_name,membership_no,email,mobile,city,type,reference_by,user_uuid from users  as us inner join reference as rs on us.user_id=rs.reference_by where  rs.user_id=:user_id and type=:ps_type;")
			result = conn.execute(stmt.bindparams(user_id=user_id,ps_type=ps_type)).first()
			if result :
				return dict(result._mapping)
			else:
				return None 

	# join query
	def get_view_pro_sec(self,user_id):
		with engine.connect() as conn:
			stmt = text("select  reference_id,rs.user_id as user_id,prefix,full_name,membership_no,email,mobile,city,type,reference_by from users  as us inner join reference as rs on us.user_id=rs.reference_by where  rs.user_id= :user_id;")
			results = conn.execute(stmt.bindparams(user_id=user_id)).all()
			return  [dict(r._mapping) for r in results] if results else None

	def get_api_data(self,email,society_id):
		with engine.connect() as conn:   
			stmt = select(self.users).where(self.users.c.email.in_([email])).where(self.users.c.society_id.in_([society_id]))    
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None  

	def get_reminder_incomplete_data(self,currentDate):
		with engine.connect() as conn: 
			stmt = text("select u.*,society_key from users u left join societies s on u.society_id=s.society_id where u.status_id between 1 and 9 and date(u.updated_at) =:currentDate")     
			results = conn.execute(stmt.bindparams(currentDate=currentDate)).all()
			results =  [dict(r._mapping) for r in results] if results else None
			if results :
				return results
			else:
				return None  

	def usp_search_prosec(self,searchData,is_prosec,society_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_search_prosec",[searchData,is_prosec,society_id])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			return None

	def AllUserData(self,user_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_user_all_data",[user_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	
	
	def usp_generate_membership_number(self,user_id,member_type_id,society_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_generate_membership_number",[user_id,member_type_id,society_id])
		columns     = [column[0] for column in cursor.description]
		results     = []
		for row in cursor.fetchall():
			results.append(dict(zip(columns, row)))
		cursor.close()
		connection.commit()
		if results :
			return results
		else :
			cursor.close()
			connection.commit()
			return None 
	
	def usp_get_members(self,search_name,search_email,search_mobile,status_id,offset,limit,user_id,search_member_type,from_memno,end_memno,approved_from,approved_to,society_id,sort_by,order_type):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_members_v1",[search_name,search_email,search_mobile,status_id,offset,limit,user_id,search_member_type,from_memno,end_memno,approved_from,approved_to,society_id,sort_by,order_type])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	

	def usp_get_incomplete_member(self,search_name,search_email,search_mobile,status_id,offset,limit,user_id,society_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_incomplete_member",[search_name,search_email,search_mobile,status_id,offset,limit,user_id,society_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	

	def usp_approved_mail_data(self,user_id,society_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_approved_mail_data",[user_id,society_id])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			return None

	def usp_data_for_dashboard(self,user_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_data_for_dashboard",[user_id])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			return None
	
	def get_member_by_city_district(self,society_id):
		with engine.connect() as conn:
			stmt = text("select u.user_id,u.membership_no,CASE WHEN u.prefix is not null then concat(u.prefix,u.full_name) else u.full_name END as full_name,u.email,u.mobile,u.city,u.district,u.profile_updated_at from users u where society_id=:society_id and status_id=14 order by membership_no_only asc;")
			results = conn.execute(stmt.bindparams(society_id=society_id)).all()
			return  [dict(r._mapping) for r in results] if results else None

	def usp_district_list(self,society_id,val):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_district_list",[society_id,val])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets

	def usp_district_list_mos(self,society_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_district_list_mos",[society_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	

	def usp_data_for_district_wise(self,society_id,district,val):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_data_for_district_wise",[society_id,district,val])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets

	def get_dynamic_columns(self,society_id):
		with engine.connect() as conn: 
			stmt 	= text("select * from dynamic_columns where FIND_IN_SET (:society_id,society_ids)  and is_visible =1;")
			result 	= conn.execute(stmt.bindparams(society_id=society_id)).all()
			return [dict(r._mapping) for r in result] if result else None
			
	def get_data_for_idcard(self,user_id,attach_type_id):
		with engine.connect() as conn: 
			stmt = text("select * from users u left join states s on u.state_id=s.state_id left join user_attachments ua on ua.user_id= u.user_id and attach_type_id="+ str(attach_type_id)  +" where u.user_id="+ str(user_id)  +";")      
			result = conn.execute(stmt).first()
			if result :
				return dict(result._mapping)
			else:
				return None
			
	def usp_get_mem_daily_count(self,society_id,dt):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_get_mem_daily_count",[society_id,dt])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			return None
			
	def usp_get_mem_daily_count_v1(self,dt):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_get_mem_daily_count_v1",[dt])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets
			
	def usp_user_all_data_v1(self,user_id):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_user_all_data_v1",[user_id])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	
		
	def get_member_by_society(self,society_id):
		with engine.connect() as conn:
			stmt = text("select profile_validate_from from societies where society_id = {}".format(society_id))
			results = conn.execute(stmt).first()
			result =  dict(results._mapping) if results else None
			if result and result['profile_validate_from']:

				stmt_1 = text("select u.user_id,u.membership_no,CASE WHEN u.prefix is not null then concat(u.prefix,u.full_name) else u.full_name END as full_name,u.email,u.mobile,u.city,u.district,u.profile_updated_at from users u where society_id={} and status_id=14 and  (date(profile_updated_at) < '{}'  or profile_updated_at is null) and email is not null order by membership_no_only asc;".format(society_id,result['profile_validate_from']))
			else:
				stmt_1 = text("select u.user_id,u.membership_no,CASE WHEN u.prefix is not null then concat(u.prefix,u.full_name) else u.full_name END as full_name,u.email,u.mobile,u.city,u.district,u.profile_updated_at from users u where society_id={} and status_id=14  and email is not null order by membership_no_only asc;".format(society_id))

			results_1 = conn.execute(stmt_1).all()
			return  [dict(r._mapping) for r in results_1] if results_1 else None
			
	def get_receipt_data(self,society_id):
		with engine.connect() as conn:
			stmt = text("select u.user_id,membership_no_only,membership_no,concat(u.prefix,u.full_name) as full_name,u.email,u.mobile,paid_at,amount,payment_method,utr_number,attach_path,attach_file_name from user_payment up inner join users u on u.user_id=up.user_id inner join user_attachments ua on ua.user_id=u.user_id and attach_type_id=6 where u.society_id=:society_id and status_id=14 and app_type='MEMBERSHIP'  and status='success' and date(paid_at) between '2022-04-01' and '2023-03-31' order by paid_at")
			results = conn.execute(stmt.bindparams(society_id=society_id)).all()
			return  [dict(r._mapping) for r in results] if results else None
			
	def usp_generate_ratification(self,ratified_year,society_id,from_membership_no,to_membership_no,is_ratification):
		sets = []
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_generate_ratification",[ratified_year,society_id,from_membership_no,to_membership_no,is_ratification])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			connection.commit()
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets
		
	def check_bo_access(self,email,app_type_id,society_id,conf_id):
		connection = engine.raw_connection()
		cursor = connection.cursor()
		cursor.callproc("usp_check_admin_access",[email,app_type_id,society_id,conf_id])
		columns = [column[0] for column in cursor.description]
		results = []
		for row in cursor.fetchall():
			results.append(dict(zip(columns, row)))
		cursor.close()
		connection.commit()
		if results :
			return results[0]
		else :
			return None
	
	def get_member_by_notproof(self,society_id):
		with engine.connect() as conn:
			stmt = text("select profile_validate_from from societies where society_id = {}".format(society_id))
			results = conn.execute(stmt).first()
			result =  dict(results._mapping) if results else None
			if result and result['profile_validate_from']:

				stmt_1 = text("select u.user_id,u.membership_no,CASE WHEN u.prefix is not null then concat(u.prefix,u.full_name) else u.full_name END as full_name,u.email,u.mobile,u.city,u.district,u.profile_updated_at from users u where society_id={} and status_id=14 and  date(profile_updated_at) >= '{}' and (gov_proof_type is   null  or email is  null or full_name is  null or mobile is  null or whatsapp_number is  null or gender is null or dob is  null or mc_number is  null or mc_state_id is  null or address1 is  null or city is  null or district is  null or country_id is  null or state_id is  null)  and email is not null order by membership_no_only asc;".format(society_id,result['profile_validate_from']))
# 			else:
# 				stmt_1 = text("select u.user_id,u.membership_no,CASE WHEN u.prefix is not null then concat(u.prefix,u.full_name) else u.full_name END as full_name,u.email,u.mobile,u.city,u.district,u.profile_updated_at from users u where society_id={} and status_id=14 and  profile_updated_at is not null   and email is not null order by membership_no_only asc;".format(society_id,r['profile_validate_from']))

			results_1 = conn.execute(stmt_1).all()
			return  [dict(r._mapping) for r in results_1] if results_1 else None
	
	def get_associate_member_data(self,society_id,member_type_id,user_id):
		with engine.connect() as conn:
			stmt = text("SELECT * FROM users u  inner join temp_mos_associate_member ta ON u.user_id = ta.user_id  WHERE  u.society_id = {} and  u.member_type_id in ({}) and u.user_id in ({}) ".format(society_id,member_type_id,user_id))
			result = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			return results
	
	def usp_search_all_members(self,searchData,society_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_search_all_members",[searchData,society_id])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			if results :
				return results
			else :
				return None 
		else :
			cursor.close()
			connection.commit()
			return None
			
	def usp_mem_converting_assmem_lifemem(self,society_id,member_type_id,attach_type_id,status_id,offset,limit):
		sets = []
		print(society_id,member_type_id,attach_type_id,status_id,offset,limit)
		try:
			connection = engine.raw_connection()
			cursor = connection.cursor()
			cursor.callproc("usp_mem_converting_assmem_lifemem",[society_id,member_type_id,attach_type_id,status_id,offset,limit])
			while 1:
				#(column_name, type_, ignore_, ignore_, ignore_, null_ok, column_flags)
				names = [c[0] for c in cursor.description]
				set_ = []
				while 1:
					row_raw = cursor.fetchone()
					if row_raw is None:
						break
						
					row = dict(zip(names, row_raw))
					set_.append(row)
	 
				sets.append(list(set_))
	 
				if cursor.nextset() is None:
					break
	 
				# nextset() doesn't seem to be sufficiant to tell the end.
				if cursor.description is None:
					break
		finally:
			# Return the connection to the pool (won't actually close).
			connection.close()
			
		return sets	

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists