Hi, I am working on an app that does a lot of code generation. One part of it generates code for SQL queries. While I plan to allow the end-user to specify the types of columns explicitly, I really also need a way to have a default. But I don’t see a way to get the database column type from the ResultSet in order to decide what that default should be. At first I wondered maybe it is not be possible, but I checked the SQLite docs and it is (and in fact has to be for the API to be useful/work).
The sqlite3_column_type() routine returns the datatype code for the initial data type of the result column. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL.
I can check, but I imagine other supported databases are going to have a way to get this info too.
So I propose adding
#column_type(index : Int32) to
DB::ResultSet. Can we add these abstract methods, so that maintainers of the various backends can proceed to implement?
To do this, I suppose we will need a standardized Enum for the variety of possible types supported across various databases, basically these.
And ideally we probably should add a method for getting the size of the column too, for column types such as VARCHAR, BLOB, etc.