im using the following code to make a query on a MySQL-Server :
var vQuery = "select vorname,nachname from kunden where nummer = 'abc123'";
var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(), vQuery, null, 500);
forms.suchen.controller.loadRecords(vDataset);
Im getting the error : "Error loading primary key data, Die Abfrage muss mit ‘SELECT’ beginnen’.
You need to select only the PK column. Servoy will load the rest for you.
So your code should look something like this:
var vQuery = "select myIDField from kunden where nummer = 'abc123'";
var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(), vQuery, null, 500);
forms.suchen.controller.loadRecords(vDataset);
Of course you need to put the correct PK fieldname in there.
Okay, the pk-field is “nummer” (as shown in Dataproviders). So i changed the code to :
var vQuery = "select nummer from kunden where nummer = 'abc123'";
var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(), vQuery, null, 500);
forms.suchen.controller.loadRecords(vDataset);
It’s a bit of a strange error you get because your select statement begins with a SELECT as it requires. Maybe you have any invisible characters in that string? Did you copy paste it from another app?
Also do you get the error on the 2nd line of code or on the 3rd (loadRecords) ?
You can see this by enabling the debugger.
I’d start with the basics and look at the output of that query in the debugger. What is the count of rows found? Look at the contents of that column output.
The table in the MySQL-DB is named “Kunden” with a big “K”. I dont know why, but the dataprovider shows it with small “k”. Normally this seems to work fine. But when i use this “query_by_hand” i have to use the big “K”.