def run(request, param): state, dbinfo = tools.getDBConf("DB") if not state: return tools.response(-1, dbinfo) db = tools.database(**dbinfo) db.printing = True # 执行方式 settings.LOCK.acquire() try: # ############################ 存储过程 ############################ # # 返回固定个数值 parmout = [tools.INT, tools.FLOAT] results = db.callproc("select_test1", ["fad"], parmout) print("parmout: ", parmout) # 返回结果集, 可通过parmout[i].fetchall()获取 parmout = [tools.CURSOR] results = db.callproc("select_test2", ["fad"], parmout) print("results: ", parmout) except Exception as e: print('执行sql failed! [%s]' % str(e)) settings.LOCK.release() raise settings.LOCK.release() print("return: ", results) # storage结果打包成json jsonData = tools.storage2Json(None) return tools.response(0, '', jsonData)
def run(request, param): state, dbinfo = tools.getDBConf("DB") if not state: return tools.response(-1, dbinfo) db = tools.database(**dbinfo) db.printing = True # 执行方式 settings.LOCK.acquire() try: # ############################ 结构化操作数据库 ############################ # # 结构化查询select entries1 = db.select("test", what="*", where="a='hehe'", order="d desc", limit=3) # 结构化单行插入insert entries2 = db.insert("test", a="sigal", b="n", c=0, d=10.1) # 结构化多行插入multiple_insert db.supports_multiple_insert = True values = [{ "a": "muti1", "b": "p", "c": 6, "d": 11.1 }, { "a": "muti2", "b": "q", "c": 6, "d": 11.2 }, { "a": "muti3", "b": "r", "c": 6, "d": 11.3 }] entries3 = db.multiple_insert("test", values=values) # 结构化更新update entries4 = db.update("test", where="a='fad'", b='mn', c=2) # 结构化删除delete entries5 = db.delete("test", where="a='ferry'") # ############################ 非结构化操作数据库, 可以执行复杂操作, 查询语句返回storage结果集, 其他返回影响行数 ############################ # sql = """select m.a, m.b, m.c, m.d, n.f, n.g from test m, test2 n where m.a = n.e""" entries6 = db.exec(sql) except Exception as e: print('执行sql failed! [%s]' % str(e)) settings.LOCK.release() raise settings.LOCK.release() # 结果打包成json jsonData = tools.storage2Json(entries1) return tools.response(0, '', jsonData)
def run(request, param): state, dbinfo = tools.getDBConf("DB") if not state: return tools.response(-1, dbinfo) db = tools.database(**dbinfo) db.printing = True # 执行方式 settings.LOCK.acquire() try: cursor = db._db_cursor() # ############################ 存储过程 ############################ # declare = "declare @p1 INT declare @p2 DECIMAL(10,2) declare @ret INT" exec = "exec @ret = select_test2 'fad',@p1 output,@p2 output" select = "select @p1,@p2,@ret" cursor.execute(f"%s %s %s" % (declare, exec, select)) result = cursor.fetchall() # 得到结果集 for i in result: print(i) while cursor.nextset(): result = cursor.fetchall() for i in result: print(i) except Exception as e: print('执行sql failed! [%s]' % str(e)) settings.LOCK.release() raise settings.LOCK.release() # storage结果打包成json jsonData = tools.storage2Json(None) return tools.response(0, '', jsonData)
def interface(request): name = request.path.lstrip("/") if name is None or name == "": return tools.response(-2, "the sub url is not gived! [%s]" % name) apiPath = os.path.join(settings.BASE_DIR, "api", name + ".py") print(apiPath) if not os.path.exists(apiPath) or os.path.isdir(apiPath): if not os.path.exists(apiPath + "c") or os.path.isdir(apiPath + "c"): return tools.response( -2, "the sub url is not give resolve! [%s]" % name) name = "api." + str(name).lstrip("/").replace("/", ".") lib = importlib.import_module(name) if not hasattr(lib, 'run'): return tools.response(-3, "there's no entry 'run' in [%s]" % name) parms = {} if request.method == "GET": for key in request.GET.keys(): parms[key] = request.GET.get(key) else: parms = request.body.decode("utf-8") if parms == "" or parms is None or len(parms) == 0: parms = None elif request.method == "POST": parms = json.loads(parms) if parms == "" or parms is None or len(parms) == 0: parms = None return lib.run(request, parms)
def run(request, param): addr = 'http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl' client = tools.soapClient(addr) if client is None: return tools.response(-20, 'create soap client error!') info = client.service.getMobileCodeInfo('15029228634', '') print(info) return tools.response(0, '', info)
def run(request, param): # 判断请求类型 if request.method != "POST": return tools.response(-1001, "please check!") # 解析参数 if param is None or param == "" or len(param) == 0: return tools.response(-1, "param is empty!") code, subresponse = update(**param) return tools.response(code, subresponse)
def run(request, param): # 解析参数 if param is None or param == "" or len(param) == 0: return tools.response(-1, "param is empty!") hisId = param["hisId"] if dict(param).keys().__contains__( "hisId") else None type = param["type"] if dict(param).keys().__contains__("type") else None doctorCode = param["doctorCode"] if dict(param).keys().__contains__( "doctorCode") else None # 非必要 departmentId = param["departmentId"] if dict(param).keys().__contains__( "departmentId") else None queryType = param["queryType"] if dict(param).keys().__contains__( "queryType") else None hospitalCode = param["hospitalCode"] if dict(param).keys().__contains__( "hospitalCode") else None return tools.response(0, '', param)
def run(request, param): state, dbinfo = tools.getDBConf("DB") if not state: return tools.response(-1, dbinfo) db = tools.database(**dbinfo) db.printing = True # 执行方式 settings.LOCK.acquire() try: # ############################ 结构化操作数据库 ############################ # # 结构化查询select entries1 = db.select("test", what="a,c,d", where="a='fad'", order="d desc", limit=2) # 结构化单行插入insert entries2 = db.insert("test", a="sigal", b="n", c=0, d=10.1) # print("entries2: ", entries2) # 结构化多行插入multiple_insert db.supports_multiple_insert = True values = [{"A": "muti1", "B": "p", "C": 6, "D": 11.1}, {"A": "muti2", "B": "q", "C": 6, "D": 11.2}, {"A": "muti3", "B": "r", "C": 6, "D": 11.3}] entries3 = db.multiple_insert("test", values=values) # 结构化更新update entries4 = db.update("test", where="A='fad'", B='mn', C=2) # 结构化删除delete entries5 = db.delete("test", where="A='ferry'") # ############################ 非结构化操作数据库, 可以执行复杂操作, 查询语句返回storage结果集, 其他返回影响行数 ############################ # sql = """select m.A, m.B, m.C, m.D, n.F, n.G from test m, test1 n where m.A = n.E """ sql = """INSERT INTO test(a, b, c, d) VALUES ('abc', 'n', 0, 10.1)""" entries6 = db.exec(sql) except Exception as e: print('执行sql failed! [%s]' % str(e)) settings.LOCK.release() raise settings.LOCK.release() # 结果打包成json jsonData = tools.storage2Json(entries1) return tools.response(0, '', jsonData)
def run(request, param): try: # ############################ 存储过程 ############################ # path = os.path.join(settings.BASE_DIR, "so/libmax.so") if not os.path.exists(path): return tools.response(-10, 'path not exist[%s]' % path) instance = tools.callc(path) if instance is None: return tools.response(-10, 'get instance failed!') max = instance.max(3, 4) except Exception as e: print('调用c so failed! [%s]' % str(e)) return tools.response(-10, str(e)) # storage结果打包成json jsonData = tools.storage2Json(max) return tools.response(0, '', jsonData)