Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector NET 8.3.0\MySql.Data.dll")
- Function New-SQLUpdate ($connectionProperties, $id, $pageCount, $cover) {
- $Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
- $Connection.ConnectionString="server=$($connectionProperties.mysqlHost);uid=$($connectionProperties.mysqlUser);pwd=$($connectionProperties.mysqlPass);database=$($connectionProperties.mysqlDatabase)"
- $Connection.Open()
- $command = New-Object MySql.Data.MySqlClient.MySqlCommand
- $command.Connection = $Connection
- $command.CommandText = "UPDATE isbninfo SET pagecount = @pagecount, cover = @cover WHERE id = @id"
- $command.Parameters.AddWithValue("@pagecount", $pageCount) | Out-Null
- $command.Parameters.AddWithValue("@cover", $cover) | Out-Null
- $command.Parameters.AddWithValue("@id", $id) | Out-Null
- $command.ExecuteNonQuery() | Out-Null
- $Connection.Close()
- }
- $connectionParameters = New-Object PSObject
- $connectionParameters | Add-Member Noteproperty "mysqlHost" "localhost"
- $connectionParameters | Add-Member Noteproperty "mysqlUser" "myuser"
- $connectionParameters | Add-Member Noteproperty "mysqlPass" "mypass"
- $connectionParameters | Add-Member Noteproperty "mysqlDatabase" "mydb"
- $connection = [MySql.Data.MySqlClient.MySqlConnection]@{ConnectionString="server=$($connectionParameters.mysqlHost);uid=$($connectionParameters.mysqlUser);pwd=$($connectionParameters.mysqlPass);database=$($connectionParameters.mysqlDatabase)"}
- $connection.Open()
- $mySQLCommand = "SELECT id FROM isbninfo WHERE pagecount = 0 OR cover = ''"
- $SQLCommand = [MySql.Data.MySqlClient.MySqlCommand]@{Connection=$connection; CommandText=$mySQLCommand}
- $SQLReader = $SQLCommand.ExecuteReader()
- While($SQLReader.Read()) {
- #magic correction happens here - use Add-Book.ps1
- #New-SQLUpdate $connectionParameters $SQLReader["id"] $pagecount $cover
- }
- $SQLReader.Close()
- $connection.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement