本文整理匯總了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()))