You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

'''
数据库的业务
'''
import math
from Model.dbModel import dbConnect
db = dbConnect()
''' 针对请求的增删改查业务进行处理'''
'''查询业务'''
'''1.查询所有字段的值'''
def getAllData(tableName):
return db.dbQuery(sql="select * from {} order by id desc".format(tableName))
'''1.1按照指定的数量查询所有字段的值并返回'''
def getAllDataByPage(tableName,page):
return db.dbQuery(sql="select * from {} order by id desc limit {},10".format(tableName,10*page-10))
'''1.2获取共有多少页数据'''
def getAllDataPage(tableName):
totalNumbers = db.dbQuery(sql="select count(id) from {} ".format(tableName))
return math.ceil(int(totalNumbers[0][0])/10)
'''2.根据id来查询对应的值'''
def getDataByID(tableName,id):
return db.dbQuery(sql="select * from {} where id={}".format(tableName,id))[0]
'''3.根据name来查询用户对应的值'''
def getDataByName(name):
return db.dbQuery(sql="select * from user where username='{}'".format(name))[0]
'''插入数据'''
def insertData(tableName,source,ctime,title,url):
sql = "insert into {} values(null,'{}','{}','{}','{}',0)".format(tableName,source,ctime,title,url)
return db.dbManage(sql=sql)
'''删除数据'''
def delData(tableName,id):
return db.dbManage(sql="delete from {} where id={}".format(tableName,id))
'''修改数据'''
def modifyData(tableName,id,status):
return db.dbManage(sql="update {} set status={} where id={}".format(tableName,status,id))
'''魔术查询'''
def searchData(kw):
return db.dbQuery(sql="select * from news where title like '%{}%'".format(kw))
'''日志入库'''
def log2db(ctime,lineno,funname,msg):
return db.dbManage(sql="insert into dblog values(null,'{}','{}','{}','{}')".format(ctime,lineno,funname,msg))
'''测试'''
if __name__=='__main__':
# print(getDataByName('admin'))
print(log2db('111','23','app','ok'))
'''测试'''