本文整理汇总了Python中Db.Db.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Db.insert方法的具体用法?Python Db.insert怎么用?Python Db.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db.Db
的用法示例。
在下文中一共展示了Db.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import insert [as 别名]
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)
for spec_filename in spec_files:
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 = []
create_table_sql = "CREATE TABLE " + filename_info[0] + "(id INT NOT NULL AUTO_INCREMENT"
for column in file:
create_table_sql += ", {} {}".format(column[0], column[2])
columns.append({"name": column[0], "width": int(column[1]), "data_type": column[2]})
create_table_sql += ", PRIMARY KEY (id));"
db.execute(create_table_sql);
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 = "INSERT INTO " + filename_info[0] + " SET "
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 += ", ".join(fields)
db.insert(sql)
示例2: Db
# 需要导入模块: from Db import Db [as 别名]
# 或者: from Db.Db import insert [as 别名]
import os
from FileNames import FileNames
from FormatFile import FormatFile
from DataFile import DataFile
from Query import Query
from Db import Db
dataFolder = "data"
specFolder = "specs"
db = Db()
q = Query()
for filename in os.listdir(dataFolder):
name = FileNames(filename)
spec = FormatFile(specFolder+"/"+name.specFileName)
data = DataFile(dataFolder+"/"+filename, spec.getFormat())
for row in data.getData():
query, params = q.insert_query(name.tableName, spec.getCols(), row)
print(query, params)
db.insert(query, params)