Good Afternoon All!
Ive been working on a project where I am building an Xcode app with Applescript behind it to pull/push data to/from SQL. Now the main body of it is working but im having some challeges with the esacpe quotes symbol ""
Basically to keep the code triggers a php script to pull the data and pre format it as a record string.
Then I plan to use Applescript to grab info from that by saying:
set variableOne to sqlVariable3 of fullSqlRecord
Now the issue im getting is that within the string its leaving in "" hidden in the string… But not when I do:
display dialog fullSqlRecord
Please see below full code:
PHP Script:
<?php
// Set login details to the DB
$username="USER";
$password="PASS";
$database="DB";
$pref=$_REQUEST['pref'];
$id=$_REQUEST['id'];
//Create connection
$conn = new mysqli('localhost',$username,$password,$database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Set SQL Replace TABLE_NAME
$sql = "SELECT * FROM PF_Data WHERE idNum = '$id' AND pref = '$pref'";
//Run the SQL
$result = $conn->query($sql);
foreach($result as $key => $row) {
foreach($row as $field => $value) {
$recNew[$field][] = $value;
}
}
//Loops through each key and value to create the record
foreach ($recNew as $key => $values)
{
$sqlString = $sqlString . $key . ':"';
foreach ($values as $cell)
{
$sqlString = $sqlString . $cell . '", ';
}
}
//Removes the trailing comma and space and returns the full string
$sqlString = substr($sqlString, 0, -1);
echo stripslashes($sqlString);
?>
set urlPath to "Url Address"
set idNumber to "5567"
set preFix to "P"
set newList to {}
set myURL to urlPath & "dbconnection.php?id=" & idNumber & "&pref=" & preFix & ""
set checkit to (do shell script "curl -k " & quoted form of myURL)
display dialog checkit
--> idNum:"5567", pref:"P", created_on:"2017-06-14 00:00:00", created_by:"Me", status:"", last_modified:"", last_modified_by:"", next_status:""
set end of newList to checkit
--I think the problem is here
-- I cant seem to get this to create a record properly
idNum of newList
--> Can't get idNum of {"idNum:\"5567\", pref:\"P\", created_on:\"2017-06-14 00:00:00\", created_by:\"Me\", status:\"\", last_modified:\"\", last_modified_by:\"\", next_status:\"\""}.
Any help would be appreiciated.
I think the problem lies in the creation of the record.
If I run the below code it runs fine:
set newList to {idNum:"5567", pref:"P", created_on:"2017-06-14 00:00:00", created_by:"Me", status:"", last_modified:"", last_modified_by:"", next_status:""}
-- This is the exact same of the string returned
set idNum to idNum of newList
--> 5567
Model: Macbook Pro
AppleScript: Xcode 8.2.1
Browser: Firefox 51.0
Operating System: Mac OS X (10.10)