executeCommandLine - Syntax error

Tags: #<Tag:0x00007f616fd654e8> #<Tag:0x00007f616fd65380>

Hi,

I want to execute the executeCommandLine with the following command:

mysql -u OpenHAB -pOpenHABPW -e "INSERT INTO Alarm_User_Access (Timestamp, Status_ID, Status, User_ID, User) VALUES ('2017-11-03 07:34:13', '0', 'uitgeschakeld', '2', 'John');" OpenHAB

When executing this command via SSH directly, it works fine.

I’ve created this rule:

rule "test"

when   
    Item  TEST_Trigger changed from OFF to ON
then
    var string sql_query = "mysql -u OpenHAB -pOpenHABPW -e \"INSERT INTO Alarm_User_Access (Timestamp, Status_ID, Status, User_ID, User) VALUES ('2017-11-03 07:34:13', '0', 'uitgeschakeld', '2', 'John');\" OpenHAB"
    // Please note the escape characters I added before the "-signs.
	logInfo("SQL","Step 1: " + sql_query)		
	var String mysql = executeCommandLine(sql_query, 5000)
	logInfo("SQL","Step 2: " + mysql)	

When executing this rule, I get:

2017-11-05 15:29:26.993 [INFO ] [g.eclipse.smarthome.model.script.SQL] - Step 1: mysql -u OpenHAB -pOpenHABPW -e "INSERT INTO Alarm_User_Access (Timestamp, Status_ID, Status, User_ID, User) VALUES ('2017-11-03 07:34:13', '0', 'uitgeschakeld', '2', 'John');" OpenHAB
2017-11-05 15:29:27.095 [INFO ] [g.eclipse.smarthome.model.script.SQL] - Step 2: ERROR 1064 (42000) at line 1: 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 '"INSERT INTO Alarm_User_Access (Timestamp, Status_ID, Status, User_ID, User) VAL' at line 1

I think it has something to do with the fact that the command also contains “”. But I’m not sure. Any idea how to further troubleshoot this?

I’m using OH 2.2 (snapshot #1073).

[EDIT]
I have the same problem with more simple commands:

mysql -u OpenHAB -pOpenHAB07 -e \"SELECT VERSION()\" OpenHAB

Ok, I’ve found the solution. It seems you need to use @@ to separate arguments:

    var string sql_query = "mysql@@-u@@OpenHAB@@-pOpenHABPW@@-e@@INSERT INTO Alarm_User_Access (Timestamp, Status_ID, Status, User_ID, User) VALUES ('2017-11-03 07:36:14', '0', 'uitgeschakeld', '2', 'John');@@OpenHAB"
	var String mysql = executeCommandLine(sql_query, 5000)