Simultaneous record creation (within same transaction)

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

Simultaneous record creation (within same transaction)

Postby stephan » Tue Jun 08, 2004 10:01 am

Hello everybody,

I'm new to Servoy and I'd like to acheive the following functionality:

In a form I want to put fields from multiple tables and a button that says "Create".

I want the user to fill the form. When he's done, he clicks on the "Create" button and <b><u>then and only then</u></b> the rows are created into the different tables (all within the same sql transaction).

I'm looking for an all-or-nothing behavior so that if the transaction fails the database is kept clean (ie: not the case if some tables have a record added and others tables don't).

Hope that it can be done without too much hassle.
stephan
 
Posts: 76
Joined: Thu Jun 03, 2004 3:30 pm

Postby Harjo » Tue Jun 08, 2004 1:05 pm

Yes that is possible, use on the form to fill in, only global-fields

than make a method that creates a new record, fill every field with the value of the global-fields and you are done!

Hope this helps
Harjo
 
Posts: 4321
Joined: Fri Apr 25, 2003 11:42 pm
Location: DEN HAM OV, The Netherlands

Postby patrick » Tue Jun 08, 2004 1:27 pm

But you can also use transactions that you can roll back if the user does not hit "Save".

The only question I have there is how that transaction is handled if several tables are involved. But as far as I have seen transactions work, related data is also rolled back. But maybe a statement from Servoy would be helpful on this question.

Patrick
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Postby stephan » Tue Jun 08, 2004 3:32 pm

Thanks for the answer.

So the only way to acheive the desired result is to create a method that reads the global fields and then create the sql sentences.

Conceptually this would looks like this:

start transaction

execute sql create sentence 1
execute sql create sentence 2
execute sql create sentence 3

commit transaction (it is rolledback if the transaction is not successfull).


This is not has fast as I wished it where but that's ok.
stephan
 
Posts: 76
Joined: Thu Jun 03, 2004 3:30 pm

Postby Odysseus » Tue Jun 08, 2004 6:03 pm

I think if you use transactions it would go along the following lines:

on loadform event
starttransaction
end loadform event

user fills out all the form fields ("creating" new records as needed)

on saveformevent (maybe on a button)
var check = function that verifies if all conditions are met and returns OK or NOTOK
if(check == "OK")
commit
else
rollback
inform user
end if
closeform

should be very quick

HTH
Odysseus

Citizen of Old Europe
Odysseus
 
Posts: 205
Joined: Wed Sep 10, 2003 9:34 pm
Location: Belgium

Postby Jan Blok » Tue Jun 15, 2004 11:45 am

patrick wrote:The only question I have there is how that transaction is handled if several tables are involved. But as far as I have seen transactions work, related data is also rolled back. But maybe a statement from Servoy would be helpful on this question.

An transaction encapsulates all changes done by client on any server/table. (meaning it will rollback all and any change in records/foundsets since the transaction is started)
Jan Blok
Servoy
Jan Blok
 
Posts: 2684
Joined: Mon Jun 23, 2003 11:15 am
Location: Amsterdam


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 42 guests

cron