Powershell command og Maria DB fejler
HejJeg har lidt udfordringer med at få det til at spille sammen,
jeg har 3 forespørgsler
den første henter data ind. den virker,
den anden er 2 delt, og virker ikke helt--- den virker i sql commanden i webinterfacet, men når jeg kører den fra powershell giver den fejl??
kode er:
# Connect to the database
$driver = "MariaDB ODBC 3.0 Driver"
$Connection = New-Object System.Data.ODBC.ODBCConnection
$Connection.connectionstring = "DRIVER={MariaDB ODBC 3.0 Driver};" +
"Server = $DB_HOSTNAME;" +
"Database = $DB_DATABASE;" +
"UID = $DB_USERNAME;" +
"PWD= $DB_PASSWORD;"
$Connection.Open()
$Query1 = "Load data infile 'C:/Users/Peter/Documents/iWall_3_6/history/result/all.csv' IGNORE into table events fields terminated by ',' lines terminated by '\n' IGNORE 1 LINES (Modtaget,Mandskab,Melding,AdresseVej,AdresseNr,AdresseSted,AdresseBy,Anmelder,Vogne,GPS);"
$Query2 = "SET @test = (SELECT `Modtaget` FROM `events` ORDER BY `Modtaget` DESC LIMIT 1); UPDATE `events` SET `AdresseVej`='',`AdresseNr`='',`Anmelder`='',`GPS`='' WHERE `Modtaget` <> @test;"
$Command1 = New-Object System.Data.ODBC.ODBCCommand($Query1, $Connection)
$Reply = $Command1.executescalar()
$Command2 = New-Object System.Data.ODBC.ODBCCommand($Query2, $Connection)
$Reply = $Command2.executescalar()
command 2 køres, får jeg følgende fejl i powershell:
Exception calling "ExecuteScalar" with "0" argument(s): "ERROR [42000] [ma-3.0.3][10.1.6-MariaDB]You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'UPDATE events SET Adres
seVej='--',AdresseNr='--',Anmelder='--',GPS='--' WHERE Mo' at line 1"
At C:\Users\Peter\Documents\Arbejde\Brand\skærm\Powershell\csv6.ps1:183 char:2
+ $Reply = $Command2.executescalar()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : OdbcException
Hvad har jeg overset??