I use my SQL db for storing data and updating it works but selecting from it returns null.
To save text field text into the db in specific column based on the String variable works but not getting the data from it.
So I have nameString var that is set based on the action to a different name. The name value of the string matches a column name in the DB file.
So when myString is set to name “John”, it will save into this column and it works:
var nameString : String;
var slot1 : String;
slot1 = slot1TextField.text
let’s say slot1 = “It works”;
nameString = “John”;
myDB.request(" UPDATE myDBTable SET '" + myDB.escape('$nameString') + "' = '" + myDB.escape('$slot1') + "' WHERE _rowid_ = 1 ");
This saves with success the slot1 text in the DB at the column that nameString equals to.
The opposite, loading the data from the DB returns Null when trying to get the text:
public function whatevert()
var myDB = Sqlite.open('db/myDB.db');
var myNewVar = myDB("SELECT '" + myDB.escape('$nameString') + "' FROM myDBTable WHERE _rowid_ = 1 ");
Doesn’t like t he variable there?
if tracing it it detects nameString as it displays in the logs correct column name:
Log:
{ cache => { h => [{ ‘John’ => John },null], q => [{ ‘John’ => John },null], length => 1 }, r => #abstract }
returns null when trying to display the text, but if in the MYSQL I typed John instead of myDB.escape(’$nameString’) it works
Code I use for displaying the DB value in a field after SELECT from …
for (char in myNewVar)
{
var displayNewText = char.nameString;
myNewVarTextField = new TextField();
myNewVarTextField.background = false;
myNewVarTextField.border = false;
myNewVarTextField.multiline = false;
myNewVarTextField.selectable = false;
myNewVarTextField.text = '$displayNewText';
myNewVarTextField.textColor = 0xFFFFFF;
addChild(myNewVarTextField);
}
if I replaced myString with e.g John like "SELECT John FROM myDBTable or above char.John , only then it would not return null but the actual value “it works”