aston_zh
aston_zh

Reputation: 6843

PowerShell: multiple queries in ODBC DSN connection

I want to execute multiple queries in an ODBC DSN MySql Connection. If I execute just one query it works fine. But if I try to execute multiple I always get this error:

"ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.84-community]You have an error in your SQL syntax; check the 
manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE TABLE SET ID = '5' WHERE TYPE = '500' AND ID' 
at line 2"

My script:

$qrys = @"
UPDATE TABLE SET ID = '5' WHERE TYPE = '500' AND ID = '0';
UPDATE TABLE SET ID = '6' WHERE TYPE = '600' AND ID = '0';
UPDATE TABLE SET ID = '7' WHERE TYPE = '700' AND ID = '0';
UPDATE TABLE SET ID = '8' WHERE TYPE = '800' AND ID = '0';
"@


$conn = new-object System.Data.Odbc.OdbcConnection
$conn.connectionstring = "DSN=MYDB"
$conn.open()

foreach ($sqlCommand in $qrys) {

    $cmd = New-object System.Data.Odbc.OdbcCommand($sqlCommand,$conn)
    $dataset = New-Object System.Data.DataSet
    (New-Object System.Data.Odbc.OdbcDataAdapter($cmd)).Fill($dataSet) 

}
$conn.Close()

Any ideas? Thanks in advance

Upvotes: 0

Views: 3224

Answers (1)

erg
erg

Reputation: 1652

MySql does not enable multiple queries by default. Either add OPTIONS=67108864 to a connection-string, or enable the checkbox Allow multiple statements in the DSN configuration dialog:

enter image description here

see: https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html

Upvotes: 2

Related Questions