Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

Add functions to get the full database names currently in use via json-rpc and python api#27203

Open
bacon-cheeseburger wants to merge 3 commits intoxbmc:masterfrom
bacon-cheeseburger:databasenames
Open

Add functions to get the full database names currently in use via json-rpc and python api#27203
bacon-cheeseburger wants to merge 3 commits intoxbmc:masterfrom
bacon-cheeseburger:databasenames

Conversation

@bacon-cheeseburger
Copy link

Description

Add the ability to get the full database names currently in use directly from a running Kodi instance. The prior draft PR for this (#27150) was abandoned in favor of this one which uses better implementation.

Note: I had to recreate my branch and github won't let me reopen the working draft PR (#27174) so I had to make this one. Sorry for any inconvenience.

Motivation and context

In trying to bisect an issue, I've noticed that addons and external tools have a bad habit of assuming the database in use is always the newest. Even worse, sometimes they don't even consider if custom database names were set in AdvancedSettings. Either of those can be problematic. For example, if a Kodi upgrade introduced a schema version change but had to be rolled back for whatever reason, or when running multiple Kodi versions for dev/testing that may use different schema versions. Simply allowing an addon/script (via python api) or external tool (via json-rpc) to get the actual database names currently in use eliminates the problem.

How has this been tested?

Testing was done using curl from command line for the json-rpc methods, and by calling the xbmc python module functions from a simple test addon that prints the database names to a dialog. The correct names were returned in all tests.

What is the effect on users?

These changes allow an addon/script/external tool that directly accesses the database to get the actual database name it should use rather than guessing or assuming. This ensures whatever action is taken, is happening at the correct database. The addition of DatabaseOperations can be expanded for further functionality also.

Screenshots (if appropriate):

Types of change

  • Bug fix (non-breaking change which fixes an issue)
  • Clean up (non-breaking change which removes non-working, unmaintained functionality)
  • Improvement (non-breaking change which improves existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that will cause existing functionality to change)
  • Cosmetic change (non-breaking change that doesn't touch code)
  • Student submission (PR was done for educational purposes and will be treated as such)
  • None of the above (please explain below)

Checklist:

  • My code follows the Code Guidelines of this project
  • My change requires a change to the documentation, either Doxygen or wiki
  • I have updated the documentation accordingly
  • I have read the Contributing document
  • I have added tests to cover my change
  • All new and existing tests passed

Copy link
Member

@ksooo ksooo left a comment

Choose a reason for hiding this comment

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

Good to go in, from my perspective.
@bacon-cheeseburger thanks, it was a pleasure working with you.

@ksooo ksooo marked this pull request as ready for review August 31, 2025 14:39
@ksooo ksooo requested a review from DaveTBlake as a code owner August 31, 2025 14:39
@garbear garbear requested a review from Copilot September 1, 2025 01:41

This comment was marked as outdated.

@CrystalP
Copy link
Contributor

CrystalP commented Sep 1, 2025

I have to wonder about the scope of the PR. Reading a bit between the lines, the goal seems to be to provide enough information to an external program that wants to open a database used by a running Kodi instance.

The database name is not enough to establish a connection. In the case of sqlite, the path is required as well and mysql/mariadb require host name, user and password at a minimum.
The sqlite path may be altered from default by advanced settings or the use of multiple profiles by the way.

So it seems to me that the "host" part of DatabaseSettings needs to be exposed as well, probably as a tuple with the db name.
Even if Kodi is not a high security application, exposing db user name and password sounds like a no-no.

@CrystalP
Copy link
Contributor

CrystalP commented Sep 1, 2025

Also accepting a string db type is not very robust but I don't know if it's possible to define constants or enums for json or python.

@ksooo
Copy link
Member

ksooo commented Sep 4, 2025

I have to wonder about the scope of the PR.

Well, I think we need to take a step back here and first need to clarify on the points @CrystalP brought up wrt completeness of functionality, and security concerns.

@ksooo ksooo added the WIP PR that is still being worked on label Sep 4, 2025
@CrystalP
Copy link
Contributor

CrystalP commented Sep 4, 2025

If you assume the external program already has access to path/hostname/user/password through other means, then it can also know the custom base names (if any), ssl parameters, etc.
In that case, all that's missing to connect is the db version number, which is much easier to retrieve.

@bacon-cheeseburger
Copy link
Author

bacon-cheeseburger commented Sep 4, 2025

I have to wonder about the scope of the PR. Reading a bit between the lines, the goal seems to be to provide enough information to an external program that wants to open a database used by a running Kodi instance.

The database name is not enough to establish a connection. In the case of sqlite, the path is required as well and mysql/mariadb require host name, user and password at a minimum. The sqlite path may be altered from default by advanced settings or the use of multiple profiles by the way.

So it seems to me that the "host" part of DatabaseSettings needs to be exposed as well, probably as a tuple with the db name. Even if Kodi is not a high security application, exposing db user name and password sounds like a no-no.

I wasn't aware sqlite required a path to login (using mariadb here) but if so then it sounds like something to consider, especially if it can vary at the profile level.

The db name in-use is generated internally and required for db access. It can change behind-the-scene via api version change so it makes sense for a way to ask Kodi what the current db name in-use is.

The hostname could be exposed without concern imo.

I wouldn't recommend exposing login/password, if not necessarily for security but as a matter of generally bad practice. I think it's a reasonable barrier-to-entry that they know the login/password as a prerequisite without Kodi telling them.

@bacon-cheeseburger
Copy link
Author

bacon-cheeseburger commented Sep 4, 2025

If you assume the external program already has access to path/hostname/user/password through other means, then it can also know the custom base names (if any), ssl parameters, etc. In that case, all that's missing to connect is the db version number, which is much easier to retrieve.

I think it's better to provide the exact database name in-use given Kodi already knows it and there's no good reason I can see in making the user generate it themself.

@bacon-cheeseburger bacon-cheeseburger force-pushed the databasenames branch 4 times, most recently from 55b112c to f0c99ae Compare September 4, 2025 19:08
@bacon-cheeseburger
Copy link
Author

Re-did the patch set based on Ksooo's refactor.

@ksooo
Copy link
Member

ksooo commented Sep 4, 2025

[databases] Refactor CDatabase (get rid of name and version virtual methods) and add CDatabaseManager::GetDatabaseNameByType. (supplied by ksooo)

Can you please fix the commit message. It reflects what was in an earlier iteration of my work, not what is in the patch I sent you which is now part of this PR.

Should read: "[databasemanager] Add CDatabaseManager::GetDatabaseNameByType()"

@garbear garbear requested a review from Copilot September 4, 2025 21:23
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds functionality to retrieve the full database names currently in use by a running Kodi instance. The implementation provides both JSON-RPC API endpoints and Python API functions to access database names for different database types (addons, epg, music, textures, tv, videos, viewmodes).

Key changes:

  • Added database type constants and management infrastructure to track database names
  • Implemented JSON-RPC Database.GetDatabaseName method and Python xbmc.getDatabaseName() function
  • Enhanced database classes to register their type and track their actual names in use

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
xbmc/DatabaseTypes.h New header defining database type constants for consistent naming
xbmc/DatabaseManager.h Enhanced to track database details including type and actual name in use
xbmc/DatabaseManager.cpp Updated to store and retrieve database information by type
xbmc/interfaces/json-rpc/DatabaseOperations.* New JSON-RPC operations for database name retrieval
xbmc/interfaces/legacy/ModuleXbmc.* Added Python API function for database name retrieval
xbmc/dbwrappers/Database.* Modified to accept and store database type information
Various database classes Updated constructors to pass database type to base class

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@bacon-cheeseburger bacon-cheeseburger force-pushed the databasenames branch 3 times, most recently from ddc2023 to 9ab4643 Compare September 4, 2025 22:13
@jenkins4kodi jenkins4kodi added the Rebase needed PR that does not apply/merge cleanly to current base branch label Oct 4, 2025
@jenkins4kodi
Copy link
Contributor

@bacon-cheeseburger this needs a rebase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API change: JSON-RPC API change: Python Component: Database Component: JSON-RPC Rebase needed PR that does not apply/merge cleanly to current base branch Type: Improvement non-breaking change which improves existing functionality v22 Piers WIP PR that is still being worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

Comments