本文整理匯總了Python中simplesqlite.SimpleSQLite.create_table_from_data_matrix方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleSQLite.create_table_from_data_matrix方法的具體用法?Python SimpleSQLite.create_table_from_data_matrix怎麽用?Python SimpleSQLite.create_table_from_data_matrix使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類simplesqlite.SimpleSQLite
的用法示例。
在下文中一共展示了SimpleSQLite.create_table_from_data_matrix方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: con
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def con(tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
return con
示例2: test_normal_empty_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [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
示例3: test_normal_add_primary_key_column
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [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"
示例4: con_profile
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def con_profile(tmpdir):
p = tmpdir.join("tmp_profile.db")
con = SimpleSQLite(str(p), "w", profile=True)
con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
con.commit()
return con
示例5: con_ro
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def con_ro(tmpdir):
p = tmpdir.join("tmp_readonly.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(TEST_TABLE_NAME, ["attr_a", "attr_b"], [[1, 2], [3, 4]])
con.close()
con.connect(str(p), "r")
return con
示例6: con_mix
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def con_mix(tmpdir):
p = tmpdir.join("tmp_mixed_data.db")
con = SimpleSQLite(str(p), "w")
con.create_table_from_data_matrix(
TEST_TABLE_NAME, ["attr_i", "attr_f", "attr_s"], [[1, 2.2, "aa"], [3, 4.4, "bb"]]
)
return con
示例7: test_normal_primary_key
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def test_normal_primary_key(self, tmpdir, table_name, attr_names, data_matrix, expected):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = TEST_TABLE_NAME
con.create_table_from_data_matrix(
table_name, attr_names, data_matrix, primary_key=attr_names[0]
)
assert con.schema_extractor.fetch_table_schema(table_name).primary_key == "AA"
示例8: test_normal_symbol_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [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
示例9: test_normal_number_header
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [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
示例10: test_except_add_primary_key_column
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def test_except_add_primary_key_column(self, tmpdir):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
with pytest.raises(ValueError):
con.create_table_from_data_matrix(
table_name="specify existing attr as a primary key",
attr_names=["AA", "BB"],
data_matrix=[["a", 11], ["bb", 12]],
primary_key="AA",
add_primary_key_column=True,
)
示例11: test_normal
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
def test_normal(self, tmpdir, attr_names, data_matrix, index_attrs, expected_attr):
p = tmpdir.join("tmp.db")
con = SimpleSQLite(str(p), "w")
table_name = TEST_TABLE_NAME
con.create_table_from_data_matrix(
table_name, attr_names, data_matrix, primary_key=None, index_attrs=index_attrs
)
# check data ---
result = con.select(select=AttrList(attr_names), table_name=table_name)
result_matrix = result.fetchall()
assert len(result_matrix) == 3
print_test_result(expected=expected_attr, actual=con.fetch_attr_type(table_name))
assert con.fetch_attr_type(table_name) == expected_attr
示例12: SimpleSQLite
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
from simplesqlite import SimpleSQLite
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_data_matrix(
table_name="hoge",
attr_name_list=["attr_a", "attr_b"],
data_matrix=[[1, "a"], [2, "b"]])
print(con.has_table("hoge"))
print(con.has_table("not_existing"))
示例13: SimpleSQLite
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
# encoding: utf-8
from __future__ import print_function
import json
from simplesqlite import SimpleSQLite
table_name = "sample_table"
con = SimpleSQLite("sample.sqlite", "w")
# create table -----
data_matrix = [
[1, 1.1, "aaa", 1, 1],
[2, 2.2, "bbb", 2.2, 2.2],
[3, 3.3, "ccc", 3, "ccc"],
]
con.create_table_from_data_matrix(
table_name,
attr_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
data_matrix=data_matrix)
# display values in the table -----
print(con.get_attr_name_list(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
print(record)
# display data type for each column in the table -----
print(json.dumps(con.get_attr_type(table_name), indent=4))
示例14: SimpleSQLite
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
import json
from simplesqlite import SimpleSQLite
con = SimpleSQLite("sample.sqlite", "w")
data_matrix = [[1, 1.1, "aaa", 1, 1], [2, 2.2, "bbb", 2.2, 2.2], [3, 3.3, "ccc", 3, "ccc"]]
con.create_table_from_data_matrix(
"sample_table", ["a", "b", "c", "d", "e"], data_matrix, index_attrs=["a"]
)
print(json.dumps(con.fetch_sqlite_master(), indent=4))
示例15: SimpleSQLite
# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_from_data_matrix [as 別名]
#!/usr/bin/env python
# encoding: utf-8
from __future__ import print_function
from simplesqlite import SimpleSQLite
table_name = "sample_table"
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_from_data_matrix(
table_name,
attr_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
data_matrix=[[1, 1.1, "aaa", 1, 1]])
con.insert(
table_name,
insert_record={
"attr_a": 4,
"attr_b": 4.4,
"attr_c": "ddd",
"attr_d": 4.44,
"attr_e": "hoge",
})
con.insert_many(
table_name,
insert_record_list=[
{
"attr_a": 5,
"attr_b": 5.5,
"attr_c": "eee",