本文整理汇总了Python中Db.Db.select方法的典型用法代码示例。如果您正苦于以下问题:Python Db.select方法的具体用法?Python Db.select怎么用?Python Db.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db.Db
的用法示例。
在下文中一共展示了Db.select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import select [as 别名]
def test(self, spec_filename):
function_map = {
"TEXT": str,
"INTEGER": int,
"BOOLEAN": int,
"DATE": str
}
properties = Properties.getProperties()
db = Db(properties)
data_files = os.listdir("data")
file_map = {}
for data_file in data_files:
file_info = data_file.split("_")
if not file_info[0] in file_map:
file_map[file_info[0]] = []
file_map[file_info[0]].append(data_file)
with open("specs/" + spec_filename, "rt") as spec_file:
filename_info = spec_filename.split(".")
file = csv.reader(spec_file, delimiter=",")
next(file) # Skip first row
columns = []
for column in file:
columns.append({"name": column[0], "width": int(column[1]), "data_type": column[2]})
if filename_info[0] in file_map:
for data_filename in file_map[filename_info[0]]:
with open("data/" + data_filename, "rt") as data_file:
for line in data_file:
sql = "SELECT count(*) as total FROM {} WHERE ".format(filename_info[0])
index = 0
fields = []
for column in columns:
fields.append(column["name"] + " = '" + str(function_map[column["data_type"]](line[index:(index + column["width"])])) + "'")
index += column["width"]
sql += " AND ".join(fields)
row = db.select(sql)[0]
if row["total"] != 1:
raise Exception("Line: {} was not inserted".format(line.strip()))