本文整理汇总了Python中simplesqlite.SimpleSQLite.select_as_tabledata方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleSQLite.select_as_tabledata方法的具体用法?Python SimpleSQLite.select_as_tabledata怎么用?Python SimpleSQLite.select_as_tabledata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simplesqlite.SimpleSQLite
的用法示例。
在下文中一共展示了SimpleSQLite.select_as_tabledata方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_normal_add_primary_key_column
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal_add_primary_key_column(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = "table1"
con.create_table_from_data_matrix(
table_name=table_name,
attr_names=["AA", "BB"],
data_matrix=[["a", 11], ["bb", 12]],
add_primary_key_column=True,
)
assert con.select_as_tabledata(table_name) == TableData(
table_name=table_name, headers=["id", "AA", "BB"], rows=[[1, "a", 11], [2, "bb", 12]]
)
assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "id"
table_name = "table2"
con.create_table_from_data_matrix(
table_name=table_name,
attr_names=["AA", "BB"],
data_matrix=[["a", 11], ["bb", 12]],
primary_key="pkey",
add_primary_key_column=True,
)
assert con.select_as_tabledata(table_name) == TableData(
table_name=table_name, headers=["pkey", "AA", "BB"], rows=[[1, "a", 11], [2, "bb", 12]]
)
assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "pkey"
示例2: test_normal_type_hint_header
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal_type_hint_header(self):
url = "https://example.com/type_hint_header.csv"
responses.add(
responses.GET,
url,
body=dedent(
"""\
"a text","b integer","c real"
1,"1","1.1"
2,"2","1.2"
3,"3","1.3"
"""
),
content_type="text/plain; charset=utf-8",
status=200,
)
runner = CliRunner()
with runner.isolated_filesystem():
result = runner.invoke(cmd, ["--type-hint-header", "-o", self.db_path, "url", url])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(self.db_path, "r")
table_names = list(set(con.fetch_table_names()) - set([SourceInfo.get_table_name()]))
# table name may change test execution order
tbldata = con.select_as_tabledata(table_names[0])
assert tbldata.headers == ["a text", "b integer", "c real"]
assert tbldata.rows == [("1", 1, 1.1), ("2", 2, 1.2), ("3", 3, 1.3)]
示例3: test_normal_no_type_inference
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal_no_type_inference(self):
runner = CliRunner()
basename = "no_type_inference"
file_path = "{}.csv".format(basename)
db_path = "{}.sqlite".format(basename)
with runner.isolated_filesystem():
with open(file_path, "w") as f:
f.write(
dedent(
"""\
"a","b"
11,"xyz"
22,"abc"
"""
)
)
f.flush()
result = runner.invoke(cmd, ["--no-type-inference", "-o", db_path, "file", file_path])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
tbldata = con.select_as_tabledata(basename)
assert tbldata.headers == ["a", "b"]
assert tbldata.rows == [("11", "xyz"), ("22", "abc")]
示例4: test_normal_type_hint_header
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal_type_hint_header(self):
runner = CliRunner()
basename = "type_hint_header"
file_path = "{}.csv".format(basename)
db_path = "{}.sqlite".format(basename)
with runner.isolated_filesystem():
with open(file_path, "w") as f:
f.write(
dedent(
"""\
"a text","b integer","c real"
1,"1","1.1"
2,"2","1.2"
3,"3","1.3"
"""
)
)
f.flush()
result = runner.invoke(cmd, ["--type-hint-header", "-o", db_path, "file", file_path])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
tbldata = con.select_as_tabledata(basename)
assert tbldata.headers == ["a text", "b integer", "c real"]
assert tbldata.rows == [("1", 1, 1.1), ("2", 2, 1.2), ("3", 3, 1.3)]
示例5: test_normal
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal(self, con, tmpdir):
dump_path = str(tmpdir.join("dump.db"))
con.dump(dump_path)
con_dump = SimpleSQLite(dump_path, "r")
assert con.fetch_num_records(TEST_TABLE_NAME) == con_dump.fetch_num_records(TEST_TABLE_NAME)
assert con.select_as_tabledata(TEST_TABLE_NAME) == con_dump.select_as_tabledata(
TEST_TABLE_NAME
)
示例6: test_normal_format_ssv
# 需要导入模块: from simplesqlite import SimpleSQLite [as 别名]
# 或者: from simplesqlite.SimpleSQLite import select_as_tabledata [as 别名]
def test_normal_format_ssv(self):
db_path = "test_ssv.sqlite"
runner = CliRunner()
with runner.isolated_filesystem():
file_path = valid_ssv_file()
result = runner.invoke(cmd, ["-o", db_path, "file", file_path, "--format", "ssv"])
print_traceback(result)
assert result.exit_code == ExitCode.SUCCESS
con = SimpleSQLite(db_path, "r")
data = con.select_as_tabledata(table_name="ssv")
expected = (
"table_name=ssv, "
"headers=[USER, PID, %CPU, %MEM, VSZ, RSS, TTY, STAT, START, TIME, COMMAND], "
"cols=11, rows=5"
)
assert str(data) == expected