当前位置: 首页>>代码示例>>Python>>正文


Python Db.insert方法代码示例

本文整理汇总了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)

开发者ID:mlen1990,项目名称:Coding-Challenges,代码行数:31,代码来源:main.py

示例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) 
开发者ID:azeemshaikh38,项目名称:CloverHealth,代码行数:23,代码来源:cli.py


注:本文中的Db.Db.insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。