copy records table 1 to table 2

Questions, tips and tricks and techniques for scripting in Servoy

copy records table 1 to table 2

Postby rogel » Mon Sep 26, 2011 2:11 am

hi!

is there a quick way to copy/move ALL records from table1 to table2 than looping through the records(from table1) and transfer it to the next table?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: copy records table 1 to table 2

Postby ptalbot » Mon Sep 26, 2011 2:25 am

Have a look at the rawSQL plugin, where you can use the executeSQL method to copy and notifyDataChange to tell your clients to reload the table based on the new IDs.
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: copy records table 1 to table 2

Postby rogel » Mon Sep 26, 2011 9:12 pm

ptalbot wrote:Have a look at the rawSQL plugin, where you can use the executeSQL method to copy and notifyDataChange to tell your clients to reload the table based on the new IDs.


Thanks Patrick.

What I am worried about is the SQL might be database independent. If I were to use servoy, which object would you suggest to use?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: copy records table 1 to table 2

Postby ptalbot » Mon Sep 26, 2011 9:40 pm

You could use transactions (set databaseManager.setAutoSave(false) first) to insert many rows in one go instead of hitting the database for each new record.
You will still need to iterate on the source foundset though, create the new records on the target foundset, fill them with the source data and commitTransaction() after a certain number of rows...
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
http://www.servoy-stuff.net
https://www.servoyforge.net
--------------------------------------------
Servoy 5.2.16 / 6.0.9 / 6.1.6 / 7.3.1
All OSes / Java 5 & 6 & 7
User avatar
ptalbot
 
Posts: 1616
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: copy records table 1 to table 2

Postby rogel » Mon Sep 26, 2011 10:29 pm

ptalbot wrote:You could use transactions (set databaseManager.setAutoSave(false) first) to insert many rows in one go instead of hitting the database for each new record.
You will still need to iterate on the source foundset though, create the new records on the target foundset, fill them with the source data and commitTransaction() after a certain number of rows...


start and commit transaction for each table or just one start/commit for the whole function?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am


Return to Methods

Who is online

Users browsing this forum: No registered users and 2 guests