Exemplo n.º 1
0
    def test_text_dictarray(self):
        try:
            self.conn.execute('drop table TEXT_TEST').commit()
        except Exception:
            pass

        self.conn.execute('create table TEXT_TEST (val text not null)').commit()
        values = (("some small string",), ("foo",))
        cur = self.conn.cursor()
        cur.executemany('insert into TEXT_TEST values (?)', values)
        cur.commit()

        with text_limit(max(*[len(v[0]) for v in values])):
            da = self.conn.execute('select * from TEXT_TEST').fetchdictarray()

        self.assertEqual(np.string_, da['val'].dtype.type)
        self.assertTrue(np.all(da['val'] == np.ravel(values)))
        self.conn.execute('drop table TEXT_TEST').commit()
Exemplo n.º 2
0
    def test_simple(self):
        limit = 100
        try:
            self.conn.execute('drop table SET_TEXT_LIMIT_TEST').commit()
        except Exception:
            pass

        self.conn.execute(
            'create table SET_TEXT_LIMIT_TEST (val varchar({0}) not null)'.
            format(limit * 2)).commit()
        lengths = list(range(0, limit * 2, limit // 40))
        test_data = [('x' * i, ) for i in lengths]
        cur = self.conn.cursor()
        cur.executemany('insert into SET_TEXT_LIMIT_TEST values (?)',
                        test_data)
        cur.commit()

        with text_limit(limit):
            da = self.conn.execute(
                'select * from SET_TEXT_LIMIT_TEST').fetchdictarray()

        val = da['val']
        self.assertTrue(np.string_, val.dtype.type)
        self.assertTrue(limit + 1, val.dtype.itemsize)