下面这段代码和使用 ORM 操作有啥区别?
class DbCommonLibaray(object):
def executeQuery(self, sql):
cursor = connection.cursor() # 获得一个游标(cursor)对象
cursor.execute(sql)
rawData = cursor.fetchall()
col_names = [desc[0] for desc in cursor.description]
result = []
for row in rawData:
objDict = {}
# 把每一行的数据遍历出来放到 Dict 中
for index, value in enumerate(row):
objDict[col_names[index]] = value
result.append(objDict)
return result
def GetDTByPage(tableName, conditions, orderby, selectField="*", pageIndex=1, pageSize=20):
if not selectField:
selectField = "*"
if conditions:
conditions = "WHERE " + conditions
sqlStart = str((pageIndex - 1) * pageSize)
sqlEnd = str(pageIndex * pageSize)
sqlQuery = "SELECT " + str(selectField) + " FROM " + tableName + " " + str(conditions) + " ORDER BY " + str(
orderby) + " LIMIT " + str(sqlStart) + ", " + str(sqlEnd)
returnValue = DbCommonLibaray.executeQuery(None, sqlQuery)
return returnValue
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.