Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BinaryConverterTests.test_CheckBinaryInputForConverter fails with both pyrqlite and sqlite3 #17

Open
zmedico opened this issue Jun 5, 2017 · 2 comments

Comments

@zmedico
Copy link
Collaborator

zmedico commented Jun 5, 2017

This test fails with pyrqlite as follows:

____________ BinaryConverterTests.test_CheckBinaryInputForConverter ____________

self = <test_types.BinaryConverterTests testMethod=test_CheckBinaryInputForConverter>

    def test_CheckBinaryInputForConverter(self):
        testdata = b"abcdefg" * 10
        compressed = zlib.compress(testdata)
>       result = self.con.execute('select ? as "x [bin]"', (compressed,)).fetchone()[0]

src/test/test_types.py:397: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
src/pyrqlite/connections.py:100: in execute
    return cursor.execute(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pyrqlite.cursors.Cursor object at 0x7efbf49d79d0>
operation = 'select \'x\x9cKLJNIMKO\xa4\x8c\x02\x00\xca\x0f\x1bY\' as "x [bin]"'
parameters = ('x\x9cKLJNIMKO\xa4\x8c\x02\x00\xca\x0f\x1bY',)

    def execute(self, operation, parameters=None):
    
        if parameters:
            operation = self._substitute_params(operation, parameters)
    
        command = self._get_sql_command(operation)
        if command in ('SELECT', 'PRAGMA'):
            payload = self._request("GET",
                                    "/db/query?" + _urlencode({'q': operation}))
        else:
            payload = self._request("POST", "/db/execute?transaction",
                                    headers={'Content-Type': 'application/json'}, body=json.dumps([operation]))
    
        last_insert_id = None
        rows_affected = -1
        payload_rows = {}
        try:
            results = payload["results"]
        except KeyError:
            pass
        else:
            rows_affected = 0
            for item in results:
                if 'error' in item:
                    logging.error(json.dumps(item))
>                   raise Error(json.dumps(item))
E                   Error: {"error": "unrecognized token: \"'x\ufffdKLJNIMKO\ufffd\ufffd\u0002\""}

It also fails with python's own sqlite3 module, as follows:

____________ BinaryConverterTests.test_CheckBinaryInputForConverter ____________

self = <test_types.BinaryConverterTests testMethod=test_CheckBinaryInputForConverter>

    def test_CheckBinaryInputForConverter(self):
        testdata = b"abcdefg" * 10
        compressed = zlib.compress(testdata)
>       result = self.con.execute('select ? as "x [bin]"', (compressed,)).fetchone()[0]
E       ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

src/test/test_types.py:397: ProgrammingError

@alanjds

@alanjds
Copy link
Contributor

alanjds commented Jun 5, 2017

Hum... Are you trying CPython 3 or CPython 2? I copied the tests from CPython 2, if I remember it right.

@zmedico
Copy link
Collaborator Author

zmedico commented Jun 5, 2017

I'm trying with CPython 2.7.12 (CPython 3 is not supported yet, though I have been working on it in my python3 branch).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants