I am righting to an existing MySQL DB (SnipeIT) and I am having issues getting the formatting correct with my last statement. I have to follow the format that is already in the DB.
The DB field is log_meta with the following:
{“notes”:{“old”:null,“new”:“Testing notes in DB”}}
I already know that I need to escape some of these characters. Here is the PowerShell
$cmd = $conn.CreateCommand()
$cmd.CommandText = "INSERT INTO action_logs (user_id,action_type,note,item_type,item_id,created_at,updated_at,company_id,log_meta,action_date) VALUES ('1238','update','Audit completed $date,'Apps\Models\Apps','$asset_id','$date','$date','`{`"notes`":`{`"old`":$null,`"new`":`"Audit completed $date`"`}`}',$date')"
$reader = $cmd.ExecuteNonQuery()
However, I get the following MySQL/PowerShell error:
ERROR: Exception calling “ExecuteNonQuery” with “0” argument(s): “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
ERROR: version for the right syntax to use near ‘Apps\Models\Apps’,‘1’,‘2023-03-03 09:40:07’,‘2023-03-03 09:40:07’,‘{“notes”:{"ol’ at line 1”
I am confuse on how to make this string PowerShell and MySQL friendly.