Functions/GenXdev.Data.SQLite/Get-SQLiteTables.ps1
|
############################################################################### <# .SYNOPSIS Retrieves a list of table names from a SQLite database. .DESCRIPTION Queries the sqlite_master system table to retrieve all user-defined table names from a SQLite database. Supports connecting via either a direct connection string or a database file path. Returns the table names as a collection of strings. .LICENSE Copyright (C) 2026 René Vaessen / GenXdev This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. .PARAMETER ConnectionString The full connection string to connect to the SQLite database. Should include the Data Source and Version parameters at minimum. .PARAMETER DatabaseFilePath The full filesystem path to the SQLite database file. The function will create an appropriate connection string internally. .EXAMPLE Get-SQLiteTables -DatabaseFilePath "C:\Databases\Inventory.sqlite" Returns all table names from the specified database file .EXAMPLE Get-SQLiteTables -ConnectionString "Data Source=C:\DB\Users.sqlite;Version=3;" Returns all table names using a custom connection string #> function Get-SQLiteTables { [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '')] [CmdletBinding(DefaultParameterSetName = 'Default')] param ( ########################################################################### [Parameter( Position = 0, Mandatory = $true, ParameterSetName = 'ConnectionString', HelpMessage = 'The connection string to the SQLite database.' )] [string]$ConnectionString, ########################################################################### [Parameter( Position = 0, Mandatory = $true, ParameterSetName = 'DatabaseFilePath', HelpMessage = 'The path to the SQLite database file.' )] [ValidateNotNullOrEmpty()] [string]$DatabaseFilePath ) begin { # log the start of table retrieval operation Microsoft.PowerShell.Utility\Write-Verbose 'Starting SQLite table name retrieval operation' } process { # define the query to get all table names from sqlite_master $PSBoundParameters['Queries'] = 'SELECT name FROM sqlite_master ' + "WHERE type='table'" # execute query using the inherited connection parameters Microsoft.PowerShell.Utility\Write-Verbose 'Executing query to retrieve table names' GenXdev\Invoke-SQLiteQuery @PSBoundParameters } end { } } |