get record from primary keys

Questions, tips and tricks and techniques for scripting in Servoy

get record from primary keys

Postby paulc » Fri Sep 10, 2010 12:38 am

is there a way in which to get a record from a foundset via primary keys without having to select a record?

doing this: foundset.selectRecord is pretty expensive in some forms, and all I would like to do is grab a record to run a recalc on it.

Thanks
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: get record from primary keys

Postby ROCLASI » Fri Sep 10, 2010 12:58 am

Hi Paul,

What about using this code?
Code: Select all
// Get a new foundset
var _fs = databaseManager.getFoundSet("serverName","tableName");
// Load the record by it's PK
_fs.loadRecords(databaseManager.convertToDataSet([myIdValue]));
// recalc this record
databaseManager.recalculate(_fs);


Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: get record from primary keys

Postby paulc » Fri Jan 07, 2011 12:29 am

Thanks for the reply Roclasi,

I don't think that would work in my scenario, because I am looking to do this for all records affected, which could potentially be slower performance wise with the overhead of the databaseManager function calls.

The other reason I am looking for this functionality is so that I can perform other actions to a record without the overhead of selecting a record.

I can get to a record via index, and select a record via pks, so I thought there would be some way of achieving this.
paulc
 
Posts: 55
Joined: Wed Feb 17, 2010 8:58 pm

Re: get record from primary keys

Postby pbakker » Fri Jan 07, 2011 10:59 am

You are grabbing a record, so Servoy loads the record and thus the calcs are fired. No need to recalculate at all, because Servoy takes care of that for you.

The only time you need to run a recalculation is if you change something of which you know that it affects records with stored calculations that are not loaded into the Clients memory.

And then only when you need the values in the DB to be correct for retrieving them without accessing the records in the Client (which would trigger the calc firing anyway), so only for direct DB access (external or databaseManager.getdatasetByQuery) like reporting tools.

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

Re: get record from primary keys

Postby ROCLASI » Fri Jan 07, 2011 11:23 am

pbakker wrote:You are grabbing a record, so Servoy loads the record and thus the calcs are fired. No need to recalculate at all, because Servoy takes care of that for you.

Just for the record....you mean only for unstored calcs, right ? Because if loading a record causes a recalc for stored calcs (and thus a save to the backend) this would be highly undesirable.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: get record from primary keys

Postby pbakker » Fri Jan 07, 2011 11:31 am

No, I really meant Stored Calcs. Why would this be undesirable? I think it's highly undesirable if it wouldn't do this, because then the user might be looking at stale data.

Of course the update to the database only happens when the value actually is different, but I assume you already know that.

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

Re: get record from primary keys

Postby ROCLASI » Fri Jan 07, 2011 11:49 am

I guess it depends on your use cases. In mine I tend to use a method instead of a calc just to be sure it only gets triggered once.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium


Return to Methods

Who is online

Users browsing this forum: Bing [Bot] and 15 guests

cron