Updated SqlBuilder

This commit is contained in:
2025-09-05 17:13:47 -05:00
parent fb4107117c
commit 9146e698c9
2 changed files with 251 additions and 36 deletions

View File

@@ -196,6 +196,18 @@ namespace DbTools.Model {
return SqlScript;
}
/// <summary>
/// Imports the schema and metadata from the connected SQLite database into the application's internal
/// structures.
/// </summary>
/// <remarks>This method reads the SQLite database schema, including tables, indexes, and
/// triggers, and populates the application's internal collections with the corresponding metadata. It
/// processes the `sqlite_master` table to extract the necessary information and organizes it into tables,
/// indexes, and triggers. <para> The method clears any existing table metadata before importing new data. It
/// also formats the SQL definitions for tables to improve readability. </para> <para> This method assumes that
/// the database connection is already open and accessible. Ensure that the connection is valid before calling
/// this method. </para></remarks>
/// <returns><see langword="true"/> if the import operation completes successfully.</returns>
private bool importFromSqlite() {
DbConnection.Open();
Tables.Clear();
@@ -264,6 +276,16 @@ namespace DbTools.Model {
return true;
}
/// <summary>
/// Appends index definitions to the corresponding tables in the database schema.
/// </summary>
/// <remarks>This method updates the <c>Indexes</c> collection of each table in the <c>Tables</c>
/// dictionary with the provided index definitions. If a table does not exist in the <c>Tables</c> dictionary,
/// it is skipped. Only valid index definitions (those containing both a name and a SQL definition) are
/// added.</remarks>
/// <param name="indexes">A dictionary where the key is the name of a table, and the value is a list of index definitions. Each index
/// definition is a semicolon-separated string, where the first part is the index name and the second part is
/// the index SQL definition.</param>
private void appendIndexes(Dictionary<string, List<string>> indexes) {
foreach (string index in indexes.Keys) {
Table table = Tables[index];
@@ -278,6 +300,16 @@ namespace DbTools.Model {
}
}
/// <summary>
/// Appends trigger definitions to the corresponding tables in the database schema.
/// </summary>
/// <remarks>This method updates the <see cref="Table.Triggers"/> collection for each table
/// specified in the <paramref name="triggers"/> dictionary. If a table does not exist in the <see
/// cref="Tables"/> collection, it is skipped. Only trigger definitions with a valid format (name and SQL body
/// separated by a semicolon) are added.</remarks>
/// <param name="triggers">A dictionary where each key represents the name of a table, and the associated value is a list of trigger
/// definitions for that table. Each trigger definition is a string containing the trigger name and its SQL
/// body, separated by a semicolon.</param>
private void appendTriggers(Dictionary<string, List<string>> triggers) {
foreach (string trigger in triggers.Keys) {
Table table = Tables[trigger];