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

Pb when dealing with string that include a ' in bulk insert #2

Closed
jbpaux opened this issue Apr 10, 2015 · 3 comments
Closed

Pb when dealing with string that include a ' in bulk insert #2

jbpaux opened this issue Apr 10, 2015 · 3 comments

Comments

@jbpaux
Copy link
Contributor

jbpaux commented Apr 10, 2015

When variable has a ' in it, it is not escaped and thus the SQL insert is failing. Proper escape is required

@RamblingCookieMonster
Copy link
Owner

Just ran into this working on a project for a blog post - will look into using parameters for these inserts, which should avoid this issue. Thanks for the reminder!

@jbpaux
Copy link
Contributor Author

jbpaux commented Apr 10, 2015

I tried something like this: (sorry, I know I should do a pull request)

$Query = "INSERT INTO $Table ($($Columns -join ", ")) VALUES (@$($Columns -join ", @"))"
foreach ($Column in $Columns) {
                $param = new-object System.Data.SQLite.SqLiteParameter $Column
                $Command.Parameters.Add($param)
            }

for ($RowNumber = 0; $RowNumber -lt $RowCount; $RowNumber++)
            {
                $row = $Datatable.Rows[$RowNumber]
                foreach($Column in $Columns) {
                    $Command.Parameters[$Column].Value = $row[$Column]
                }
...
}

@RamblingCookieMonster
Copy link
Owner

Thanks for the help! Should be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants