Git Product home page Git Product logo

Comments (3)

rogerbinns avatar rogerbinns commented on July 19, 2024

Nothing to do with TypesConverterCursorFactory which you can see if you comment out setting it as cursor_factory.

Virtual tables are a SQLite thing which means they only operate on SQLite supported data types. I've changed the error message, so now you get this as the last line of the exception:

TypeError: Value from Python is not supported by SQLite. It should be one of None, int, float, str, or bytes. Received complex.

There is a repr_invalid parameter to make_virtual_table which would have turned the complex number into the string '(3+4j)' but that is repr output and not something the types converter would understand. The parameter is off by default because it is expensive checking every value in every column of every row returned.

You could change the yield line to this which would convert the value into something SQLite supports.

yield {"col1": registrar.adapt_value(table_data[c])}

But then on running you will get this where the values are the adapted ones (strings).

┌──────────┐
│   col1   │
│ 3.0+4.0  │
│ 8.0+-2.0 │
│ 1.0+-5.0 │
└──────────┘

The reason for that is the virtual table at the SQLite level does not have declared column types. Using apsw.ext.query_info will include this where the None is the declared column type:
description=(('col1', None),),

In short, this is trying really hard to pretend SQLite supports COMPLEX but that has to be done everywhere. If the yield line was changed and make_virtual_table did declare the column at the SQLite level to have type COMPLEX then it would work. But the latter is not something that will be changed in apsw because the library code is applicable to everyone.

You can however do it yourself. You can copy make_virtual_table, and where it gets the function signature you have to look at the annotation and turn that into whatever string you want in the SQL that creates the virtual table.

from apsw.

rogerbinns avatar rogerbinns commented on July 19, 2024

Thinking about it a little more, I'd recommend you avoid make_virtual_table and implement your own virtual tables. That will provide precise control over exactly what values are provided to SQLite, as well as the table and column declarations for the virtual table which are necessary for TypesConverterCursorFactory to work as expected.

from apsw.

alexneufeld avatar alexneufeld commented on July 19, 2024

Will do. Thanks for your help!

from apsw.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.