diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4eecd14 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Working.SQLite \ No newline at end of file diff --git a/PSSQLite/Invoke-SqliteBulkCopy.ps1 b/PSSQLite/Invoke-SqliteBulkCopy.ps1 index 576fe88..7042df8 100644 --- a/PSSQLite/Invoke-SqliteBulkCopy.ps1 +++ b/PSSQLite/Invoke-SqliteBulkCopy.ps1 @@ -135,11 +135,7 @@ $NotifyAfter = 0, [switch] - $Force, - - [Int32] - $QueryTimeout = 600 - + $Force ) Write-Verbose "Running Invoke-SQLiteBulkCopy with ParameterSet '$($PSCmdlet.ParameterSetName)'." @@ -189,7 +185,7 @@ } } - function New-SqliteBulkQuery { + function Invoke-SqliteBulkQuery { [CmdletBinding()] Param( [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] @@ -246,7 +242,6 @@ $SQLiteConnection.Open() } $Command = $SQLiteConnection.CreateCommand() - $CommandTimeout = $QueryTimeout $Transaction = $SQLiteConnection.BeginTransaction() } Catch @@ -303,11 +298,11 @@ #Build up the query if ($PSBoundParameters.ContainsKey('ConflictClause')) { - $Command.CommandText = New-SqliteBulkQuery -Table $Table -Columns $ColumnToParamHash.Keys -Parameters $ColumnToParamHash.Values -ConflictClause $ConflictClause + $Command.CommandText = Invoke-SqliteBulkQuery -Table $Table -Columns $ColumnToParamHash.Keys -Parameters $ColumnToParamHash.Values -ConflictClause $ConflictClause } else { - $Command.CommandText = New-SqliteBulkQuery -Table $Table -Columns $ColumnToParamHash.Keys -Parameters $ColumnToParamHash.Values + $Command.CommandText = Invoke-SqliteBulkQuery -Table $Table -Columns $ColumnToParamHash.Keys -Parameters $ColumnToParamHash.Values } foreach ($Column in $Columns) diff --git a/PSSQLite/Invoke-SqliteQuery.ps1 b/PSSQLite/Invoke-SqliteQuery.ps1 index 83a704f..662e949 100644 --- a/PSSQLite/Invoke-SqliteQuery.ps1 +++ b/PSSQLite/Invoke-SqliteQuery.ps1 @@ -290,7 +290,7 @@ } Catch { - if( -not ($Library = Add-Type -path $SQLiteAssembly -PassThru -ErrorAction stop) ) + if( -not (Add-Type -path $SQLiteAssembly -PassThru -ErrorAction stop) ) { Throw "This module requires the ADO.NET driver for SQLite:`n`thttp://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki" } @@ -427,11 +427,11 @@ $cmd.CommandText = $Query $cmd.CommandTimeout = $QueryTimeout - if ($SqlParameters -ne $null) + if ($null -ne $SqlParameters) { $SqlParameters.GetEnumerator() | ForEach-Object { - If ($_.Value -ne $null) + If ($null -ne $_.Value) { if($_.Value -is [datetime]) { $_.Value = $_.Value.ToString("yyyy-MM-dd HH:mm:ss") } $cmd.Parameters.AddWithValue("@$($_.Key)", $_.Value) diff --git a/PSSQLite/New-SqliteConnection.ps1 b/PSSQLite/New-SqliteConnection.ps1 index 9da0d9d..7ca05a7 100644 --- a/PSSQLite/New-SqliteConnection.ps1 +++ b/PSSQLite/New-SqliteConnection.ps1 @@ -55,7 +55,7 @@ SQL #> - [cmdletbinding()] + [cmdletbinding(SupportsShouldProcess=$true)] [OutputType([System.Data.SQLite.SQLiteConnection])] param( [Parameter( Position=0, @@ -94,48 +94,51 @@ { foreach($DataSRC in $DataSource) { - if ($DataSRC -match ':MEMORY:' ) + if ( $PSCmdlet.ShouldProcess($DataSRC) ) { - $Database = $DataSRC - } - else - { - $Database = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DataSRC) - } - - Write-Verbose "Querying Data Source '$Database'" - [string]$ConnectionString = "Data Source=$Database;" - if ($Password) - { - $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) - $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) - $ConnectionString += "Password=$PlainPassword;" - } - if($ReadOnly) - { - $ConnectionString += "Read Only=True;" - } - - $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentList $ConnectionString - $conn.ParseViaFramework = $true #Allow UNC paths, thanks to Ray Alex! - Write-Debug "ConnectionString $ConnectionString" - - if($Open) - { - Try + if ($DataSRC -match ':MEMORY:' ) { - $conn.Open() + $Database = $DataSRC } - Catch + else { - Write-Error $_ - continue + $Database = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($DataSRC) } + + Write-Verbose "Querying Data Source '$Database'" + [string]$ConnectionString = "Data Source=$Database;" + if ($Password) + { + $BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password) + $PlainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) + $ConnectionString += "Password=$PlainPassword;" + } + if($ReadOnly) + { + $ConnectionString += "Read Only=True;" + } + + $conn = New-Object System.Data.SQLite.SQLiteConnection -ArgumentList $ConnectionString + $conn.ParseViaFramework = $true #Allow UNC paths, thanks to Ray Alex! + Write-Debug "ConnectionString $ConnectionString" + + if($Open) + { + Try + { + $conn.Open() + } + Catch + { + Write-Error $_ + continue + } + } + + write-Verbose "Created SQLiteConnection:`n$($Conn | Out-String)" + + $Conn } - - write-Verbose "Created SQLiteConnection:`n$($Conn | Out-String)" - - $Conn } } } \ No newline at end of file diff --git a/PSSQLite/Out-DataTable.ps1 b/PSSQLite/Out-DataTable.ps1 index 039af37..96fdd41 100644 --- a/PSSQLite/Out-DataTable.ps1 +++ b/PSSQLite/Out-DataTable.ps1 @@ -121,7 +121,7 @@ $Col.ColumnName = $Name #If it's not DBNull or Null, get the type - if ($Value -isnot [System.DBNull] -and $Value -ne $null) + if ($Value -isnot [System.DBNull] -and $null -ne $Value) { $Col.DataType = [System.Type]::GetType( $(Get-ODTType $property.TypeNameOfValue) ) } @@ -149,7 +149,7 @@ { $DR.Item($Name) = $Value | ConvertTo-XML -As String -NoTypeInformation -Depth 1 } - elseif($Value -eq $null) + elseif($null -eq $Value) { $DR.Item($Name) = [DBNull]::Value } @@ -165,7 +165,7 @@ } #Did we get a null or dbnull for a non-nullable item? let the user know. - if($NonNullable -contains $Name -and ($Value -is [System.DBNull] -or $Value -eq $null)) + if($NonNullable -contains $Name -and ($Value -is [System.DBNull] -or $null -eq $Value)) { write-verbose "NonNullable property '$Name' with null value found: $($object | out-string)" } diff --git a/PSSQLite/PSSQLite.psm1 b/PSSQLite/PSSQLite.psm1 index 4add9a9..66b54ce 100644 --- a/PSSQLite/PSSQLite.psm1 +++ b/PSSQLite/PSSQLite.psm1 @@ -18,7 +18,7 @@ Throw "Something is odd with bitness..." } - if( -not ($Library = Add-Type -path $SQLiteAssembly -PassThru -ErrorAction stop) ) + if( -not (Add-Type -path $SQLiteAssembly -PassThru -ErrorAction stop) ) { Throw "This module requires the ADO.NET driver for SQLite:`n`thttp://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki" } @@ -45,4 +45,4 @@ } #Create some aliases, export public functions - Export-ModuleMember -Function $($Public | Select -ExpandProperty BaseName) \ No newline at end of file + Export-ModuleMember -Function $($Public | Select-Object -ExpandProperty BaseName) \ No newline at end of file