Page 1 of 1

getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 10, 2010 12:24 pm
by Bonkie
Hi there,

I dont know if this request is already been made but I would like to have the option to select the value by columnname instead of column index.

For example now it is

Code: Select all
var vSQL = databaseManager.getDataSetByQuery('server', 'SELECT * FROM table', null, -1);

// Lets loop trough the result set
for(i = 1; i < vSQL.getMaxRowIndex(); i++)
{
    variable = vSQL.getValue(1,i);
}


But this is not usable because the order of the index could change or be different on any SQL installation. But you dont want to select the column manually if you need them all when you have about 80 columns or what.

So what I would like to see is

Code: Select all
var vSQL = databaseManager.getDataSetByQuery('server', 'SELECT * FROM table', null, -1);

// Lets loop trough the result set
for(i = 1; i < vSQL.getMaxRowIndex(); i++)
{
    variable = vSQL.getValue('pk',i);
}

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 10, 2010 1:39 pm
by lvostinar
you can use vSQL['my_column'] to return the value from current row (where rowIndex points); not sure when it was introduced , I think in some version of Servoy 4 (I can check if you need this info)

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Fri Feb 12, 2010 4:40 pm
by pbakker
Even vSQL.columnName should work, but you have to set the rowIndex first.

Paul

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Mon Feb 15, 2010 5:45 pm
by jcompagner
or

Code: Select all
for(i = 1; i < vSQL.getMaxRowIndex(); i++)
{
    variable = vSQL[i]['name'];
}


without setting the row index.

there is one catch, that only works for GETTING values not for setting!

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 17, 2010 2:33 pm
by Bonkie
Ok didn't know that. But does that also work in Servoy 3.5.x?

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 17, 2010 2:44 pm
by jcompagner
Bonkie wrote:Ok didn't know that. But does that also work in Servoy 3.5.x?


no only in the latest versions of servoy. (that you should use by now ofcourse ;) )

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 17, 2010 2:45 pm
by Bonkie
jcompagner wrote:
Bonkie wrote:Ok didn't know that. But does that also work in Servoy 3.5.x?


no only in the latest versions of servoy. (that you should use by now ofcourse ;) )


To badly that some customers still work @ Servoy 3.5.. But is really no option to use it in 3.5?

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Wed Feb 17, 2010 3:45 pm
by jcompagner
no those new constructs cant be used in 3.5

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 11:58 am
by birgit
Hi

What does the "-1" mean in
Code: Select all
databaseManager.getDataSetByQuery(..., -1);

Thanks and regards
Birgit

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 12:14 pm
by Harjo
-1 means, no limit on max returned records.

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 12:49 pm
by birgit
Wow, thanks, Harjo! That's what I was hoping for. I didn't know about this, but I can use it everywhere now :D

Regards
Birgit

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 12:57 pm
by jcompagner
You better can specify 1000 or something.. (or 10K)
just to be sure that not somehow that query will transfer billion of rows to your client.

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 1:16 pm
by birgit
Hi Johan

Billion rows of course is not an issue. In our environment we talk about hundreds of rows. Until now I always defined an upper border of 1'000 or 10'000 rows. And I always had this bad feeling of: what happens if the maximum number of rows returned is too small? Should I always ask for hadMoreData and log this if yes?

I prefer no upper limit. And if the number of rows exceeds a reasonable size, I will add useful filters to the user.

Other ideas?

Regards
Birgit

Re: getValue() by columnname using getDataSetByQuery

PostPosted: Thu Feb 18, 2010 2:02 pm
by pbakker
Do set an upper limit and check if there were more rows. If yes, prompt the user with a meaningful message or log something, what ever you like, like giving them the option to extend the upper limit, maybe.

IMHO it's better to have an upper limit and notify the user somehow than having the Client stall/crash because there are too many rows downloaded.

Paul