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


Python psycopg2.DataError方法代码示例

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


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

示例1: test_transaction_point_oldstyle

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_transaction_point_oldstyle(engine):
    async with engine.acquire() as cur:
        tr = Transaction(cur, IsolationLevel.read_committed)
        await tr.begin()

        await cur.execute("insert into tbl values(1, 'data')")

        try:
            await tr.savepoint()
            await cur.execute("insert into tbl values(1/0, 'no data')")
        except psycopg2.DataError:
            await tr.rollback_savepoint()

        await tr.savepoint()
        await cur.execute("insert into tbl values(2, 'data')")
        await tr.release_savepoint()

        await cur.execute("insert into tbl values(3, 'data')")

        resp = await cur.execute('select * from tbl')
        row = await resp.fetchall()
        assert row == [(22, 'read only'), (1, 'data'), (2, 'data'),
                       (3, 'data')]

        await tr.commit() 
开发者ID:aio-libs,项目名称:aiopg,代码行数:27,代码来源:test_transaction.py

示例2: test_transaction_point

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_transaction_point(engine):
    async with engine.cursor() as cur:
        async with Transaction(cur, IsolationLevel.read_committed) as tr:
            await cur.execute("insert into tbl values(1, 'data')")

            with pytest.raises(psycopg2.DataError):
                async with tr.point():
                    await cur.execute("insert into tbl values(1/0, 'data')")

            async with tr.point():
                await cur.execute("insert into tbl values(2, 'data point')")

            await cur.execute("insert into tbl values(3, 'data')")

            await cur.execute('select * from tbl')
            row = await cur.fetchall()
            assert row == [(22, 'read only'), (1, 'data'),
                           (2, 'data point'), (3, 'data')] 
开发者ID:aio-libs,项目名称:aiopg,代码行数:20,代码来源:test_async_transaction.py

示例3: test_begin_nested

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_begin_nested(engine):
    async with engine.cursor() as cur:
        async with cur.begin_nested():
            await cur.execute("insert into tbl values(1, 'data')")

            with pytest.raises(psycopg2.DataError):
                async with cur.begin_nested():
                    await cur.execute("insert into tbl values(1/0, 'no data')")

            async with cur.begin_nested():
                await cur.execute("insert into tbl values(2, 'data')")

        async with cur.begin_nested():
            await cur.execute('select * from tbl')
            row = await cur.fetchall()
            assert row == [(22, 'read only'), (1, 'data'),
                           (2, 'data'), ] 
开发者ID:aio-libs,项目名称:aiopg,代码行数:19,代码来源:test_async_transaction.py

示例4: forms

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def forms(w):
        """ Return a list of all possible forms of a particular root (stem) """
        c = Meanings._cursor
        assert c is not None
        m = None
        try:
            c.execute(Meanings._DB_Q_FORMS, [w])
            # Map the returned data from fetchall() to a list of instances
            # of the BIN_Meaning namedtuple
            g = c.fetchall()
            if g is not None:
                m = list(map(BIN_Meaning._make, g))
        except (psycopg2.DataError, psycopg2.ProgrammingError) as e:
            print("Word '{0}' caused DB exception {1}".format(w, e))
            m = None
        return m 
开发者ID:mideind,项目名称:Greynir,代码行数:18,代码来源:vocab.py

示例5: sentences

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def sentences(self):
        """ Return a list of all test sentences in the database """
        assert self._c is not None
        m = [ ]
        try:
            self._c.execute("SELECT id, sentence, numtrees, best, target FROM sentences ORDER BY id;")
            t = self._c.fetchall()
            m = [ dict(
                    identity = r[0],
                    sentence = r[1],
                    numtrees = r[2],
                    best = r[3],
                    target = r[4])
                for r in t]
        except psycopg2.DataError as e:
            # Fall through with empty m
            pass
        return m 
开发者ID:mideind,项目名称:Greynir,代码行数:20,代码来源:ptest.py

示例6: insert_rows

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def insert_rows(self, rows, table_name=None):
        """
        Inserts many rows, all in the same transaction, using psycopg2.extras.execute_values
        """

        if table_name is None:
            table_name = self.table_name

        with self.conn.cursor() as curs:
            sql_str, template = sql.insert_many(table_name, rows)
            try:
                psycopg2.extras.execute_values(
                    curs,
                    sql_str,
                    rows,
                    template=template,
                    page_size=len(rows)
                )
            except psycopg2.DataError:
                print(rows) # useful for debugging
                raise
        self.conn.commit() 
开发者ID:nycdb,项目名称:nycdb,代码行数:24,代码来源:database.py

示例7: vfolder_check_exists

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def vfolder_check_exists(handler: Callable[..., Awaitable[web.Response]]):
    '''
    Checks if the target vfolder exists and is owned by the current user.

    The decorated handler should accept an extra "row" argument
    which contains the matched VirtualFolder table row.
    '''

    @functools.wraps(handler)
    async def _wrapped(request: web.Request, *args, **kwargs) -> web.Response:
        dbpool = request.app['dbpool']
        user_uuid = request['user']['uuid']
        folder_name = request.match_info['name']
        async with dbpool.acquire() as conn:
            j = sa.join(
                vfolders, vfolder_permissions,
                vfolders.c.id == vfolder_permissions.c.vfolder, isouter=True)
            query = (
                sa.select('*')
                .select_from(j)
                .where(((vfolders.c.user == user_uuid) |
                        (vfolder_permissions.c.user == user_uuid)) &
                       (vfolders.c.name == folder_name)))
            try:
                result = await conn.execute(query)
            except psycopg2.DataError:
                raise InvalidAPIParameters
            row = await result.first()
            if row is None:
                raise VFolderNotFound()
        return await handler(request, row, *args, **kwargs)

    return _wrapped 
开发者ID:lablup,项目名称:backend.ai-manager,代码行数:35,代码来源:vfolder.py

示例8: parse

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def parse(self, s, curs):
        if s is None:
            return None

        tokens = self.tokenize(s)
        if len(tokens) != len(self.atttypes):
            raise psycopg2.DataError(
                "expecting %d components for the type %s, %d found instead" %
                (len(self.atttypes), self.name, len(tokens)))

        values = [curs.cast(oid, token)
            for oid, token in zip(self.atttypes, tokens)]

        return self.make(values) 
开发者ID:tryolabs,项目名称:aws-workshop,代码行数:16,代码来源:extras.py

示例9: test_path_invalid_repo_name_and_job_name

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_path_invalid_repo_name_and_job_name(self):
        try:
            self.get('/v2/hello/world', self.get_project_headers())
        except psycopg2.DataError:
            pass 
开发者ID:SAP,项目名称:InfraBox,代码行数:7,代码来源:test.py

示例10: test_insertErr

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_insertErr(self):
		key = len(TEST_DATA) + 2
		self.assertRaises((ValueError, psycopg2.DataError), self.tree.insert, 'wat', 1) 
开发者ID:fake-name,项目名称:IntraArchiveDeduplicator,代码行数:5,代码来源:Test_db_BKTree.py

示例11: test_parse_incomplete_date

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_parse_incomplete_date(self):
        self.assertRaises(psycopg2.DataError, self.DATE, '2007', self.curs)
        self.assertRaises(psycopg2.DataError, self.DATE, '2007-01', self.curs) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:5,代码来源:test_dates.py

示例12: test_parse_incomplete_time

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_parse_incomplete_time(self):
        self.assertRaises(psycopg2.DataError, self.TIME, '13', self.curs)
        self.assertRaises(psycopg2.DataError, self.TIME, '13:30', self.curs) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:5,代码来源:test_dates.py

示例13: test_parse_incomplete_datetime

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def test_parse_incomplete_datetime(self):
        self.assertRaises(psycopg2.DataError,
                          self.DATETIME, '2007', self.curs)
        self.assertRaises(psycopg2.DataError,
                          self.DATETIME, '2007-01', self.curs)
        self.assertRaises(psycopg2.DataError,
                          self.DATETIME, '2007-01-01 13', self.curs)
        self.assertRaises(psycopg2.DataError,
                          self.DATETIME, '2007-01-01 13:30', self.curs) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:11,代码来源:test_dates.py

示例14: testFloatInf

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def testFloatInf(self):
        try:
            self.execute("select 'inf'::float")
        except psycopg2.DataError:
            return self.skipTest("inf::float not available on the server")
        except ValueError:
            return self.skipTest("inf not available on this platform")
        s = self.execute("SELECT %s AS foo", (float("inf"),))
        self.failUnless(str(s) == "inf", "wrong float quoting: " + str(s))      
        self.failUnless(type(s) == float, "wrong float conversion: " + repr(s))

        s = self.execute("SELECT %s AS foo", (float("-inf"),))
        self.failUnless(str(s) == "-inf", "wrong float quoting: " + str(s)) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:15,代码来源:test_types_basic.py

示例15: testArrayMalformed

# 需要导入模块: import psycopg2 [as 别名]
# 或者: from psycopg2 import DataError [as 别名]
def testArrayMalformed(self):
        curs = self.conn.cursor()
        ss = ['', '{', '{}}', '{' * 20 + '}' * 20]
        for s in ss:
            self.assertRaises(psycopg2.DataError,
                psycopg2.extensions.STRINGARRAY, b(s), curs) 
开发者ID:synthetichealth,项目名称:syntheticmass,代码行数:8,代码来源:test_types_basic.py


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