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


Python SimpleSQLite.insert方法代碼示例

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


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

示例1: SimpleSQLite

# 需要導入模塊: from simplesqlite import SimpleSQLite [as 別名]
# 或者: from simplesqlite.SimpleSQLite import insert [as 別名]
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",
            "attr_d": 5.55,
            "attr_e": "foo",
        },
        {
開發者ID:yedan2010,項目名稱:SimpleSQLite,代碼行數:32,代碼來源:sample_insert_dict.py

示例2: SimpleSQLite

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

from __future__ import print_function

from collections import namedtuple
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]])

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():
    print(record)
開發者ID:yedan2010,項目名稱:SimpleSQLite,代碼行數:32,代碼來源:sample_insert_mix_data.py


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