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


Python extensions.ISQLQuote方法代碼示例

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


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

示例1: test_none_fast_path

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_none_fast_path(self):
        # the None adapter is not actually invoked in regular adaptation

        class WonkyAdapter(object):
            def __init__(self, obj): pass
            def getquoted(self): return "NOPE!"

        curs = self.conn.cursor()

        orig_adapter = ext.adapters[type(None), ext.ISQLQuote]
        try:
            ext.register_adapter(type(None), WonkyAdapter)
            self.assertEqual(ext.adapt(None).getquoted(), "NOPE!")

            s = curs.mogrify("SELECT %s;", (None,))
            self.assertEqual(b("SELECT NULL;"), s)

        finally:
            ext.register_adapter(type(None), orig_adapter) 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:21,代碼來源:test_types_extras.py

示例2: __conform__

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def __conform__(self, proto):
        # Does the given protocol conform to what Psycopg2 expects?
        if proto == ISQLQuote:
            return self
        else:
            raise Exception('Error implementing psycopg2 protocol. Is psycopg2 installed?') 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:8,代碼來源:adapter.py

示例3: __conform__

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def __conform__(self, proto):
        if proto is _ext.ISQLQuote:
            return self 
開發者ID:tryolabs,項目名稱:aws-workshop,代碼行數:5,代碼來源:extras.py

示例4: __conform__

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def __conform__(self, proto):
        if self._proto is ISQLQuote:
            return self 
開發者ID:tryolabs,項目名稱:aws-workshop,代碼行數:5,代碼來源:_range.py

示例5: test_adapt_fail

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_adapt_fail(self):
        class Foo(object): pass
        self.assertRaises(psycopg2.ProgrammingError,
            psycopg2.extensions.adapt, Foo(), ext.ISQLQuote, None)
        try:
            psycopg2.extensions.adapt(Foo(), ext.ISQLQuote, None)
        except psycopg2.ProgrammingError, err:
            self.failUnless(str(err) == "can't adapt type 'Foo'") 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:10,代碼來源:test_types_extras.py

示例6: test_register_on_dict

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_register_on_dict(self):
        from psycopg2.extras import Json
        psycopg2.extensions.register_adapter(dict, Json)

        try:
            curs = self.conn.cursor()
            obj = {'a': 123}
            self.assertEqual(curs.mogrify("%s", (obj,)),
                b("""'{"a": 123}'"""))
        finally:
           del psycopg2.extensions.adapters[dict, ext.ISQLQuote] 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:13,代碼來源:test_types_extras.py

示例7: test_register_range_adapter

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_register_range_adapter(self):
        from psycopg2.extras import Range, register_range
        cur = self.conn.cursor()
        cur.execute("create type textrange as range (subtype=text)")
        rc = register_range('textrange', 'TextRange', cur)

        TextRange = rc.range
        self.assert_(issubclass(TextRange, Range))
        self.assertEqual(TextRange.__name__, 'TextRange')

        r = TextRange('a', 'b', '(]')
        cur.execute("select %s", (r,))
        r1 = cur.fetchone()[0]
        self.assertEqual(r1.lower, 'a')
        self.assertEqual(r1.upper, 'b')
        self.assert_(not r1.lower_inc)
        self.assert_(r1.upper_inc)

        cur.execute("select %s", ([r,r,r],))
        rs = cur.fetchone()[0]
        self.assertEqual(len(rs), 3)
        for r1 in rs:
            self.assertEqual(r1.lower, 'a')
            self.assertEqual(r1.upper, 'b')
            self.assert_(not r1.lower_inc)
            self.assert_(r1.upper_inc)

        # clear the adapters to allow precise count by scripts/refcounter.py
        del ext.adapters[rc.range, ext.ISQLQuote] 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:31,代碼來源:test_types_extras.py

示例8: test_conform_accepts_ISQLQuote

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_conform_accepts_ISQLQuote(self):
        mac = MAC(factory.make_mac_address())
        self.assertEqual(mac, mac.__conform__(ISQLQuote)) 
開發者ID:maas,項目名稱:maas,代碼行數:5,代碼來源:test_fields.py

示例9: test_range_escaping

# 需要導入模塊: from psycopg2 import extensions [as 別名]
# 或者: from psycopg2.extensions import ISQLQuote [as 別名]
def test_range_escaping(self):
        from psycopg2.extras import register_range
        cur = self.conn.cursor()
        cur.execute("create type textrange as range (subtype=text)")
        rc = register_range('textrange', 'TextRange', cur)

        TextRange = rc.range
        cur.execute("""
            create table rangetest (
                id integer primary key,
                range textrange)""")

        bounds = [ '[)', '(]', '()', '[]' ]
        ranges = [ TextRange(low, up, bounds[i % 4])
            for i, (low, up) in enumerate(zip(
                [None] + map(chr, range(1, 128)),
                map(chr, range(1,128)) + [None],
                ))]
        ranges.append(TextRange())
        ranges.append(TextRange(empty=True))

        errs = 0
        for i, r in enumerate(ranges):
            # not all the ranges make sense:
            # fun fact: select ascii('#') < ascii('$'), '#' < '$'
            # yelds... t, f! At least in en_GB.UTF-8 collation.
            # which seems suggesting a supremacy of the pound on the dollar.
            # So some of these ranges will fail to insert. Be prepared but...
            try:
                cur.execute("""
                    savepoint x;
                    insert into rangetest (id, range) values (%s, %s);
                    """, (i, r))
            except psycopg2.DataError:
                errs += 1
                cur.execute("rollback to savepoint x;")

        # ...not too many errors! in the above collate there are 17 errors:
        # assume in other collates we won't find more than 30
        self.assert_(errs < 30,
            "too many collate errors. Is the test working?")

        cur.execute("select id, range from rangetest order by id")
        for i, r in cur:
            self.assertEqual(ranges[i].lower, r.lower)
            self.assertEqual(ranges[i].upper, r.upper)
            self.assertEqual(ranges[i].lower_inc, r.lower_inc)
            self.assertEqual(ranges[i].upper_inc, r.upper_inc)
            self.assertEqual(ranges[i].lower_inf, r.lower_inf)
            self.assertEqual(ranges[i].upper_inf, r.upper_inf)

        # clear the adapters to allow precise count by scripts/refcounter.py
        del ext.adapters[TextRange, ext.ISQLQuote] 
開發者ID:synthetichealth,項目名稱:syntheticmass,代碼行數:55,代碼來源:test_types_extras.py


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