Example #1
0
 def test_complete_insert(self):
     p = MySQLCompleteInsertProtocol()
     key, value = p.read(
         "INSERT INTO `user` (`id`, `name`, `score`, `data`, `misc`) VALUES"
         " (1,'David Marin',25.25,0xC0DE,NULL);")
     self.assertEqual(
         (key, value), (u'user', {u'id': 1,
                                  u'name': u'David Marin',
                                  u'score': 25.25,
                                  u'data': '\xc0\xde',
                                  u'misc': None}))
Example #2
0
 def test_alternate_encoding(self):
     p = MySQLCompleteInsertProtocol(encoding='latin-1')
     # encoded in UTF-8, but we will decode it in latin-1
     key, value = p.read(
         "INSERT INTO `user` (`id`, `name`, `score`, `data`, `misc`) VALUES"
         " (3,'Paul Erdős',0,0x0E2D05,NULL);")
     self.assertEqual(
         (key, value), (u'user', {u'id': 3,
                                  u'name': 'Paul Erdős'.decode('latin-1'),
                                  u'score': 0,
                                  u'data': '\x0e\x2d\x05',
                                  u'misc': None}))
Example #3
0
    def test_default_encoding(self):
        p = MySQLCompleteInsertProtocol()
        # encoded in UTF-8
        key, value = p.read(
            "INSERT INTO `user` (`id`, `name`, `score`, `data`, `misc`) VALUES"
            " (3,'Paul Erdős',0,0x0E2D05,NULL);")
        self.assertEqual(
            (key, value), (u'user', {u'id': 3,
                                     u'name': u'Paul Erdős',
                                     u'score': 0,
                                     u'data': '\x0e\x2d\x05',
                                     u'misc': None, }))

        key, value = p.read(
            # encoded in latin-1, with ö instead of ő
            "INSERT INTO `user` (`id`, `name`, `score`, `data`, `misc`) VALUES"
            " (3,'Paul Erd\xf6s',0,0x0E2D05,NULL);")
        self.assertEqual(
            (key, value), (u'user', {u'id': 3,
                                     u'name': u'Paul Erdös',
                                     u'score': 0,
                                     u'data': '\x0e\x2d\x05',
                                     u'misc': None, }))