Help with loading records following SQL select

Questions, tips and tricks and techniques for scripting in Servoy

Help with loading records following SQL select

Postby drookwood » Sun Feb 08, 2004 1:58 pm

I'm having trouble loading records into a form after an SQL query. My method looks like this: ('groups' is name of table and 'groupsid' is primary key, 'curr_usergroup' is a global field)

var query = "select groupsid from groups where group_name = curr_usergroup";
var pkdataset = databaseManager.getDataSetByQuery(forms.groups_list.controller.getServerName(), query, null, 100);
forms.groups_list.controller.loadRecords(pkdataset);


When I execute the script I get an error "Error loading primary key data, null" with no further info. In the debugger against pkdataset I am getting a 'dynamicSQL error SQL error code -104 Token unknown - ' plus some other info that I cannot scroll onto screen!

I'm probably missing somethign simple here but can't get it!
drookwood
 
Posts: 290
Joined: Tue Nov 11, 2003 7:08 pm
Location: Somerset, UK

Postby pbakker » Sun Feb 08, 2004 2:34 pm

If curr_usergroup is a global field in Servoy, the problem lie sin the fact that you fire the SQL to the database and the database does not know the globals.

What you should do is, add the content of the global to the query string:

var query = "select groupsid from groups where group_name = "+curr_usergroup;

This way you make the querystring out of two parts:
"groupsid from groups where group_name = "
and the value of the Global.

Paul
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby drookwood » Mon Feb 09, 2004 11:47 pm

Thanks Paul
drookwood
 
Posts: 290
Joined: Tue Nov 11, 2003 7:08 pm
Location: Somerset, UK


Return to Methods

Who is online

Users browsing this forum: No registered users and 31 guests

cron