本文整理匯總了Python中simplesqlite.SimpleSQLite.fetch_attr_names方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleSQLite.fetch_attr_names方法的具體用法?Python SimpleSQLite.fetch_attr_names怎麽用?Python SimpleSQLite.fetch_attr_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類simplesqlite.SimpleSQLite
的用法示例。
在下文中一共展示了SimpleSQLite.fetch_attr_names方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_normal_empty_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal_empty_header(self, tmpdir, table_name, attr_names, data_matrix, expected):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例2: test_normal_file
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal_file(
self,
tmpdir,
json_text,
filename,
table_name,
expected_table_name,
expected_attr_names,
expected_data_matrix,
):
p_db = tmpdir.join("tmp.db")
p_json = tmpdir.join(filename)
with open(str(p_json), "w") as f:
f.write(json_text)
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_json(str(p_json), table_name)
assert con.fetch_table_names() == [expected_table_name]
assert expected_attr_names == con.fetch_attr_names(expected_table_name)
result = con.select(select="*", table_name=expected_table_name)
result_matrix = result.fetchall()
assert len(result_matrix) == 3
assert result_matrix == expected_data_matrix
示例3: test_normal_number_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal_number_header(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = "numbers"
attr_names = [1, 123456789]
data_matrix = [[1, 2], [1, 2]]
expected = ["1", "123456789"]
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例4: test_normal_symbol_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal_symbol_header(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = "symbols"
attr_names = ["a!bc#d$e%f&gh(i)j", "[email protected][m]n{o}p;q:r_s.t/u"]
data_matrix = [{"ABCD>8.5": "aaa", "ABCD<8.5": 0}, {"ABCD>8.5": "bbb", "ABCD<8.5": 9}]
expected = ["a!bc#d$e%f&gh(i)j", "[email protected][m]n{o}p;q:r_s.t/u"]
con.create_table_from_data_matrix(table_name, attr_names, data_matrix)
assert con.fetch_attr_names(table_name) == expected
示例5: test_normal
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal(self, tmpdir, value, type_hints, expected):
p_db = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_tabledata(value)
assert con.fetch_table_names() == [value.table_name]
assert con.fetch_attr_names(value.table_name) == value.headers
actual = con.select_as_tabledata(
columns=value.headers, table_name=value.table_name, type_hints=type_hints
)
assert actual.value_matrix == expected
示例6: test_normal_text
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
def test_normal_text(
self,
tmpdir,
csv_text,
table_name,
attr_names,
expected_table_name,
expected_attr_names,
expected_data_matrix,
):
p_db = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p_db), "w")
con.create_table_from_csv(csv_text, table_name, attr_names)
assert con.fetch_table_names() == [expected_table_name]
assert expected_attr_names == con.fetch_attr_names(expected_table_name)
result = con.select(select="*", table_name=expected_table_name)
result_matrix = result.fetchall()
assert len(result_matrix) == 3
assert result_matrix == expected_data_matrix
示例7: open
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import fetch_attr_names [as 別名]
# create sample data file ---
with open(file_path, "w") as f:
f.write(
"""{
"table_a" : [
{"attr_b": 4, "attr_c": "a", "attr_a": 1},
{"attr_b": 2.1, "attr_c": "bb", "attr_a": 2},
{"attr_b": 120.9, "attr_c": "ccc", "attr_a": 3}
],
"table_b" : [
{"a": 1, "b": 4},
{"a": 2 },
{"a": 3, "b": 120.9}
]
}"""
)
# create table ---
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_json(file_path)
# output ---
for table_name in con.fetch_table_names():
print("table: " + table_name)
print(con.fetch_attr_names(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
print(record)
print()