Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions PSSQLite/Invoke-SqliteBulkCopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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!
}
Expand Down
18 changes: 16 additions & 2 deletions PSSQLite/Invoke-SqliteQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -278,7 +281,10 @@
ValueFromRemainingArguments=$false )]
[Alias( 'Connection', 'Conn' )]
[System.Data.SQLite.SQLiteConnection]
$SQLiteConnection
$SQLiteConnection,
[Parameter(Position=8, Mandatory=$false)]
[string]
$ConnectionStringOptions
)

Begin
Expand Down Expand Up @@ -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"
Expand Down
30 changes: 23 additions & 7 deletions PSSQLite/New-SqliteConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
{
Expand All @@ -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"
Expand Down