Manage Results from SQL Searches

Questions, tips and tricks and techniques for scripting in Servoy

Manage Results from SQL Searches

Postby agis » Sat Oct 25, 2003 12:29 pm

With the command: getDataSetByQuery we can run a SQL search and fill the result in a variable (resp. array).
Now my Question: How to process the result. For Example showing the dataset in a portal, combine it with other datasets, make it to the aktual selection and so on. No idea how to manage this, could you help us?
agis
 
Posts: 15
Joined: Sat Oct 04, 2003 4:10 pm
Location: Baden-Baden, Germany

Postby IT2Be » Sat Oct 25, 2003 1:32 pm

I am not certaiin but I think you can only fill a portal through a relationship.

Filling fields etc. can be done like 'dataprovider = dataset.getValue(x,y)' and hooking up values to elements can be done by naming an element 'element.name.whatever = dataset.getValue(x,y)'.

Hope this is somewhat of an answer. I am pretty new to servoy so there could be lot's of other/better answers...

Marcel
User avatar
IT2Be
Servoy Expert
 
Posts: 4766
Joined: Tue Oct 14, 2003 7:09 pm
Location: Germany

Postby Jan Aleman » Sat Oct 25, 2003 6:21 pm

Click on move sample while highlighting the object in the method editor and you'll see some documented examples.

Additionally you can also load the results of a query into a form, in that case make sure your query is returning primary keys and load those into the form by using:

var query = "select orderid from orders where orderid = 10248";
var pkdataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 100);
controller.loadRecords(pkdataset);

Keep in mind that if you use the method above you can't print anymore or sort.
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby Harjo » Sun Oct 26, 2003 12:51 am

jaleman wrote:Keep in mind that if you use the method above you can't print anymore or sort.


I thought the limititations where solved!?
see last reply of Jan Blok:

http://forum.servoy.com/viewtopic.php?t=281
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby Jan Aleman » Sun Oct 26, 2003 11:35 am

I stand corrected!
Jan Aleman
Servoy
Jan Aleman
 
Posts: 2083
Joined: Wed Apr 23, 2003 9:49 pm
Location: Planet Earth

Postby pbakker » Fri Jan 16, 2004 11:34 pm

Question about loading the result of a custom SQL statement (getdatasetbyquery) into a form: No problem of getting the result into the form as a foundset, but is there a way to display it on listview or a portal?

What I' trying is to get a listview of al the users in the system. The getasHTML doesn't fullfill my needs (I think), because I want the user to be able to select one of the found users and based on the selection trigger methods.

So far I have the following code:

var pkdataset = security.getUsers()
//elements.test.text = '<html>'+users.getAsHTML()+'</html>';
controller.loadRecords(pkdataset)

Any way of doing this? (without building a form based on the repository)

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

Postby pbakker » Fri Jan 16, 2004 11:45 pm

I see we cannot base forms on the Servoy system DB-tables, since they are not visible when creating a new form.... :?
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby bcusick » Sat Jan 17, 2004 12:08 pm

pbakker wrote:Question about loading the result of a custom SQL statement (getdatasetbyquery) into a form: No problem of getting the result into the form as a foundset, but is there a way to display it on listview or a portal?

What I' trying is to get a listview of al the users in the system. The getasHTML doesn't fullfill my needs (I think), because I want the user to be able to select one of the found users and based on the selection trigger methods.

So far I have the following code:

var pkdataset = security.getUsers()
//elements.test.text = '<html>'+users.getAsHTML()+'</html>';
controller.loadRecords(pkdataset)

Any way of doing this? (without building a form based on the repository)


Hi Paul,

Beginning in 2.0b1 you can execute a global method with INLINE HTML. So, if you displayed the list of users as HTML - you can add this line to your HTML - and have a "link" that the users can click on that execute a Servoy global method:

<a href="javascript:methodName">PersonName</a>

You can even pass parameters to the global method:

<a href="javascript:methodName('100','300')">PersonName</a>

IMPORTANT NOTE: If you pass parameters - they MUST be surrounded by SINGLE QUOTES.

Hope this helps,

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby pbakker » Sat Jan 17, 2004 2:09 pm

Good thing I wrote '(I think)'.... :D all these new features, I cannot keep up with them.

Tnx for the help, I'll go and play around with it.

Two other questions though:
- Based on your answer: I asume that it is not possible to retrieve the result in a portal of normal listview?
- How can I alter the look of the HTML retrieval, to make it look more like a regular listview?

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

Postby maarten » Sat Jan 17, 2004 2:47 pm

- Based on your answer: I asume that it is not possible to retrieve the result in a portal of normal listview?

portal>no, listview>with controller.loadRecords(pkdataset)
How can I alter the look of the HTML retrieval, to make it look more like a regular listview?


you can do a loop through the dataset and combine html with the
dataset values:
Code: Select all
var HTML = '<html><table>' //var HTML receives all html code
//get dataset by query

for( var i = 1 ; i <= dataset.getMaxRowIndex() ; i++ )
{
    dataset.rowIndex = i;
    HTML += '<tr><td>'+ dataset[1]+'</td><td>'+ dataset[2]+'</td></tr>';
}
HTML += '</table>'
elements.test.text = HTML; //set your label with the html code
Maarten Berkenbosch
User avatar
maarten
 
Posts: 797
Joined: Wed Apr 23, 2003 10:52 pm
Location: Amersfoort, Netherlands

Postby pbakker » Sat Jan 17, 2004 3:59 pm

Maarten,

"controller.loadRecords(pkdataset)": does this work with a dataset retrieved by getDatasetByQuery, especially if the Query runs over another table (or multiple tables) than the table the form, on which you want to display the dataset, is based?

As for the suggested loop through the data: I'll go and fiddle with it... :)

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

Postby bcusick » Sat Jan 17, 2004 4:19 pm

pbakker wrote:"controller.loadRecords(pkdataset)": does this work with a dataset retrieved by getDatasetByQuery, especially if the Query runs over another table (or multiple tables) than the table the form, on which you want to display the dataset, is based?


YES! Does work. That's sort of the whole point... :D

In your select statement returnONLY the primary key of table you're going to display in.

For example: customers is the base table for my listview (used in a tabpanel). The primary key is "custId".

Your query would look like:

SELECT custId from customers where ......

Bob Cusick
bcusick
 
Posts: 1255
Joined: Wed Apr 23, 2003 11:27 pm
Location: Thousand Oaks, CA USA

Postby pbakker » Sat Jan 17, 2004 5:19 pm

:lol:

Well, I guess I have to try more.....

Last question then: If I use the security node to retrieve all user_id's and user_names, the PK is User_ID and I want to display the result using controller.loadrecords(pkdataset), I asume I must have a form based on the table where the user_ID's are pk as well, right?

As far as I know, I cannot build a form on that table, because that table (a Servoy table) does not show in the available tables when creating a new form....
pbakker
 
Posts: 2822
Joined: Wed Oct 01, 2003 8:12 pm
Location: Amsterdam, the Netherlands

Postby jcompagner » Mon Jan 19, 2004 1:36 pm

no you can't create a form based on a servoy table
The only thing to do is showing the user data in a value list

Code: Select all
var ds = security.getUsers();
var names = new Array();
var id = new Array();
for(var k=1;k<ds.getMaxRowIndex();k++)
{
   id[k-1] = ds.getValue(k, 1);
   names[k-1] = ds.getValue(k, 2);
}
application.setValueListItems( 'users',  names,id);
Johan Compagner
Servoy
User avatar
jcompagner
 
Posts: 8839
Joined: Tue May 27, 2003 7:26 pm
Location: The Internet

Postby pbakker » Wed Jan 28, 2004 11:55 pm

According to Bob, you could now have a link in HTML view launch a Servoy method. Based on the given examples, I created the following code. The HTML shows that it is a link, but the method is not launched.... where am I going wrong?

var pkdataset = security.getUsers()
var HTML = '<html><table>' //var HTML receives all html code
for( var i = 1 ; i <= pkdataset.getMaxRowIndex() ; i++ )
{
pkdataset.rowIndex = i;
HTML += '<tr><td>'+ pkdataset[1]+'</td><td><a href="javascript:test2()">'+ pkdataset[2]+'</a></td></tr>';
}
HTML += '</table>'
elements.test.text = HTML; //set your label with the html code

tnx in advance,

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

Next

Return to Methods

Who is online

Users browsing this forum: No registered users and 11 guests

cron