Skip to content

Conversation

JanJakes
Copy link
Member

@JanJakes JanJakes commented Jul 4, 2025

This PR implements emulation of PDOStatement::getColumnMeta() values and adds support for $wpdb::get_col_info().

This feature is necessary for support of MySQL tools like Adminer, phpMyAdmin, and others, as well as for any plugins that may rely on this functionality.

Resolves #190.

@JanJakes JanJakes force-pushed the column-meta branch 4 times, most recently from fec56d7 to 163fc67 Compare October 1, 2025 07:47
@JanJakes JanJakes force-pushed the column-meta branch 2 times, most recently from d877817 to 6b05356 Compare October 1, 2025 08:18
@JanJakes JanJakes marked this pull request as ready for review October 1, 2025 08:52
@JanJakes JanJakes requested a review from adamziel October 1, 2025 08:52
@JanJakes
Copy link
Member Author

JanJakes commented Oct 1, 2025

@adamziel I've got this to a point where I think we can merge it, including plenty of tests. It would be useful to advance the Adminer, phpMyAdmin, and other tool support.

I can also create a follow-up ticket for what can be further improved (MySQLi flags, etc.). Maybe also all the mysql-type-to-something maps in the driver could be refactored to a single map aggregating all needed properties for each type, etc., but it's an implementation detail, and I don't want to delay this PR on that.

* This is used to compute the column metadata from the information schema.
*/
const COLUMN_INFO_MYSQL_TO_NATIVE_TYPES_MAP = array(
// Numeric data types:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we sort it by mysqli type within each datatype group (int, string etc)? It seems like we'll be looking up entries in this mapping by that number a little bit. Alternatively, we could create a bunch of named constants and reference them here, e.g. self::MYSQLI_BIT etc.

Copy link
Member Author

@JanJakes JanJakes Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel As we already have multiple maps in the form of mysql-type-to-something, I was thinking about consolidating them into something like this:

Screenshot 2025-10-02 at 9 54 39

It would be all in one place then, and likely more readable. Usage:

$sqlite_type      = self::MYSQL_TYPE_MAP[$type][self::KEY_SQLITE_TYPE];
$implicit_default = self::MYSQL_TYPE_MAP[$type][self::KEY_MYSQL_IMPLICIT_DEFAULT];
...

What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ticket: #259

* that have no records in the information schema (i.e., expressions).
*/
const COLUMN_INFO_SQLITE_TO_NATIVE_TYPES_MAP = array(
'NULL' => array( 'NULL', 6, 0, 0 ),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for those numbers

@adamziel
Copy link
Collaborator

adamziel commented Oct 1, 2025

Nice! Yeah let's get it in. The limitations would be also nice to document in a comment within the code as that's where we'll be looking for this information.

@JanJakes JanJakes merged commit 842d581 into develop Oct 2, 2025
14 checks passed
@JanJakes JanJakes deleted the column-meta branch October 2, 2025 13:10
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

Successfully merging this pull request may close these issues.

Provide column info
2 participants