PowerShell:ODBC DSN 连接中的多个查询
PowerShell: multiple queries in ODBC DSN connection
我想在 ODBC DSN MySql 连接中执行多个查询。如果我只执行一个查询,它工作正常。但是如果我尝试执行多个,我总是会得到这个 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"
我的脚本:
$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()
有什么想法吗?提前致谢
MySql默认不启用多查询。将 OPTIONS=67108864
添加到连接字符串,或在 DSN 配置对话框中启用复选框 Allow multiple statements
:
参见:https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html
我想在 ODBC DSN MySql 连接中执行多个查询。如果我只执行一个查询,它工作正常。但是如果我尝试执行多个,我总是会得到这个 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"
我的脚本:
$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()
有什么想法吗?提前致谢
MySql默认不启用多查询。将 OPTIONS=67108864
添加到连接字符串,或在 DSN 配置对话框中启用复选框 Allow multiple statements
:
参见:https://dev.mysql.com/doc/connector-odbc/en/connector-odbc-configuration-connection-parameters.html