Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed to pass script analyzer tests #20

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Working.SQLite
13 changes: 4 additions & 9 deletions PSSQLite/Invoke-SqliteBulkCopy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@
$NotifyAfter = 0,

[switch]
$Force,

[Int32]
$QueryTimeout = 600

$Force
)

Write-Verbose "Running Invoke-SQLiteBulkCopy with ParameterSet '$($PSCmdlet.ParameterSetName)'."
Expand Down Expand Up @@ -189,7 +185,7 @@
}
}

function New-SqliteBulkQuery {
function Invoke-SqliteBulkQuery {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
Expand Down Expand Up @@ -246,7 +242,6 @@
$SQLiteConnection.Open()
}
$Command = $SQLiteConnection.CreateCommand()
$CommandTimeout = $QueryTimeout
$Transaction = $SQLiteConnection.BeginTransaction()
}
Catch
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions PSSQLite/Invoke-SqliteQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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)
Expand Down
77 changes: 40 additions & 37 deletions PSSQLite/New-SqliteConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
SQL

#>
[cmdletbinding()]
[cmdletbinding(SupportsShouldProcess=$true)]
[OutputType([System.Data.SQLite.SQLiteConnection])]
param(
[Parameter( Position=0,
Expand Down Expand Up @@ -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
}
}
}
6 changes: 3 additions & 3 deletions PSSQLite/Out-DataTable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) )
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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)"
}
Expand Down
4 changes: 2 additions & 2 deletions PSSQLite/PSSQLite.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -45,4 +45,4 @@
}

#Create some aliases, export public functions
Export-ModuleMember -Function $($Public | Select -ExpandProperty BaseName)
Export-ModuleMember -Function $($Public | Select-Object -ExpandProperty BaseName)