getDataSetByQuery() question

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

getDataSetByQuery() question

Postby Morley » Thu Dec 09, 2004 7:27 pm

This is my first attempt at using this function. I'm attempting to find all records which have the current value of the field "catkey". Therefore I'm first putting the target value into the variable "key". However I'm getting an error message saying it can't find the column "key". Obviously a syntax error, but what?

Code: Select all
var key = catkey;
var maxReturedRows = 10;//useful to limit number of rows
var query = 'SELECT catid FROM cat WHERE catkey = key';
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, maxReturedRows);
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby patrick » Thu Dec 09, 2004 7:31 pm

You're statement says:

give me catid from cat where the column catkey equals the column key.

If there is no column key, you get an error. What you want to do is:

Code: Select all
var query = 'select catid from cat where catkey = ' + key


This only works if catkey is a number column. If it is string, you need to take care of "...
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby Morley » Thu Dec 09, 2004 9:19 pm

Much thanks, Patrick.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada

Postby IT2Be » Mon Dec 13, 2004 10:20 am

Morley, why don't you check out 'www.sqlcourse.com. This will help you with the basics of working with sql statements...
Marcel J.G. Trapman (IT2BE)
SAN partner - Freelance Java and Servoy
Servoy Components - IT2BE Plug-ins and Beans for Servoy
ServoyForge - Open Source Components for Servoy
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby Morley » Tue Dec 14, 2004 5:38 pm

IT2BE wrote:Morley, why don't you check out 'www.sqlcourse.com. This will help you with the basics of working with sql statements...
Excellent, exactly what I needed. Thanks.
Morley Chalmers
7Office Inc.
User avatar
Morley
 
Posts: 891
Joined: Fri Apr 25, 2003 4:54 pm
Location: Toronto, Canada


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 2 guests