diff --git a/PSSQLite/Invoke-SqliteBulkCopy.ps1 b/PSSQLite/Invoke-SqliteBulkCopy.ps1 index 576fe88..4e3fcae 100644 --- a/PSSQLite/Invoke-SqliteBulkCopy.ps1 +++ b/PSSQLite/Invoke-SqliteBulkCopy.ps1 @@ -23,6 +23,9 @@ .PARAMETER SQLiteConnection An existing SQLiteConnection to use. We do not close this connection upon completed query. +.PARAMETER ConnectionStringOptions + Optional string to append custom options to the SQLite connection string. For example, use 'DateTimeFormat=JulianDay' to enable Julian day date handling. Do not include a leading semicolon; it will be added automatically if needed. + .PARAMETER ConflictClause The conflict clause to use in case a conflict occurs during insert. Valid values: Rollback, Abort, Fail, Ignore, Replace @@ -107,15 +110,23 @@ [string] $DataSource, - [Parameter( ParameterSetName = 'Connection', - Position=1, - Mandatory=$true, - ValueFromPipeline=$false, - ValueFromPipelineByPropertyName=$true, - ValueFromRemainingArguments=$false )] - [Alias( 'Connection', 'Conn' )] - [System.Data.SQLite.SQLiteConnection] - $SQLiteConnection, + [Parameter( ParameterSetName = 'Connection', + Position=1, + Mandatory=$true, + ValueFromPipeline=$false, + ValueFromPipelineByPropertyName=$true, + ValueFromRemainingArguments=$false )] + [Alias( 'Connection', 'Conn' )] + [System.Data.SQLite.SQLiteConnection] + $SQLiteConnection, + + [Parameter( ParameterSetName = 'Datasource', + Position=2, + Mandatory=$false, + ValueFromPipelineByPropertyName=$true, + ValueFromRemainingArguments=$false )] + [string] + $ConnectionStringOptions, [parameter( Position=2, Mandatory = $true)] @@ -234,6 +245,13 @@ } $ConnectionString = "Data Source={0}" -f $Database + if ($ConnectionStringOptions) { + if ($ConnectionStringOptions.StartsWith(';')) { + $ConnectionString += $ConnectionStringOptions + } else { + $ConnectionString += ";$ConnectionStringOptions" + } + } $SQLiteConnection = New-Object System.Data.SQLite.SQLiteConnection -ArgumentList $ConnectionString $SQLiteConnection.ParseViaFramework = $true #Allow UNC paths, thanks to Ray Alex! } diff --git a/PSSQLite/Invoke-SqliteQuery.ps1 b/PSSQLite/Invoke-SqliteQuery.ps1 index 90f61e1..c8b592f 100644 --- a/PSSQLite/Invoke-SqliteQuery.ps1 +++ b/PSSQLite/Invoke-SqliteQuery.ps1 @@ -43,6 +43,9 @@ .PARAMETER AppendDataSource If specified, append the SQLite data source path to PSObject or DataRow output + .PARAMETER ConnectionStringOptions + Optional string to append custom options to the SQLite connection string. For example, use 'DateTimeFormat=JulianDay' to enable Julian day date handling. + .INPUTS DataSource You can pipe DataSource paths to Invoke-SQLiteQuery. The query will execute against each Data Source. @@ -278,7 +281,10 @@ ValueFromRemainingArguments=$false )] [Alias( 'Connection', 'Conn' )] [System.Data.SQLite.SQLiteConnection] - $SQLiteConnection + $SQLiteConnection, + [Parameter(Position=8, Mandatory=$false)] + [string] + $ConnectionStringOptions ) Begin @@ -421,11 +427,19 @@ } else { - Write-Verbose "Creating andn querying Data Source '$Database'" + Write-Verbose "Creating and querying Data Source '$Database'" } $ConnectionString = "Data Source={0}" -f $Database + if ($ConnectionStringOptions) { + if ($ConnectionStringOptions.StartsWith(';')) { + $ConnectionString += $ConnectionStringOptions + } else { + $ConnectionString += ";$ConnectionStringOptions" + } + } + $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentList $ConnectionString $conn.ParseViaFramework = $true #Allow UNC paths, thanks to Ray Alex! Write-Debug "ConnectionString $ConnectionString" diff --git a/PSSQLite/New-SqliteConnection.ps1 b/PSSQLite/New-SqliteConnection.ps1 index 9da0d9d..7d23567 100644 --- a/PSSQLite/New-SqliteConnection.ps1 +++ b/PSSQLite/New-SqliteConnection.ps1 @@ -18,6 +18,9 @@ .PARAMETER ReadOnly If specified, open SQLite data source as read only + .PARAMETER ConnectionStringOptions + Optional string to append custom options to the SQLite connection string. For example, use 'DateTimeFormat=JulianDay' to enable Julian day date handling. + .PARAMETER Open We open the connection by default. You can use this parameter to create a connection without opening it. @@ -83,12 +86,18 @@ [Switch] $ReadOnly, - [Parameter( Position=4, - Mandatory=$false, - ValueFromPipelineByPropertyName=$true, - ValueFromRemainingArguments=$false )] - [bool] - $Open = $True + [Parameter( Position=4, + Mandatory=$false, + ValueFromPipelineByPropertyName=$true, + ValueFromRemainingArguments=$false )] + [string] + $ConnectionStringOptions, + [Parameter( Position=5, + Mandatory=$false, + ValueFromPipelineByPropertyName=$true, + ValueFromRemainingArguments=$false )] + [bool] + $Open = $True ) Process { @@ -115,7 +124,14 @@ { $ConnectionString += "Read Only=True;" } - + if ($ConnectionStringOptions) { + if ($ConnectionStringOptions.StartsWith(';')) { + $ConnectionString += $ConnectionStringOptions + } else { + $ConnectionString += ";$ConnectionStringOptions" + } + } + $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentList $ConnectionString $conn.ParseViaFramework = $true #Allow UNC paths, thanks to Ray Alex! Write-Debug "ConnectionString $ConnectionString"