[CONPY-264] Incorrect types for defaults returned for `show columns in table` Created: 2023-06-03 Updated: 2023-06-25 Resolved: 2023-06-04 |
|
| Status: | Closed |
| Project: | MariaDB Connector/Python |
| Component/s: | Parser |
| Affects Version/s: | 1.1.6 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Minor |
| Reporter: | Andrej | Assignee: | Georg Richter |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu linux 22.04 |
||
| Python Version: | 3.10.6 |
| Description |
|
This is table definition:
Running from the connector:
Evidently all default values are returned as strings rather than the columns' respective types. The expected output should have been:
|
| Comments |
| Comment by Georg Richter [ 2023-06-04 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
MariaDB Connector/Python converts the value in default to the type which was sent by server in the metadata packet.
As you can see, the default value is defined as VAR_STRING. So it's up to your application to convert the value to the appropriate type. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrej [ 2023-06-06 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Thank you for your quick response, and my apologies for reporting a non-issue. But please help me understand this better. If I query an actual row through the connector, all types get converted to the proper python types; can the same not be done for the defaults? Variable types are clearly stored correctly in the database itself, why can't the connector cast them to proper types? Are there any public methods in the connector code that can be used to consistently (w.r.t. the connector itself) convert default values to the appropriate type? I would have expected that type conversion should be done by the connector and not the application. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-06-25 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
select * from mytable or show columns in mytable — these statements return results as a table. In a table all values in a column have the same metadata. You cannot have the value in the second row, fourth column to be an integer and the value in the third row, fourth column, to be a string. In this case you ask Connector/Python to send an SQL query to the server, and return you the tabular data as they come from the server. Connector/Python doesn't even know that the first column corresponds to the column name in some table of yours and the fifth column contains its default value. |