本文整理汇总了Python中models.DBSession.connection方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.connection方法的具体用法?Python DBSession.connection怎么用?Python DBSession.connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.DBSession
的用法示例。
在下文中一共展示了DBSession.connection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getUserInfo
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import connection [as 别名]
def getUserInfo(userid):
mySession = DBSession()
sql = "SELECT user_fullname, user_organization, user_email, user_about,lkpcountry.cnty_name,lkpsector.sector_name FROM " \
"user,lkpcountry,lkpsector WHERE user_cnty = lkpcountry.cnty_cod AND user_sector = lkpsector.sector_cod AND user_name = " + "'" + userid + "'"
connection = mySession.connection()
results = connection.execute(sql)
userInfo = {}
for result in results:
userInfo["user_fullname"] = result[0];
userInfo["user_organization"] = result[1];
userInfo["user_email"] = result[2];
userInfo["user_about"] = result[3];
userInfo["cnty_name"] = result[4];
userInfo["sector_name"] = result[5];
connection.close()
mySession.close()
return userInfo
示例2: getUserLog
# 需要导入模块: from models import DBSession [as 别名]
# 或者: from models.DBSession import connection [as 别名]
def getUserLog(user,limit = True):
sql = "SELECT DATE_FORMAT(DATE(log_datetime), '%%W %%D %%M %%Y') as log_date,TIME(log_datetime) as log_time,log_type,log_message,log_datetime as date1,log_datetime as date2 FROM activitylog WHERE log_user = '" + user + "' ORDER BY date1 DESC,date2 ASC,log_id desc"
if limit:
sql = sql + " LIMIT 20"
mySession = DBSession()
connection = mySession.connection()
activities = connection.execute(sql)
items = []
count = 1
for activity in activities:
if count%2 == 0:
alt = False
else:
alt= True
count = count + 1
if activity[2] == "PRF":
color = "terques"
icon = "fa-user"
else:
if activity[2] == "MOD":
color = "purple"
icon = "fa-gears"
else:
if activity[2] == "FED":
color = "blue"
icon = "fa-leaf"
else:
if activity[2] == "API":
color = "green"
icon = "fa-bolt"
else:
color = "red"
icon = "fa-bullhorn"
items.append({"date":activity[0],"time":activity[1],"type":activity[2],"message":activity[3],"alt":alt,"icon":icon,"color":color})
connection.close()
mySession.close()
return items