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