CRUD on mysql using forms

Questions and answers for designing and implementing forms in Servoy

CRUD on mysql using forms

Postby rajhritish » Thu Dec 17, 2015 4:04 pm

Hey guys,
how can we perform crud ops on db? we have database manager and in that I am able to find few methods, but I need to perform them only on a button click. If I give an event it asks for various types of events like entity, form and scope. Can anyone explain with an example?

Thank you
Posts: 1
Joined: Thu Dec 17, 2015 3:56 pm

Re: CRUD on mysql using forms

Postby paronne » Thu Dec 17, 2015 5:23 pm

Hi normally CRUD operations on database are done through the foundset object. You can perform direct CRUD queries in db but we discourage to do so.
In few words the foundset caches records of a table into a programmatical object as result of a query.
On a foundset object you can, create newRecord, deleteRecord and edit the records. Edit of the record it can be done directly from the UI thanks to the databinding feature.
To perform CRUD operation programmaticaly, let's assume you want to edit the column (we call it dataprovider) 'companyname' of the table 'companies'. You will need to retrieve a foundset object based on table companies (a foundset has always a datasource which normally is a table in a database). You can create a new record with the method foundset.newRecord, delete it with foundset.deleteRecord and you can update a value by simplying accessing the column name.
foundset.companyname = "New Company" would update the column of the selectedRecord (a foundset has always a selectedRecord).
foundset.getRecord(idx).companyname = "New Company" would update the value of the column in a record at index idx.
You can finally use the methods of the databaseManager, databaseManager.saveData() to push the changes to the DB, you have support for transactions and recordLocking too.
NOTE Carefully: Servoy has an autoSave mode which is ON by default and pushes immediately any change to the database. call databaseManager.setAutoSave(false) to disable it and get in control on when to save the changes.

See our wiki pages for a better understanding of the foundset:, ... y+Foundset
Posts: 107
Joined: Fri Nov 02, 2012 3:21 pm

Return to Forms

Who is online

Users browsing this forum: No registered users and 4 guests