当前位置: 首页>>代码示例>>Python>>正文


Python sqlite3.Cursor方法代码示例

本文整理汇总了Python中sqlite3.Cursor方法的典型用法代码示例。如果您正苦于以下问题:Python sqlite3.Cursor方法的具体用法?Python sqlite3.Cursor怎么用?Python sqlite3.Cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlite3的用法示例。


在下文中一共展示了sqlite3.Cursor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CheckCursorConstructorCallCheck

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorConstructorCallCheck(self):
        """
        Verifies that cursor methods check whether base class __init__ was
        called.
        """
        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                pass

        con = sqlite.connect(":memory:")
        cur = Cursor(con)
        try:
            cur.execute("select 4+5").fetchall()
            self.fail("should have raised ProgrammingError")
        except sqlite.ProgrammingError:
            pass
        except:
            self.fail("should have raised ProgrammingError") 
开发者ID:vmware-archive,项目名称:vsphere-storage-for-docker,代码行数:20,代码来源:regression.py

示例2: CheckCursorConstructorCallCheck

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorConstructorCallCheck(self):
        """
        Verifies that cursor methods check whether base class __init__ was
        called.
        """
        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                pass

        con = sqlite.connect(":memory:")
        cur = Cursor(con)
        try:
            cur.execute("select 4+5").fetchall()
            self.fail("should have raised ProgrammingError")
        except sqlite.ProgrammingError:
            pass
        except:
            self.fail("should have raised ProgrammingError")
        with self.assertRaisesRegexp(sqlite.ProgrammingError,
                                     r'^Base Cursor\.__init__ not called\.$'):
            cur.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:regression.py

示例3: CheckCursorConstructorCallCheck

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorConstructorCallCheck(self):
        """
        Verifies that cursor methods check wether base class __init__ was called.
        """
        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                pass

        con = sqlite.connect(":memory:")
        cur = Cursor(con)
        try:
            cur.execute("select 4+5").fetchall()
            self.fail("should have raised ProgrammingError")
        except sqlite.ProgrammingError:
            pass
        except:
            self.fail("should have raised ProgrammingError") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:19,代码来源:regression.py

示例4: delete

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def delete(self, table_name: str, where: Optional[WhereQuery] = None) -> Optional[Cursor]:
        """
        Send a DELETE query to the database.

        :param str table_name: Table name of executing the query.
        :param where: |arg_select_where|
        :type where: |arg_where_type|
        """

        self.validate_access_permission(["w", "a"])
        self.verify_table_existence(table_name)

        query = "DELETE FROM {:s}".format(table_name)
        if where:
            query += " WHERE {:s}".format(where)

        return self.execute_query(query, logging.getLogger().findCaller()) 
开发者ID:thombashi,项目名称:SimpleSQLite,代码行数:19,代码来源:core.py

示例5: insert_system

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def insert_system(cur, system_name, encoded_data=None):
    """Insert a system name into the cache.

    Args:
        cur (:class:`sqlite3.Cursor`):
            An sqlite3 cursor. This function is meant to be run within a :obj:`with` statement.

        system_name (str):
            The unique name of a system

        encoded_data (dict, optional):
            If a dictionary is provided, it will be populated with the serialized data. This is
            useful for preventing encoding the same information many times.

    """
    if encoded_data is None:
        encoded_data = {}

    if 'system_name' not in encoded_data:
        encoded_data['system_name'] = system_name

    insert = "INSERT OR IGNORE INTO system(system_name) VALUES (:system_name);"
    cur.execute(insert, encoded_data) 
开发者ID:dwavesystems,项目名称:dwave-system,代码行数:25,代码来源:database_manager.py

示例6: execute

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def execute(cls, query, params=()):
        """
        This method executes a query with parameters.

        :param str query: The query.
        :param tuple params: The parameters.
        :rtype: sqlite3.Cursor
        """

        Model.lock.acquire()

        try:
            result = Model.db.execute(query, params)
        finally:
            Model.lock.release()

        return result 
开发者ID:zerofox-oss,项目名称:deepstar,代码行数:19,代码来源:model.py

示例7: test_get_db_connection

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [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

示例8: CheckCursorConstructorCallCheck

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorConstructorCallCheck(self):
        """
        Verifies that cursor methods check whether base class __init__ was
        called.
        """
        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                pass

        con = sqlite.connect(":memory:")
        cur = Cursor(con)
        with self.assertRaises(sqlite.ProgrammingError):
            cur.execute("select 4+5").fetchall()
        with self.assertRaisesRegex(sqlite.ProgrammingError,
                                    r'^Base Cursor\.__init__ not called\.$'):
            cur.close() 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:18,代码来源:regression.py

示例9: CheckCursorRegistration

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorRegistration(self):
        """
        Verifies that subclassed cursor classes are correctly registered with
        the connection object, too.  (fetch-across-rollback problem)
        """
        class Connection(sqlite.Connection):
            def cursor(self):
                return Cursor(self)

        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                sqlite.Cursor.__init__(self, con)

        con = Connection(":memory:")
        cur = con.cursor()
        cur.execute("create table foo(x)")
        cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
        cur.execute("select x from foo")
        con.rollback()
        with self.assertRaises(sqlite.InterfaceError):
            cur.fetchall() 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:23,代码来源:regression.py

示例10: sqlite3

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def sqlite3(self, conn, sql, parameters=None, *args, **kwargs):
        """
        Reads input by querying from a sqlite database.

        >>> seq.sqlite3('examples/users.db', 'select id, name from users where id = 1;').first()
        [(1, 'Tom')]

        :param conn: path or sqlite connection, cursor
        :param sql: SQL query string
        :param parameters: Parameters for sql query
        :return: Sequence wrapping SQL cursor
        """

        if parameters is None:
            parameters = ()

        if isinstance(conn, (sqlite3api.Connection, sqlite3api.Cursor)):
            return self(conn.execute(sql, parameters))
        elif isinstance(conn, str):
            with sqlite3api.connect(conn, *args, **kwargs) as input_conn:
                return self(input_conn.execute(sql, parameters))
        else:
            raise ValueError(
                "conn must be a must be a file path or sqlite3 Connection/Cursor"
            ) 
开发者ID:EntilZha,项目名称:PyFunctional,代码行数:27,代码来源:streams.py

示例11: __init__

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def __init__(
        self,
        schema_path: str,
        cursor: Cursor = None,
        use_prelinked_entities: bool = True,
        variable_free: bool = True,
        use_untyped_entities: bool = False,
    ) -> None:
        self.cursor = cursor
        self.schema = read_dataset_schema(schema_path)
        self.columns = {column.name: column for table in self.schema.values() for column in table}
        self.dataset_name = os.path.basename(schema_path).split("-")[0]
        self.use_prelinked_entities = use_prelinked_entities
        self.variable_free = variable_free
        self.use_untyped_entities = use_untyped_entities

        # NOTE: This base dictionary should not be modified.
        self.base_grammar_dictionary = self._initialize_grammar_dictionary(
            deepcopy(GRAMMAR_DICTIONARY)
        ) 
开发者ID:allenai,项目名称:allennlp-semparse,代码行数:22,代码来源:text2sql_world.py

示例12: default

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def default(self, obj):
        if isinstance(obj, sqlite3.Row):
            return tuple(obj)
        if isinstance(obj, sqlite3.Cursor):
            return list(obj)
        if isinstance(obj, bytes):
            # Does it encode to utf8?
            try:
                return obj.decode("utf8")
            except UnicodeDecodeError:
                return {
                    "$base64": True,
                    "encoded": base64.b64encode(obj).decode("latin1"),
                }
        return json.JSONEncoder.default(self, obj) 
开发者ID:simonw,项目名称:datasette,代码行数:17,代码来源:__init__.py

示例13: query

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def query(query: str, *param: str) -> 'sqlite3.Cursor':  # type: ignore
  """
  Performs the given query on our sqlite manual cache. This database should
  be treated as being read-only. File permissions generally enforce this, and
  in the future will be enforced by this function as well.

  ::

    >>> import stem.manual
    >>> print(stem.manual.query('SELECT description FROM torrc WHERE key=?', 'CONTROLSOCKET').fetchone()[0])
    Like ControlPort, but listens on a Unix domain socket, rather than a TCP socket.  0 disables ControlSocket. (Unix and Unix-like systems only.) (Default: 0)

  .. versionadded:: 1.6.0

  :param query: query to run on the cache
  :param param: query parameters

  :returns: :class:`sqlite3.Cursor` with the query results

  :raises:
    * **ImportError** if the sqlite3 module is unavailable
    * **sqlite3.OperationalError** if query fails
  """

  try:
    import sqlite3
  except (ImportError, ModuleNotFoundError):
    raise ImportError('Querying requires the sqlite3 module')

  # The only reason to explicitly close the sqlite connection is to ensure
  # transactions are committed. Since we're only using read-only access this
  # doesn't matter, and can allow interpreter shutdown to do the needful.

  global DATABASE

  if DATABASE is None:
    DATABASE = sqlite3.connect('file:%s?mode=ro' % CACHE_PATH, uri=True)

  return DATABASE.execute(query, param) 
开发者ID:torproject,项目名称:stem,代码行数:41,代码来源:manual.py

示例14: CheckCursorWrongClass

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorWrongClass(self):
        class Foo: pass
        foo = Foo()
        try:
            cur = sqlite.Cursor(foo)
            self.fail("should have raised a ValueError")
        except TypeError:
            pass 
开发者ID:vmware-archive,项目名称:vsphere-storage-for-docker,代码行数:10,代码来源:dbapi.py

示例15: CheckCursorRegistration

# 需要导入模块: import sqlite3 [as 别名]
# 或者: from sqlite3 import Cursor [as 别名]
def CheckCursorRegistration(self):
        """
        Verifies that subclassed cursor classes are correctly registered with
        the connection object, too.  (fetch-across-rollback problem)
        """
        class Connection(sqlite.Connection):
            def cursor(self):
                return Cursor(self)

        class Cursor(sqlite.Cursor):
            def __init__(self, con):
                sqlite.Cursor.__init__(self, con)

        con = Connection(":memory:")
        cur = con.cursor()
        cur.execute("create table foo(x)")
        cur.executemany("insert into foo(x) values (?)", [(3,), (4,), (5,)])
        cur.execute("select x from foo")
        con.rollback()
        try:
            cur.fetchall()
            self.fail("should have raised InterfaceError")
        except sqlite.InterfaceError:
            pass
        except:
            self.fail("should have raised InterfaceError") 
开发者ID:vmware-archive,项目名称:vsphere-storage-for-docker,代码行数:28,代码来源:regression.py


注:本文中的sqlite3.Cursor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。