當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleSQLite.create_table_with_data方法代碼示例

本文整理匯總了Python中simplesqlite.SimpleSQLite.create_table_with_data方法的典型用法代碼示例。如果您正苦於以下問題:Python SimpleSQLite.create_table_with_data方法的具體用法?Python SimpleSQLite.create_table_with_data怎麽用?Python SimpleSQLite.create_table_with_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在simplesqlite.SimpleSQLite的用法示例。


在下文中一共展示了SimpleSQLite.create_table_with_data方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_with_data [as 別名]
#!/usr/bin/env python
# encoding: utf-8


import json
from simplesqlite import SimpleSQLite
import six

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_with_data(
    table_name,
    attribute_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
    data_matrix=data_matrix)

# display values in the table -----
six.print_(con.get_attribute_name_list(table_name))
result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
    six.print_(record)

# display data type for each column in the table -----
six.print_(json.dumps(con.get_attr_type(table_name), indent=4))
開發者ID:kustomzone,項目名稱:SimpleSQLite,代碼行數:32,代碼來源:sample_create_table_nested_list.py

示例2: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_with_data [as 別名]
#!/usr/bin/env python
# encoding: utf-8


from simplesqlite import SimpleSQLite
import six


con = SimpleSQLite("sample.sqlite", "w")
con.create_table_with_data(
    table_name="hoge",
    attribute_name_list=["attr_a", "attr_b"],
    data_matrix=[[1, "a"], [2, "b"]])
six.print_(con.get_table_name_list())
開發者ID:furikake,項目名稱:SimpleSQLite,代碼行數:16,代碼來源:sample_get_table_name_list.py

示例3: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_with_data [as 別名]
#!/usr/bin/env python
# encoding: utf-8


from simplesqlite import SimpleSQLite
import six


con = SimpleSQLite("sample.sqlite", "w", profile=True)
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_with_data(
    table_name="sample_table",
    attribute_name_list=["a", "b", "c", "d", "e"],
    data_matrix=data_matrix,
    index_attribute_list=["a"])

for profile in con.get_profile():
    six.print_(profile)
開發者ID:furikake,項目名稱:SimpleSQLite,代碼行數:24,代碼來源:sample_get_profile.py

示例4: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_with_data [as 別名]
#!/usr/bin/env python
# encoding: utf-8


from collections import namedtuple
from simplesqlite import SimpleSQLite
import six


table_name = "sample_table"
con = SimpleSQLite("sample.sqlite", "w")
con.create_table_with_data(
    table_name,
    attribute_name_list=["attr_a", "attr_b", "attr_c", "attr_d", "attr_e"],
    data_matrix=[[1, 1.1, "aaa", 1,   1]])

SampleTuple = namedtuple(
    "SampleTuple", "attr_a attr_b attr_c attr_d attr_e")

con.insert(table_name, insert_record=[7, 7.7, "fff", 7.77, "bar"])
con.insert_many(
    table_name,
    insert_record_list=[
        (8, 8.8, "ggg", 8.88, "foobar"),
        SampleTuple(9, 9.9, "ggg", 9.99, "hogehoge"),
    ]
)

result = con.select(select="*", table_name=table_name)
for record in result.fetchall():
    six.print_(record)
開發者ID:furikake,項目名稱:SimpleSQLite,代碼行數:33,代碼來源:sample_insert_mix_data.py

示例5: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import create_table_with_data [as 別名]

from simplesqlite import SimpleSQLite
from simplesqlite.sqlquery import SqlQuery
import six


table_name = "sample_table"
con = SimpleSQLite("sample.sqlite", "w")

data_matrix = [
    [1, "aaa"],
    [2, "bbb"],
]
con.create_table_with_data(
    table_name,
    attribute_name_list=["key", "value"],
    data_matrix=data_matrix)

six.print_("---- before update ----")
for record in con.select(select="*", table_name=table_name).fetchall():
    six.print_(record)
six.print_()

con.update(
    table_name,
    set_query="value = 'ccc'",
    where=SqlQuery.make_where(key="key", value=1))

six.print_("---- after update ----")
for record in con.select(select="*", table_name=table_name).fetchall():
    six.print_(record)
開發者ID:furikake,項目名稱:SimpleSQLite,代碼行數:33,代碼來源:sample_update.py


注:本文中的simplesqlite.SimpleSQLite.create_table_with_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。