In-Memory Datasources

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

In-Memory Datasources

Postby juan.cristobo » Mon May 22, 2017 6:32 pm

Hi all, I saw this webinar and I'm starting to play with in-memory datasources. I've created a datasource named "organizations" with this fileds: organizationid, countryname, name. organizationid is the PK od the datasource.
In order to populate the "table" I'm using this code:
Code: Select all
var ds  = databaseManager.createEmptyDataSet();
ds.createDataSource('organizations');

And then, using a for loop I'm trying to populate it using, i.e., this:
Code: Select all
ds.addRow([100, 'Spain', 'Organization XYZ'])
.
But it throws an error.
If I use datasources.mem['organizations'].getColumnNames() I receive: "organizationid, countryname, name". But If I use ds.getColumnNames() I only receive 2 fields: "countryname, name", so I can't set the organizationid field using ds.addRow()

What's wrong in my code?
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 178
Joined: Thu Apr 19, 2012 9:12 am

Re: In-Memory Datasources

Postby patrick » Mon May 22, 2017 7:02 pm

What error did you get?

I just made a simple test with a datasource test_id: UUID, test: String, test_2: String and then

Code: Select all
var dsEmpty = databaseManager.createEmptyDataSet();
dsEmpty.addRow([application.getUUID(), 'test', 'test2']);
dsEmpty.addRow([application.getUUID(), 'test3', 'test4']);
dsEmpty.createDataSource('test');


To me it looks like you should fill your dataset and then create the datasource from it.

Also, you could simply do

Code: Select all
var fs = datasources.mem.test.getFoundSet();
fs.loadAllRecords();
fs.deleteAllRecords();
fs.newRecord();
fs.test_id = application.getUUID();
fs.test = 'test';
fs.test_2 = 'test2';


so simply get a foundset of your in-memory table, clear all data and loop to create new records.
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3598
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: In-Memory Datasources

Postby juan.cristobo » Tue May 23, 2017 9:36 am

I've tried your first solution (fill the dataset and create the datasource) and it works.

Thanks, Patrick!
Juan
Madrid (Spain)

Servoy 7.4.x - MySQL / SQL Server 2008-2016
Windows 10 Pro
juan.cristobo
 
Posts: 178
Joined: Thu Apr 19, 2012 9:12 am


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 7 guests