当前位置: 首页>>代码示例>>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;未经允许,请勿转载。