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


Python sqlite3.Connection方法代碼示例

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


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

示例1: _DetectApplicationUsageTable

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def _DetectApplicationUsageTable(self, conn):
    """Detect whether the application usage table exists.

    Args:
      conn: sqlite3.Connection object
    Returns:
      True if the table exists, False if not.
    Raises:
      sqlite3.Error: if error occurs
    """
    try:
      conn.execute(APPLICATION_USAGE_TABLE_DETECT)
      exists = True
    except sqlite3.OperationalError, e:
      if e.args[0].startswith('no such table'):
        exists = False
      else:
        raise 
開發者ID:google,項目名稱:macops,代碼行數:20,代碼來源:ApplicationUsage.py

示例2: _InsertApplicationUsage

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def _InsertApplicationUsage(
      self, conn, event, bundle_id, app_version, app_path, now):
    """Insert usage data into application usage table.

    Args:
      conn: sqlite3.Connection object
      event: str
      bundle_id: str
      app_version: str
      app_path: str
      now: int
    """
    # this looks weird, but it's the simplest way to do an update or insert
    # operation in sqlite, and atomically update number_times, that I could
    # figure out.  plus we avoid using transactions and multiple SQL
    # statements in most cases.

    v = (app_version, app_path, now, event, bundle_id)
    q = conn.execute(APPLICATION_USAGE_TABLE_UPDATE, v)
    if q.rowcount == 0:
      number_times = 1
      v = (event, bundle_id, app_version, app_path, now, number_times)
      conn.execute(APPLICATION_USAGE_TABLE_INSERT, v) 
開發者ID:google,項目名稱:macops,代碼行數:25,代碼來源:ApplicationUsage.py

示例3: read_check

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def read_check(id, type):
    try:
        conn = sqlite3.Connection('data/xuexi.db')
        cursor = conn.cursor()
        if cursor.execute('select * from read_history where id = "%s"' % id).fetchall() == []:
            cursor.execute('insert into read_history values("%s","%s")' % (id, type))
            conn.commit()
            logging.debug('new content %s %s' % (id, type))
            return True
        else:
            logging.debug('%s is in read history' % id)
            return False
    except Exception as error:
        logging.debug(error)
    finally:
        cursor.close()
        conn.close()

    return True 
開發者ID:zodiac182,項目名稱:autoxuexi,代碼行數:21,代碼來源:xuexi.py

示例4: CheckConnectionConstructorCallCheck

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def CheckConnectionConstructorCallCheck(self):
        """
        Verifies that connection methods check whether base class __init__ was
        called.
        """
        class Connection(sqlite.Connection):
            def __init__(self, name):
                pass

        con = Connection(":memory:")
        try:
            cur = con.cursor()
            self.fail("should have raised ProgrammingError")
        except sqlite.ProgrammingError:
            pass
        except:
            self.fail("should have raised ProgrammingError") 
開發者ID:vmware-archive,項目名稱:vsphere-storage-for-docker,代碼行數:19,代碼來源:regression.py

示例5: CheckConnectionConstructorCallCheck

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def CheckConnectionConstructorCallCheck(self):
        """
        Verifies that connection methods check wether base class __init__ was called.
        """
        class Connection(sqlite.Connection):
            def __init__(self, name):
                pass

        con = Connection(":memory:")
        try:
            cur = con.cursor()
            self.fail("should have raised ProgrammingError")
        except sqlite.ProgrammingError:
            pass
        except:
            self.fail("should have raised ProgrammingError") 
開發者ID:dxwu,項目名稱:BinderFilter,代碼行數:18,代碼來源:regression.py

示例6: commit

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def commit(self) -> None:
        """
        .. seealso:: :py:meth:`sqlite3.Connection.commit`
        """

        try:
            self.check_connection()
        except NullDatabaseConnectionError:
            return

        logger.debug("commit: path='{}'".format(self.database_path))
        assert self.connection  # to avoid type check error

        try:
            self.connection.commit()
        except sqlite3.ProgrammingError:
            pass 
開發者ID:thombashi,項目名稱:SimpleSQLite,代碼行數:19,代碼來源:core.py

示例7: close

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def close(self) -> None:
        """
        Commit and close the connection.

        .. seealso:: :py:meth:`sqlite3.Connection.close`
        """

        if self.__delayed_connection_path and self.__connection is None:
            self.__initialize_connection()
            return

        try:
            self.check_connection()
        except (SystemError, NullDatabaseConnectionError):
            return

        logger.debug("close connection to a SQLite database: path='{}'".format(self.database_path))

        self.commit()
        assert self.connection  # to avoid type check error
        self.connection.close()
        self.__initialize_connection() 
開發者ID:thombashi,項目名稱:SimpleSQLite,代碼行數:24,代碼來源:core.py

示例8: initialize_db

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def initialize_db(fname):
        """

        Args:
            fname (str): location of the database.

        Returns:
            db (sqlite3.Connection): a SQLite3 database with an embeddings table.

        """
        if path.dirname(fname) and not path.isdir(path.dirname(fname)):
            makedirs(path.dirname(fname))
        # open database in autocommit mode by setting isolation_level to None.
        db = sqlite3.connect(fname, isolation_level=None)
        c = db.cursor()
        c.execute('create table if not exists embeddings(word text primary key, emb blob)')
        return db 
開發者ID:vzhong,項目名稱:embeddings,代碼行數:19,代碼來源:embedding.py

示例9: create_model

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def create_model(dump, db_file=':memory:', N=2):
    """Create a semanticizer model from a wikidump and store it in a DB.

    Parameters
    ----------
    dump : string
        Filename of a Wikipedia dump, e.g.,
        'enwiki-20141106-pages-articles.xml.bz2'
    db_file : string
       (File)name of the sqlite3 DB. If `df_file` is `:memory:`, an in-memory
       db will be created, otherwise it is the filename of the
       disk-based db.

    Returns
    ------
    db : sqlite3.Connection
        The handle to the newly created db containing the model.
    """
    db = sqlite3.connect(db_file)
    _parse_stuff_to_db(dump, db, N=N)
    return db 
開發者ID:semanticize,項目名稱:semanticizest,代碼行數:23,代碼來源:_semanticizer.py

示例10: test_get_db_connection

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_get_db_connection():
    """ Test PhotosDB.get_db_connection """
    import osxphotos
    import sqlite3

    photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
    conn, cursor = photosdb.get_db_connection()

    assert isinstance(conn, sqlite3.Connection)
    assert isinstance(cursor, sqlite3.Cursor)

    results = conn.execute(
        "SELECT ZUUID FROM ZGENERICASSET WHERE ZFAVORITE = 1;"
    ).fetchall()
    assert len(results) == 1
    assert results[0][0] == "E9BC5C36-7CD1-40A1-A72B-8B8FAC227D51"  # uuid

    conn.close() 
開發者ID:RhetTbull,項目名稱:osxphotos,代碼行數:20,代碼來源:test_catalina_10_15_5.py

示例11: test_database_existing_tables

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_database_existing_tables(connection: Connection_instance) -> None:
    """
    Check tables that currently exists
    in database (after creating)
    :param connection: sqlite3.Connection object
    :return: None
    """
    assert sorted(
        connection.execute("SELECT name FROM sqlite_master").fetchall()
    ) == sorted(
        [
            ("sqlite_sequence",),
            ("scan_information",),
            ("scan_data",),
            ("shodan_results",),
            ("censys_results",),
        ]
    ) 
開發者ID:sdnewhop,項目名稱:grinder,代碼行數:20,代碼來源:test_database.py

示例12: test_database_existing_scan_information_columns

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_database_existing_scan_information_columns(
    connection: Connection_instance
) -> None:
    """
    Check column names of 'scan_information' table
    :param connection: sqlite3.Connection object
    :return: None
    """
    assert sorted(
        connection.execute("PRAGMA table_info(scan_information)").fetchall()
    ) == sorted(
        [
            (0, "id", "INTEGER", 0, None, 1),
            (1, "scan_name", "TEXT", 0, None, 0),
            (2, "scan_date", "TEXT", 0, None, 0),
            (3, "scan_start_time", "TEXT", 0, None, 0),
            (4, "scan_end_time", "TEXT", 0, None, 0),
            (5, "scan_duration", "TEXT", 0, None, 0),
            (6, "scan_total_products", "INT", 0, None, 0),
            (7, "scan_total_results", "INT", 0, None, 0),
        ]
    ) 
開發者ID:sdnewhop,項目名稱:grinder,代碼行數:24,代碼來源:test_database.py

示例13: test_database_existing_shodan_results_columns

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_database_existing_shodan_results_columns(
    connection: Connection_instance
) -> None:
    """
    Check column names of 'shodan_results' table
    :param connection: sqlite3.Connection object
    :return: None
    """
    assert sorted(
        connection.execute("PRAGMA table_info(shodan_results)").fetchall()
    ) == sorted(
        [
            (0, "id", "INTEGER", 0, None, 1),
            (1, "scan_data_id", "INTEGER", 0, None, 0),
            (2, "scan_information_id", "INTEGER", 0, None, 0),
            (3, "query", "TEXT", 0, None, 0),
            (4, "query_confidence", "TEXT", 0, None, 0),
            (5, "results_count", "INTEGER", 0, None, 0),
            (6, "results", "TEXT", 0, None, 0),
        ]
    ) 
開發者ID:sdnewhop,項目名稱:grinder,代碼行數:23,代碼來源:test_database.py

示例14: test_database_existing_censys_results_columns

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_database_existing_censys_results_columns(
    connection: Connection_instance
) -> None:
    """
    Check column names of 'censys_results' table
    :param connection: sqlite3.Connection object
    :return: None
    """
    assert sorted(
        connection.execute("PRAGMA table_info(censys_results)").fetchall()
    ) == sorted(
        [
            (0, "id", "INTEGER", 0, None, 1),
            (1, "scan_data_id", "INTEGER", 0, None, 0),
            (2, "scan_information_id", "INTEGER", 0, None, 0),
            (3, "query", "TEXT", 0, None, 0),
            (4, "query_confidence", "TEXT", 0, None, 0),
            (5, "results_count", "INTEGER", 0, None, 0),
            (6, "results", "TEXT", 0, None, 0),
        ]
    ) 
開發者ID:sdnewhop,項目名稱:grinder,代碼行數:23,代碼來源:test_database.py

示例15: test_update_end_time_success

# 需要導入模塊: import sqlite3 [as 別名]
# 或者: from sqlite3 import Connection [as 別名]
def test_update_end_time_success(connection: Connection_instance) -> None:
    """
    Check if we can successfully update time
    of scan - time when scan was finished
    :param connection: sqlite3.Connection object
    :return: None
    """
    db.update_end_time()
    end_time_values = connection.execute(
        """
        SELECT * FROM scan_information 
        WHERE scan_information.id = (
            SELECT max(id) 
            FROM scan_information
        )
        """
    ).fetchall()
    end_time, end_duration = end_time_values[0][4:6]
    assert end_time == str(db.scan_end_time.time().strftime("%H:%M:%S"))
    assert end_duration == str(db.scan_duration) 
開發者ID:sdnewhop,項目名稱:grinder,代碼行數:22,代碼來源:test_database.py


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