### Open Oracle Connection with Credentials Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md This example demonstrates how to provide explicit credentials for connecting to the Oracle database. The PSCredential object should be created beforehand. ```powershell $cred = Get-Credential Open-OracleConnection -Server "your_server" -ServiceName "your_service" -Credential $cred ``` -------------------------------- ### Start-SqlTransaction Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Start-SqlTransaction.md Starts a SQL transaction (BEGIN). ```APIDOC ## Start-SqlTransaction ### Description Starts a SQL transaction (BEGIN). ### Method Start-SqlTransaction ### Parameters #### ConnectionName - **ConnectionName** (String) - Optional - User defined name for connection. Aliases: cn. Default value: default. #### Confirm - **Confirm** (SwitchParameter) - Optional - Prompts you for confirmation before running the cmdlet. Aliases: cf. #### WhatIf - **WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. The cmdlet is not run. Aliases: wi. ### CommonParameters - Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. ### Input System.String ### Output System.Object ``` -------------------------------- ### Install SimplySql Module Source: https://github.com/mithrandyr/simplysql/blob/master/README.md Installs the SimplySql module for the current user from the PowerShell Gallery. Requires PowerShell 5.0 or greater. ```powershell Install-Module SimplySql -Scope CurrentUser ``` -------------------------------- ### Open Oracle Connection with Additional Parameters Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md This example shows how to pass additional, non-standard connection parameters using a hashtable. Consult Oracle documentation for valid additional parameters. ```powershell Open-OracleConnection -Server "your_server" -ServiceName "your_service" -Additional @{ "FetchSize" = "10000" } ``` -------------------------------- ### Execute a Parameterized Query with Invoke-SqlQuery Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlQuery.md This example demonstrates how to run a query with dynamic parameters. Use the -Parameters hashtable to define and pass values for placeholders in your query. ```powershell PS C:\> Invoke-SqlQuery -Query "SELECT * FROM TABLE WHERE col1=@id' AND colb > @someDate" -Parameters @{id = 1; someDate = (Get-Date)} ``` -------------------------------- ### Display Information Message in Oracle SQL Developer Source: https://github.com/mithrandyr/simplysql/blob/master/developmentideas.txt This example demonstrates how to display an informational message within the Oracle SQL Developer worksheet. ```sql SET SERVEROUTPUT ON DECLARE v_message VARCHAR2(100) := 'Hello, World!'; BEGIN DBMS_OUTPUT.PUT_LINE(v_message); END; / ``` -------------------------------- ### Start a SQL Transaction Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Start-SqlTransaction.md Initiates a new SQL transaction using the Start-SqlTransaction cmdlet. This command is typically used to group multiple SQL operations into a single atomic unit. ```powershell Start-SqlTransaction ``` -------------------------------- ### Execute SQL Update with Object Parameters Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlUpdate.md This example demonstrates updating SQL records using parameters defined within a custom PowerShell object. The member names of the object should correspond to the parameter names in the SQL query. ```powershell PS C:\> $obj = [PSCustomObject]@{id = 549; val = 999999} PS C:\> $obj | Invoke-SqlUpdate -Query "UPDATE employees SET salary = @val WHERE manager = @id" ``` -------------------------------- ### Get All SQL Messages Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Get-SqlMessage.md This snippet retrieves all available informational messages from the message queue. Ensure you have the SimplySql module imported. ```powershell PS C:\> Get-SqlMessage ``` -------------------------------- ### Get Provider Connection Object Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Get-SqlConnection.md Use this cmdlet to retrieve the provider-specific connection object for the current or a named connection. No specific setup is required beyond having the SimplySql module loaded. ```powershell PS C:\> Get-SqlConnection ``` -------------------------------- ### Execute Scalar Query with Date Parameter Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlScalar.md This example shows how to pass a date parameter to a scalar query. The parameter is defined in a hashtable and passed to the cmdlet. ```powershell Invoke-SqlQuery -Query "SELECT Count(1) FROM TABLE WHERE colb > @someDate" -Parameters @{someDate = (Get-Date)} ``` -------------------------------- ### Initialize Git Submodules Source: https://github.com/mithrandyr/simplysql/blob/master/developmentideas.txt Ensure all git submodules, including the wiki, are properly initialized after cloning or adding. ```bash git submodule update --init ``` -------------------------------- ### Clone Project Wiki as Docs Source: https://github.com/mithrandyr/simplysql/blob/master/developmentideas.txt Use this command to clone the project's wiki into a local 'docs' folder for offline reference. ```bash git clone https://github.com/youName/ProjectName.wiki docs ``` -------------------------------- ### Basic Database Query Workflow Source: https://github.com/mithrandyr/simplysql/blob/master/README.md Demonstrates the fundamental pattern of opening a connection, executing a query, and closing the connection. Supports parameterized queries. ```powershell Open-*Connection -DataSource "SomeServer" -InitialCatalog "SomeDB" $data = Invoke-SqlQuery -query "SELECT * FROM someTable" #or using parameters $data = Invoke-SqlQuery -query "SELECT * FROM someTable WHERE someCol = @var" -Parameters @{var = 'a value'} Close-SqlConnection ``` -------------------------------- ### Create and Populate a SQLite Table Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/about_SimplySql.md Opens a SQLite connection, creates a table, and inserts file information into it using parameterized queries. The number of inserted records is tracked and displayed. ```powershell Open-SQLiteConnection Invoke-SqlUpdate -Query "CREATE TABLE test (path text, size real, created datetime)" | Out-Null $InsertQuery = "INSERT INTO test (path, size, created) VALUES (@path, @size, @created)" [int]$recordsInserted = 0 Get-ChildItem -Recurse | ForEach-Object { $recordsInserted += Invoke-SqlUpdate -Query $InsertQuery -Parameters @{ path = $_.FullName size = $_.Length created = $_.CreationTime } } Write-Host "Insert $recordsInserted" ``` -------------------------------- ### Show all SQL Connections Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Show-SqlConnection.md Use the -All parameter to list all active SQL connections. This is useful for managing multiple connections. ```powershell Show-SqlConnection -All ``` -------------------------------- ### Add Project Wiki as Git Submodule Source: https://github.com/mithrandyr/simplysql/blob/master/developmentideas.txt Integrate the project's wiki as a submodule, allowing for easier updates and management. ```bash git submodule add https://github.com/youName/ProjectName.wiki docs ``` -------------------------------- ### Get the provider transaction object Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Get-SqlTransaction.md This snippet retrieves the provider-specific transaction object for the current default connection. Use this when you need direct access to the transaction for advanced operations. ```powershell PS C:\> Get-SqlTransaction ``` -------------------------------- ### Managing Multiple Database Connections Source: https://github.com/mithrandyr/simplysql/wiki/Home Demonstrates how to open, use, and close multiple simultaneous database connections using unique connection names. This is useful for managing different database instances or configurations within the same PowerShell session. ```powershell #Open two SQLite Connections Open-SQLiteConnection Open-SQLiteConnection -cn b #-cn is the alias for -ConnectionName #create table in 1st connection and add 10 rows Invoke-SqlUpdate "CREATE TABLE tmp(val integer)" 1..10 | ForEach-Object { Invoke-SqlUpdate "INSERT INTO tmp VALUES (@v)" -Parameters @{v = $_}} #Query from the first connection Invoke-SqlQuery "SELECT * FROM tmp" Invoke-SqlQuery "SELECT * FROM tmp" -ConnectionName default #this will work too, because "default" is the name given to connections without a name #query from 2nd connection, it will fail, because the table does not exit Invoke-SqlQuery "SELECT * FROM tmp" -ConnectionName b #Close both connections Close-SqlConnection #closing the "default" Close-SqlConnection b ``` -------------------------------- ### Show-SqlConnection - single Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Show-SqlConnection.md Lists the current SqlConnection information using the default parameter set. ```APIDOC ## Show-SqlConnection - single ### Description Lists the current SqlConnection information. ### Method Cmdlet ### Endpoint Show-SqlConnection ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. Accepts pipeline input. - **CommonParameters** - Supports common PowerShell parameters like -Debug, -Verbose, etc. ``` -------------------------------- ### Basic SQLite Operations with SimplySQL Source: https://github.com/mithrandyr/simplysql/wiki/Examples Demonstrates creating a table, inserting file information, and querying data from an SQLite database using SimplySQL cmdlets. Ensure you have a connection open before running this script. ```powershell Open-SQLiteConnection Invoke-SqlUpdate -Query "CREATE TABLE test (path text, size real, created datetime)" | Out-Null $InsertQuery = "INSERT INTO test (path, size, created) VALUES (@path, @size, @created)" [int]$recordsInserted = 0 Get-ChildItem -Recurse | ForEach-Object { $recordsInserted += Invoke-SqlUpdate -Query $InsertQuery -Parameters @{path = $_.FullName; size = $_.Length; created = $_.CreationTime} } Write-Host "Insert $recordsInserted" Invoke-SqlQuery -Query "SELECT * FROM test WHERE size > @size or created < @dt" -Parameters @{size = 100kb; dt = (Get-Date).AddYears(-2)} -Stream Close-SqlConnection ``` -------------------------------- ### Show-SqlConnection - all Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Show-SqlConnection.md Outputs a list of all SqlConnections currently active using the -All parameter. ```APIDOC ## Show-SqlConnection - all ### Description Outputs a list of all SqlConnections currently active. ### Method Cmdlet ### Endpoint Show-SqlConnection ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **All** (SwitchParameter) - Required - If present, will return list of all connection names. - **CommonParameters** - Supports common PowerShell parameters like -Debug, -Verbose, etc. ``` -------------------------------- ### Open-SQLConnection - ConnectionString Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a SQL Server connection using a provided connection string, supporting both credentials and Azure Token. ```APIDOC ## Open-SQLConnection - ConnectionString ### Description Opens a connection to a SQL Server using a provided connection string. This method can also accept credentials or an Azure Token. ### Method Cmdlet ### Endpoint N/A (PowerShell Cmdlet) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **ConnectionString** (String) - Required - Specifies a provider specific connectionstring to be used. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). - **AzureToken** (String) - Optional - Pass in Azure Token (make sure you use the proper resource). If your token begins with "bearer " that will be stripped off first. - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. ### Request Example ```powershell $connString = "Server=your_server;Database=your_database;User ID=your_user;Password=your_password;" Open-SQLConnection -ConnectionString $connString ``` ### Response #### Success Response Returns a connection object. #### Response Example ```powershell # Connection object details would be displayed here ``` ``` -------------------------------- ### Open MySQL Connection with Server and Database Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-MySqlConnection.md Opens a connection to a MySQL server using specified server and database names. It prompts the user for credentials. ```powershell PS C:\> Open-MySqlConnection -server 'localhost' -database 'DBname' -Credential (Get-Credential) ``` -------------------------------- ### Open Oracle Connection using Connection String Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md Use this syntax to provide a full Oracle connection string. This offers flexibility for complex connection configurations. ```powershell Open-OracleConnection -ConnectionString "Data Source=your_server:1521/your_service;User ID=your_user;Password=your_password;" ``` -------------------------------- ### Open-PostGreConnection Cmdlet Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-PostGreConnection.md This cmdlet opens a connection to a PostgreSQL database. It supports two parameter sets: 'default' for general connection parameters and 'conn' for establishing a connection using a connection string. ```APIDOC ## Open-PostGreConnection ### Description Open a connection to a PostGre Database. ### Syntax #### default (Default) ``` Open-PostGreConnection [-ConnectionName ] [-CommandTimeout ] [[-Server] ] [[-Database] ] [-Port ] [-MaxAutoPrepare ] [-SSLMode ] [[-Credential] ] [-Additional ] [] ``` #### conn ``` Open-PostGreConnection [-ConnectionName ] [-CommandTimeout ] [[-Credential] ] -ConnectionString [] ``` ### Parameters #### -Additional Hashtable to provide additional connection parameters. - **Type**: Hashtable - **Parameter Sets**: default - **Required**: False - **Position**: Named #### -CommandTimeout The default command timeout to be used for all commands executed against this connection. - **Type**: Int32 - **Parameter Sets**: (All) - **Required**: False - **Position**: Named - **Default value**: 30 #### -ConnectionName User defined name for connection. - **Type**: String - **Parameter Sets**: (All) - **Required**: False - **Position**: Named - **Default value**: default #### -ConnectionString Specifies a provider specific connectionstring to be used. - **Type**: String - **Parameter Sets**: conn - **Required**: True - **Position**: Named #### -Credential A PSCredential object providing the proper credentials to access to the datasource (if required). - **Type**: PSCredential - **Parameter Sets**: (All) - **Required**: False - **Position**: 2 #### -Database Database name. - **Type**: String - **Parameter Sets**: default - **Required**: False - **Position**: 1 - **Default value**: postgres #### -MaxAutoPrepare The maximum number SQL statements that can be automatically prepared at any given point. Beyond this number the least-recently-used statement will be recycled. Zero disables automatic preparation. DEFAULTS TO 25. - **Type**: Int32 - **Parameter Sets**: default - **Required**: False - **Position**: Named - **Default value**: 25 #### -Port Port to connect on, if different from default (5432). - **Type**: Int32 - **Parameter Sets**: default - **Required**: False - **Position**: Named - **Default value**: 5432 #### -Server The Server for the connection. - **Type**: String - **Parameter Sets**: default - **Required**: False - **Position**: 0 - **Default value**: localhost #### -SSLMode Which SLLMode to use (defaults to Preferred) Disabled: Do not use SSL. Preferred: Use SSL if the server supports it. Required: Always use SSL. Deny connection if server does not support SSL. Does not validate CA or hostname. VerifyCA: Always use SSL. Validates the CA but tolerates hostname mismatch. VerifyFull: Always use SSL. Validates CA and hostname. - **Type**: String - **Parameter Sets**: default - **Required**: False - **Position**: Named - **Accepted values**: Disable, Prefer, Require, VerifyCA, VerifyFull ### CommonParameters This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ### Inputs System.String System.Int32 System.Management.Automation.PSCredential System.Collections.Hashtable ### Outputs System.Object ``` -------------------------------- ### Run a Simple Query with Invoke-SqlQuery Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlQuery.md Use this to execute a basic SQL query and retrieve all results. Ensure the query syntax is valid for your target database. ```powershell PS C:\> Invoke-SqlQuery -Query "SELECT * FROM TABLE" ``` -------------------------------- ### Test-SqlConnection (all) Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Test-SqlConnection.md Checks if any SQL Server connections are configured and available. Returns true if at least one connection exists, otherwise false. ```APIDOC ## Test-SqlConnection - All ### Description Checks if any SQL Server connections are configured and available. Returns true if at least one connection exists, otherwise false. ### Method Invoke-Command (or equivalent PowerShell execution) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **All** (SwitchParameter) - Required - Returns true if there are any connections, otherwise false. ### Common Parameters Supports common PowerShell parameters like -Debug, -ErrorAction, -Verbose, etc. ``` -------------------------------- ### Open SQL Server Connection with Additional Parameters Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Connects to a SQL Server and provides additional connection parameters via a hashtable. This allows for advanced configuration options not directly exposed as parameters. ```powershell Open-SQLConnection -Server "localhost" -Database "master" -Additional @{"ApplicationIntent"="ReadOnly"} ``` -------------------------------- ### Open-MySqlConnection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-MySqlConnection.md Opens a connection to a MySql Database. This cmdlet supports two parameter sets: 'default' for general connection parameters and 'conn' for establishing a connection using a connection string. ```APIDOC ## Open-MySqlConnection ### Description Opens a connection to a MySql Database. ### Method Cmdlet ### Parameters #### Default Parameter Set - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **Server** (String) - Optional - The Server for the connection. Default value: localhost. - **Database** (String) - Optional - Database name. Default value: mysql. - **Port** (Int32) - Optional - Port to connect on, if different from default (3306). Default value: 3306. - **SSLMode** (String) - Optional - Which SLLMode to use (defaults to Preferred). Accepted values: None, Preferred, Required, VerifyCA, VerifyFull. Default value: Preferred. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. #### Connection String Parameter Set - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **ConnectionString** (String) - Required - Specifies a provider specific connectionstring to be used. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). ### Example ```powershell Open-MySqlConnection -server 'localhost' -database 'DBname' -Credential (Get-Credential) ``` Opens a connection to localhost using a credential retrieved from the user. ``` -------------------------------- ### Open-SQLConnection - Default Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a SQL Server connection using default Windows Integrated Authentication. It allows specifying server, database, command timeout, and additional connection parameters. ```APIDOC ## Open-SQLConnection - Default ### Description Opens a connection to a SQL Server using default Windows Integrated Authentication. Allows specifying server, database, command timeout, and additional connection parameters. ### Method Cmdlet ### Endpoint N/A (PowerShell Cmdlet) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **Server** (String) - Optional - The server to connect to. Default value: localhost. - **Database** (String) - Optional - The database to connect to. Default value: master. - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. ### Request Example ```powershell Open-SQLConnection -Server "your_server" -Database "your_database" ``` ### Response #### Success Response Returns a connection object. #### Response Example ```powershell # Connection object details would be displayed here ``` ``` -------------------------------- ### Open-SQLConnection - Token Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a SQL Server connection using an Azure Token for authentication. ```APIDOC ## Open-SQLConnection - Token ### Description Opens a connection to a SQL Server using an Azure Token for authentication. The token can be provided directly. ### Method Cmdlet ### Endpoint N/A (PowerShell Cmdlet) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **Server** (String) - Optional - The server to connect to. Default value: localhost. - **Database** (String) - Optional - The database to connect to. Default value: master. - **AzureToken** (String) - Optional - Pass in Azure Token (make sure you use the proper resource). If your token begins with "bearer " that will be stripped off first. - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. ### Request Example ```powershell Open-SQLConnection -Server "your_server" -Database "your_database" -AzureToken "your_bearer_token" ``` ### Response #### Success Response Returns a connection object. #### Response Example ```powershell # Connection object details would be displayed here ``` ``` -------------------------------- ### Open SQLite Connection with Additional Parameters Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a connection to a SQLite database and provides additional, custom connection parameters via a hashtable. This is useful for advanced configurations not covered by standard parameters. ```powershell Open-SQLiteConnection -DataSource "C:\path\to\your\database.db" -Additional @{JournalMode='WAL'; ForeignKeys=On} ``` -------------------------------- ### Open SQL Server Connection with Connection String Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Connects to a SQL Server using a provided connection string. This method is flexible and can include various parameters for authentication and configuration. ```powershell Open-SQLConnection -ConnectionString "Server=your_server;Database=your_database;User ID=your_user;Password=your_password;" ``` -------------------------------- ### Show a Specific SQL Connection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Show-SqlConnection.md List information for a specific SQL connection by providing its name using the -ConnectionName parameter. Defaults to 'default' if no name is specified. ```powershell Show-SqlConnection -ConnectionName "MyConnection" ``` -------------------------------- ### Open SQL Server Connection with Azure Token Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a connection to a SQL Server using an Azure token. The token should be for the correct resource, and any leading "bearer " will be automatically stripped. ```powershell Open-SQLConnection -Server "your_azure_sql.database.windows.net" -Database "your_database" -AzureToken "your_bearer_token" ``` -------------------------------- ### Open-SQLConnection - Credential Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a SQL Server connection using provided credentials (e.g., username/password) and supports Azure AD authentication for Azure SQL Databases. ```APIDOC ## Open-SQLConnection - Credential ### Description Opens a connection to a SQL Server using provided credentials. Supports Azure AD authentication for Azure SQL Databases when the -AzureAD switch is used. ### Method Cmdlet ### Endpoint N/A (PowerShell Cmdlet) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **Server** (String) - Optional - The server to connect to. Default value: localhost. - **Database** (String) - Optional - The database to connect to. Default value: master. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). - **AzureAD** (SwitchParameter) - Optional - Use this when connecting to an Azure SQL Database and you are using Azure AD credentials. - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. ### Request Example ```powershell $cred = Get-Credential "username" Open-SQLConnection -Server "your_server" -Database "your_database" -Credential $cred -AzureAD ``` ### Response #### Success Response Returns a connection object. #### Response Example ```powershell # Connection object details would be displayed here ``` ``` -------------------------------- ### Open Oracle Connection using Server and Service Name Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md Use this syntax to open a connection by specifying the server host and the Oracle service name. The command timeout defaults to 30 seconds. ```powershell Open-OracleConnection -Server "your_server" -ServiceName "your_service" -CommandTimeout 60 ``` -------------------------------- ### Open-SQLiteConnection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a connection to a SQLite database file. It supports two parameter sets: 'default' for specifying data source and password, and 'conn' for providing a full connection string. ```APIDOC ## Open-SQLiteConnection ### Description Opens a connection to a SQLite database file. ### Method Cmdlet ### Syntax #### default Open-SQLiteConnection [-ConnectionName ] [-CommandTimeout ] [[-DataSource] ] [[-Password] ] [-Additional ] [] #### conn Open-SQLiteConnection [-ConnectionName ] [-CommandTimeout ] [-ConnectionString ] [] ### Parameters #### -Additional Type: Hashtable Description: Hashtable to provide additional connection parameters. Required: False Position: Named Default value: None Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False #### -CommandTimeout Type: Int32 Description: The default command timeout to be used for all commands executed against this connection. Required: False Position: Named Default value: 30 Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False #### -ConnectionName Type: String Description: User defined name for connection. Required: False Position: Named Default value: default Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False #### -ConnectionString Type: String Description: Specifies a provider specific connectionstring to be used. Required: False Position: Named Default value: None Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False #### -DataSource Type: String Description: The datasource for the connection. Required: False Position: 0 Default value: :memory: Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False #### -Password Type: String Description: Password for the database file. Required: False Position: 1 Default value: None Accept pipeline input: True (ByPropertyName) Accept wildcard characters: False ### CommonParameters Supports common parameters like -Debug, -ErrorAction, -Verbose, etc. ``` -------------------------------- ### Open SQL Server Connection with Default Authentication Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Establishes a connection to a SQL Server using default Windows Integrated Authentication. This is suitable for local development or environments where Windows authentication is configured. ```powershell Open-SQLConnection -Server "localhost" -Database "master" ``` -------------------------------- ### Execute SQL Update with Parameters Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlUpdate.md Use this snippet to update records in a SQL table using parameterized queries. Provide parameters as a hashtable to prevent SQL injection and improve readability. ```powershell PS C:\> Invoke-SqlUpdate -Query "UPDATE employees SET salary = @val WHERE manager = @managerId" -Parameters @{val = 999999; managerId = 549} ``` -------------------------------- ### Execute a Simple Scalar Query Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlScalar.md This snippet demonstrates how to execute a basic scalar query to count rows in a table. No parameters are needed for this simple query. ```powershell Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE" ``` -------------------------------- ### Invoke-SqlBulkCopy - Table Syntax Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlBulkCopy.md Use this syntax to perform a bulk copy from a source table to a destination table. Ensure connection names and table names are correctly specified. Column mapping can be used to align source and destination columns. ```powershell Invoke-SqlBulkCopy -SourceConnectionName -DestinationConnectionName -DestinationTable -SourceTable [-ColumnMap ] [-BatchSize ] [-BatchTimeout ] [-Notify] [-NotifyAction ] [-WhatIf] [-Confirm] [] ``` -------------------------------- ### Invoke-SqlQuery - Hashtable Syntax Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlQuery.md Executes a query and returns data, allowing parameters to be passed as a hashtable. This is useful for queries with multiple named parameters. ```APIDOC ## Invoke-SqlQuery - Hashtable Syntax ### Description Executes a query and returns data, allowing parameters to be passed as a hashtable. This is useful for queries with multiple named parameters. ### Method Invoke-SqlQuery ### Parameters #### Path Parameters - **ConnectionName** (String) - Optional - The name of the connection to use. - **Query** (String[]) - Required - The SQL query to execute. - **Parameters** (Hashtable) - Required - A hashtable containing the parameters for the query. - **CommandTimeout** (Int32) - Optional - The command timeout in seconds. - **Stream** (Switch) - Optional - If used, only the first result set is returned and the output is a PSObject for each row. - **AsDataTable** (Switch) - Optional - Returns the output as a DataTable. - **UseTypesFromProvider** (Switch) - Optional - Uses types from the provider. ### Examples #### Example 2: Query with Parameters via Hashtable ```powershell Invoke-SqlQuery -Query "SELECT * FROM TABLE WHERE col1=@id' AND colb > @someDate" -Parameters @{id = 1; someDate = (Get-Date)} ``` ``` -------------------------------- ### Invoke-SqlBulkCopy - Query Syntax Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlBulkCopy.md This syntax is used for bulk copying data resulting from a query to a destination table. A destination table must be specified when using a source query. Source query parameters can also be provided. ```powershell Invoke-SqlBulkCopy -SourceConnectionName -DestinationConnectionName -DestinationTable -SourceQuery [-SourceParameters ] [-ColumnMap ] [-BatchSize ] [-BatchTimeout ] [-Notify] [-NotifyAction ] [-WhatIf] [-Confirm] [] ``` -------------------------------- ### Set-SqlConnection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Set-SqlConnection.md Configures the default database and command timeout for a SQL connection. The database can be changed, but this may not be valid for all providers. The command timeout specifies the default duration for all commands executed against the connection. ```APIDOC ## Set-SqlConnection ### Description Set Database and/or Command Timeout for the SqlConnection. Changing the database may not be valid for all providers. ### Method Cmdlet ### Endpoint Set-SqlConnection ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. - **Database** (String) - Optional - The database to connect to. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. - **WhatIf** (SwitchParameter) - Optional - Shows what would happen if the cmdlet runs. The cmdlet is not run. - **Confirm** (SwitchParameter) - Optional - Prompts you for confirmation before running the cmdlet. ### Request Example ```powershell Set-SqlConnection -ConnectionName "MyConnection" -Database "NewDB" -CommandTimeout 60 ``` ### Response #### Success Response This cmdlet does not return a value. #### Response Example None ``` -------------------------------- ### Open-OracleConnection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md Opens a connection to an Oracle Database using different parameter sets for flexibility. ```APIDOC ## Open-OracleConnection ### Description Opens a connection to an Oracle Database. ### Method Cmdlet ### Parameters #### Default Parameter Set - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **Server** (String) - Optional - The datasource for the connection. Default value: localhost. - **ServiceName** (String) - Optional - Oracle ServiceName (SID). - **Port** (Int32) - Optional - Port to connect on, if different from default (1521). Default value: 1521. - **Privilege** (String) - Optional - Determines the elevated privileges the connection has: SYSDBA, SYSOPER, SYSASM. By default, none. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. #### TNS Parameter Set - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **TnsName** (String) - Required - The TnsName to connect to. - **Privilege** (String) - Optional - Determines the elevated privileges the connection has: SYSDBA, SYSOPER, SYSASM. By default, none. - **Credential** (PSCredential) - Optional - A PSCredential object providing the proper credentials to access to the datasource (if required). - **Additional** (Hashtable) - Optional - Hashtable to provide additional connection parameters. #### ConnectionString Parameter Set - **ConnectionName** (String) - Optional - User defined name for connection. - **CommandTimeout** (Int32) - Optional - The default command timeout to be used for all commands executed against this connection. Default value: 30. - **ConnectionString** (String) - Required - Specifies a provider specific connectionstring to be used. - **Privilege** (String) - Optional - Determines the elevated privileges the connection has: SYSDBA, SYSOPER, SYSASM. By default, none. ### Common Parameters Supports common parameters like -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. ``` -------------------------------- ### Invoke-SqlQuery - Default Syntax Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlQuery.md Executes a query and returns data using the default object output. This syntax is suitable for basic queries without explicit parameter objects. ```APIDOC ## Invoke-SqlQuery - Default Syntax ### Description Executes a query and returns data using the default object output. This syntax is suitable for basic queries without explicit parameter objects. ### Method Invoke-SqlQuery ### Parameters #### Path Parameters - **ConnectionName** (String) - Optional - The name of the connection to use. - **Query** (String[]) - Required - The SQL query to execute. - **CommandTimeout** (Int32) - Optional - The command timeout in seconds. - **ParamObject** (PSObject) - Optional - An object containing parameters for the query. - **Stream** (Switch) - Optional - If used, only the first result set is returned and the output is a PSObject for each row. - **AsDataTable** (Switch) - Optional - Returns the output as a DataTable. - **UseTypesFromProvider** (Switch) - Optional - Uses types from the provider. ### Examples #### Example 1: Simple Query ```powershell Invoke-SqlQuery -Query "SELECT * FROM TABLE" ``` #### Example 2: Query with Parameters via Object ```powershell $obj = [PSCustomObject]@{id = 1; sd = (Get-date)} $obj | Invoke-SqlQuery -Query "SELECT * FROM TABLE WHERE col1=@id' AND colb > @someDate" ``` ``` -------------------------------- ### Open SQLite Connection with ConnectionString Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a connection to a SQLite database using a provided connection string. This method is more flexible for specifying various connection properties. ```powershell Open-SQLiteConnection -ConnectionString "Data Source=C:\path\to\your\database.db;Version=3;" ``` -------------------------------- ### Open Oracle Connection with SYSDBA Privilege Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md This syntax allows opening a connection with elevated SYSDBA privileges. Use with caution and ensure proper authorization. ```powershell Open-OracleConnection -Server "your_server" -ServiceName "your_service" -Privilege "SYSDBA" ``` -------------------------------- ### Open SQLite Connection with DataSource Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a connection to a SQLite database file using the DataSource parameter. This is useful for connecting to a persistent database file. ```powershell Open-SQLiteConnection -DataSource "C:\path\to\your\database.db" ``` -------------------------------- ### Set SqlConnection Database Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Set-SqlConnection.md This snippet demonstrates how to change the database associated with an existing SQL connection. Note that changing the database might not be supported by all SQL providers. ```powershell Set-SqlConnection -ConnectionName "MyConnection" -Database "NewDatabase" ``` -------------------------------- ### Open SQLite Connection with Custom Timeout and Name Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a connection to a SQLite database with a specified command timeout and a custom connection name. This allows for better management and control over database operations. ```powershell Open-SQLiteConnection -DataSource "C:\path\to\your\database.db" -CommandTimeout 60 -ConnectionName "MyDbConnection" ``` -------------------------------- ### Open SQL Server Connection with Custom Command Timeout Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Opens a connection with a specified command timeout. This is useful when dealing with long-running queries that might exceed the default timeout. ```powershell Open-SQLConnection -Server "localhost" -Database "master" -CommandTimeout 120 ``` -------------------------------- ### Execute Scalar Query with Object Parameter Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlScalar.md This snippet illustrates using a PSCustomObject to supply parameters for a scalar query. The object's member names must match the query parameter names. ```powershell $obj = [PSCustomObject]@{sd = (Get-date)} $obj | Invoke-SqlScalar -Query "SELECT Count(1) FROM TABLE WHERE colb> @sd" ``` -------------------------------- ### Test-SqlConnection (single) Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Test-SqlConnection.md Tests a specific SQL Server connection by its name. If the -Detailed switch is present, it also checks if the connection is in an Open state. ```APIDOC ## Test-SqlConnection - ConnectionName ### Description Tests a specific SQL Server connection by its name. If the -Detailed switch is present, it also checks if the connection is in an Open state. ### Method Invoke-Command (or equivalent PowerShell execution) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **ConnectionName** (String) - Optional - User defined name for connection. Aliases: cn. Default value: default. - **Detailed** (SwitchParameter) - Optional - If present, will only return return if connection is found and in an Open state. ### Common Parameters Supports common PowerShell parameters like -Debug, -ErrorAction, -Verbose, etc. ``` -------------------------------- ### Invoke-SqlBulkCopy - query Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlBulkCopy.md Performs a bulk copy operation from a source query to a destination table. Supports source parameters, column mapping, batching, and notifications. ```APIDOC ## Invoke-SqlBulkCopy - query ### Description Executes a bulk copy operation from a source query to a destination table. ### Method Invoke-SqlBulkCopy ### Parameters #### Parameters - **SourceConnectionName** (String) - The name of the source SQL connection. - **DestinationConnectionName** (String) - The name of the destination SQL connection. - **DestinationTable** (String) - The name of the destination table. Required when using SourceQuery. - **SourceQuery** (String[]) - An array of strings representing the SQL query to execute on the source. - **SourceParameters** (Hashtable) - A hash table of parameters for the source query. - **ColumnMap** (Hashtable) - A hash table to map columns between source and destination. - **BatchSize** (Int32) - The number of rows to copy in each batch. - **BatchTimeout** (Int32) - The timeout in seconds for each batch operation. - **Notify** - Switch parameter to enable row count notifications. - **NotifyAction** (System.Action`1[System.Int64]) - An action to perform when a row count notification is received. - **WhatIf** - Shows what would happen if the cmdlet runs. - **Confirm** - Prompts you for confirmation before running the cmdlet. ### Considerations * You must specify either a SourceConnectionName or DestinationConnectionName, whichever one is not specified will use 'default'. * DestinationTable is required if you use SourceQuery. * If you specify ColumnMap and SourceQuery, the select against the SourceConnection will be limited to the columns you specified in ColumnMap. Returns the number of rows copied. ``` -------------------------------- ### Open In-Memory SQLite Connection Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLiteConnection.md Opens a temporary, in-memory SQLite database connection. Data in this connection is lost when the connection is closed. ```powershell Open-SQLiteConnection ``` -------------------------------- ### Open SQL Server Connection with Azure AD Credentials Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-SQLConnection.md Connects to an Azure SQL Database using Azure Active Directory credentials. Ensure you provide a valid PSCredential object for authentication. ```powershell Open-SQLConnection -Server "your_azure_sql.database.windows.net" -Database "your_database" -Credential (Get-Credential) -AzureAD ``` -------------------------------- ### Invoke-SqlBulkCopy - table Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlBulkCopy.md Performs a bulk copy operation from a source table to a destination table using specified connection names. Supports column mapping, batch size, and batch timeout. ```APIDOC ## Invoke-SqlBulkCopy - table ### Description Executes a bulk copy operation from a source table to a destination table. ### Method Invoke-SqlBulkCopy ### Parameters #### Parameters - **SourceConnectionName** (String) - The name of the source SQL connection. - **DestinationConnectionName** (String) - The name of the destination SQL connection. - **DestinationTable** (String) - The name of the destination table. - **SourceTable** (String) - The name of the source table. - **ColumnMap** (Hashtable) - A hash table to map columns between source and destination. - **BatchSize** (Int32) - The number of rows to copy in each batch. - **BatchTimeout** (Int32) - The timeout in seconds for each batch operation. - **Notify** - Switch parameter to enable row count notifications. - **NotifyAction** (System.Action`1[System.Int64]) - An action to perform when a row count notification is received. - **WhatIf** - Shows what would happen if the cmdlet runs. - **Confirm** - Prompts you for confirmation before running the cmdlet. ### Considerations * You must specify either a SourceConnectionName or DestinationConnectionName, whichever one is not specified will use 'default'. * If you don't specify DestinationTable, it will use SourceTable. * If you specify ColumnMap and SourceTable, the select against the SourceConnection will be limited to the columns you specified in ColumnMap. Returns the number of rows copied. ``` -------------------------------- ### Open Oracle Connection using TNS Name Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Open-OracleConnection.md This syntax is for connecting to an Oracle database using a TNS name defined in your tnsnames.ora file. Ensure the TNS name is correctly configured. ```powershell Open-OracleConnection -TnsName "your_tns_entry" ``` -------------------------------- ### Pass Parameters via Object Piping to Invoke-SqlQuery Source: https://github.com/mithrandyr/simplysql/blob/master/Docs/Invoke-SqlQuery.md This snippet shows how to pipe an object to Invoke-SqlQuery, where its properties are automatically converted into query parameters. This is useful for executing the same query with different sets of parameters derived from objects. ```powershell PS C:\> $obj = [PSCustomObject]@{id = 1; sd = (Get-date)} PS C:\> $obj | Invoke-SqlQuery -Query "SELECT * FROM TABLE WHERE col1=@id' AND colb > @someDate" ```