database transactions

Questions and answers regarding general SQL and backend databases

database transactions

Postby rogel » Thu Sep 29, 2011 3:19 pm

hi!

In the below code.

1. foundset.deleteAllRecords (table1)
2. create insert records from table2 and execute rawsql.executeSQL to table1
3. plugins.maintenance.getServer.droptable(table2)
4. update sequence for table 1

if i place databaseManager.starttransaction before line1 and committransaction after line4. Would the data be able to rollback if the all the steps were not completed?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: database transactions

Postby ROCLASI » Thu Sep 29, 2011 3:25 pm

Hi Rogel,

Is table2 a temp table ? I don't see where you create it.
If it's not a temp table you should consider that not all of the SQL vendors support transactions on DDL commands. PostgreSQL does support transactions on most DDL commands.
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: database transactions

Postby rogel » Thu Sep 29, 2011 3:29 pm

ROCLASI wrote:Hi Rogel,

Is table2 a temp table ? I don't see where you create it.
If it's not a temp table you should consider that not all of the SQL vendors support transactions on DDL commands. PostgreSQL does support transactions on most DDL commands.


I created table2 using the server.createTable and just placed TEMP_<tableName> as prefix. Is there a servoy method to create temp tables?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: database transactions

Postby ROCLASI » Thu Sep 29, 2011 3:36 pm

Hi Rogel,

For temp tables you use SQL and the rawSQL plugin.
Also server.createTable is a maintainance plugin function and I don't think these functions work in the client. It's designed for use in pre- and post import hooks when you import your solution into the server.
Are you writing this for those pre-/post import scripts ?
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: database transactions

Postby rogel » Thu Sep 29, 2011 3:48 pm

ROCLASI wrote:Hi Rogel,

For temp tables you use SQL and the rawSQL plugin.
Also server.createTable is a maintainance plugin function and I don't think these functions work in the client. It's designed for use in pre- and post import hooks when you import your solution into the server.
Are you writing this for those pre-/post import scripts ?


Hi Robert,

The solution is in a web service for it needs the process to be done in the server (i am not sure it headless client is better). I am not confident in using the "CREATE TEMP table" SQL because I am not sure if other database can support it. I am doing a backup/restore database utility.
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: database transactions

Postby ROCLASI » Thu Sep 29, 2011 4:14 pm

Hi Rogel,

There are indeed some differences in syntax/behavior between the vendors. For example in PostgreSQL a temp table is only visible in the connection (session) it was created in. So multiple sessions can create the same temp table. Other vendors allow such temp table to be visible to other sessions as well.
Anyway, I think for your solution you need to use plain SQL to create any table since (if I am not mistaken) the maintainance plugin won't do it for you in web/headless/smart client. And you need to make sure this table name is then unique as well for this specific user.
And since DDL (create/drop table, etc) with transactaction support (being able to roll it back) is also not cross-vendor you would have to handle that yourself as well (the cleaning up of the table).
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: database transactions

Postby rogel » Fri Sep 30, 2011 2:52 pm

ROCLASI wrote:And since DDL (create/drop table, etc) with transaction support (being able to roll it back) is also not cross-vendor you would have to handle that yourself as well (the cleaning up of the table).

The DDL you are referring to is the native SQL statements or servoy objects?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am

Re: database transactions

Postby ROCLASI » Fri Sep 30, 2011 10:43 pm

Hi Rogel,

I am refering to any Data Definition Language (DDL) commands (CREATE/ALTER/DROP) that is send to the backend database, be it via the rawSQL plugin or via Servoy objects.
If the backend doesn't have support for these statements to execute inside a database transaction then you can't roll them back.
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: database transactions

Postby rogel » Tue Oct 04, 2011 12:24 am

ROCLASI wrote:Hi Rogel,

I am refering to any Data Definition Language (DDL) commands (CREATE/ALTER/DROP) that is send to the backend database, be it via the rawSQL plugin or via Servoy objects.
If the backend doesn't have support for these statements to execute inside a database transaction then you can't roll them back.


I see. But the SQL generated by the Servoy objects are likely to work on "most" backend databases?
rogel
 
Posts: 264
Joined: Mon Jul 04, 2011 9:09 am


Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 16 guests

cron