en-US/about_SimplySql.help.txt
TOPIC
about_simplysql SHORT DESCRIPTION SimplySql - Talking to relational databases the PowerShell way. Simple commands... Powerful opportunities. LONG DESCRIPTION SimplySql is a module that provides an intuitive set of cmdlets for talking to databases that abstracts the vendor specifics, allowing you to focus on getting work done. The basic pattern is to connect to a database, execute one or more sql statements and then close your database connection. This module provides cmdlets that map to this basic pattern. Open/Close/Show/Test/Set/Get -SqlConnection - Open/Close cmdlets enable you to connect to databases in straightforward terms without worrying about differences between database vendors. There is a specific "Open-*" cmdlet for each provider. (Open-SqlConnection, Open-SQLiteConnection, Open-OracleConnection, Open-PostGreConnection, Open-MySqlConnection). - Show/Test cmdlets allow you to see what connections are currently active in your powershell session and see specific details about those connections. - Set cmdlet allows you to change the default commandTimeout and the database/catalog in use (if the provider supports it). - Get cmdlet returns the underlying connection object itself. Invoke- SqlScalar/SqlQuery/SqlUpdate - These cmdlets allow you to execute sql statements against the database connections that you have opened. Any type of statement can be used with any cmdlet, but the output is tailored to specific types of activity. - SqlScalar is great for returning a single value. - SqlQuery is used for returning one or more result sets (output is DataRow for single resultset and Table for multiple resultsets). You can use the switch -Stream to return PSObject instead of DataRow. - SqlUpdate is used for making modifications (insert, update, delete, etc) and its output is the number of rows effected. Get/Clear -SqlMessage - These cmdlets provider access to informational messages, if the provider supports them. - Get will return the messages generated by Invoke-SqlScalar/SqlQuery/SqlUpdate cmdlets. Messages are consumed as they are read and can be cleared, without reading, by calling the Clear cmdlet. - The messages are timestamped to when they were received by calling command (and not necessarily when they were generated on the server since many implementations are Asynchronous.) Invoke-SqlBulkCopy - This is intended to make moving data from one connection to another connection (even cross vendor) simple. This is highly optimized for all providers. Start/Complete/Undo -SqlTransaction - These cmdlets provide a simple way to wrap Invoke-Sql* (except for SqlBulkCopy) into a transaction and then either commit or rollback. - Complete-SqlTransaction maps to COMMIT and Undo-SqlTransaction maps to ROLLBACK. EXAMPLES 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" $query = "SELECT * FROM test WHERE size > @size or created < @dt" Invoke-SqlQuery -Query $query -Parameters @{ size = 100kb dt = (Get-Date).AddYears(-2) } -Stream Close-SqlConnection SEE ALSO about_SimplySql_Providers KEYWORDS SimplySql |