Skip to content

add get_table_info function #204

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

havi05
Copy link

@havi05 havi05 commented Mar 2, 2025

This adds a new function to get the column names and data types of a table. The function is simply a predefined query like drop_table(). I need this query to load databases whose structure I don't know and I think this should be a separate function as the PRAGMA statement is specific to sqlite and therefore not so well known.

Please let me know your thoughts on this.

@2shady4u
Copy link
Owner

Hello @havi05 😄

Could you tell me the exact benefit of wrapping this PRAGMA as an additional method? (Instead of just defining a utility method somewhere in your Godot project)
Also why did you opt to use the table_info() instead of the table_xinfo()-method?

If I understand your use-case correctly, it seems that you want to be able to correctly load tables whose schema you don't know? But the current implementation would just return "BLOB" instead of the "PackedByteArray" type that Godot expects?

@havi05
Copy link
Author

havi05 commented Mar 13, 2025

If I understand your use-case correctly, it seems that you want to be able to correctly load tables whose schema you don't know?

Yes, to visualize the content of a database (loaded by the user) in a table and inform the user about the columns that my program cannot use (in the main aspect of the program, not in the visualizer), and to help the user to update the schema to my format when importing.

Could you tell me the exact benefit of wrapping this PRAGMA as an additional method?

While it's pretty easy to google this function from sqlite, I thought it would be handy for other developers to have a function to get this information, since it's a custom sql statement just used in sqlite (and each sql database has a different way to get this information), so you'd have to search for it instead of just finding it in the built-in documentation. Especially since Godot has a beginner friendly approach it could be useful, on the other hand new programmers probably wouldn't start with a database so it might not really be needed.

Also why did you opt to use the table_info() instead of the table_xinfo()-method?

In my quick search I found table_info() and it worked for me, so I didn't look any further, but table_xinfo() is better, so I would change that.

But the current implementation would just return "BLOB" instead of the "PackedByteArray" type that Godot expects?

When I tried it the result was an Array of Dictionarys and the typeof() function returned 28 for Array, so I thought it would be fine, but please tell me if this could be improved.


Personally, I would consider this a sort of “core” feature to easily get all the information about the tables and not just the data in them. I can also understand if you think this is a too special use case (since it's just a small utility method in gdscript and already possible), so I'd be open to your decision.

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.

2 participants