Why do you use Servoy or DB managed sequences???

As in the header, who uses either one or the other and what was/were the reason(s)?

I am still struggling with this question…

What do you use to manage your sequences
  • I use Servoy managed sequences
  • I use DB managed sequences
0 voters

i can name one thing that you have to use db sequences: If the table is also used by other programs then servoy (for example a webapp)

I have been playing with this question quite a while, too and came to the conclusion that it is far safer to use DB sequences.

In practice you will figure that some other process will add records to a database, maybe because another app is using it or a large import is done not using Servoy.

I can see only two downsides to this:

  1. You need to use controller.saveData() (which is not a problem really)
  2. Almost all databases have their own way of defining a sequence, so Servoy will not be able to create them for you when importing that solution. Worst case you have to create tons of sequence definitions yourself when moving to another database than your development environment.

To be honest: I would not recommend using Servoy sequences to anyone, just because when one day they get you in trouble, you will have a lot of work converting your logic.

My vote goes for DB sequence.

Patrick

I misvoted in the poll. :?

I use DB sequences for 2 reasons:

  1. I use other apps to access/edit the database(s) as well.
  2. I strongly believe in keeping things where they belong in the first place.

I use db-managed sequence, becoz:
-we will have to import data from other applications/databases when a new client is gonna use our software
-I do believe that db is the place to create the sequence and not the application
-servoy leaves rooms for error becoz you can change the sequences manually (allthough servoy warns you for it so it will be your own dumb fault)

DB Sequences, because of all the allready stated reasons.

To me, the use of Servoy sequences is only to quickly build a solution/define tables for test purposes, concept proofing etc.

Any real solution I would create with DB sequences, because it’s so much safer.

Paul

I started off using Servoy sequences and from time to time hit the “Can’t save data” problem, (sequences are out of sync). Can I ask then

patrick:

  1. You need to use controller.saveData() (which is not a problem really)
    Patrick

For DB sequences to work correctly, should I have a controller.saveData() after every controller.newRecord()? Anything else I should think about?

Thanks

antonio:
I started off using Servoy sequences and from time to time hit the “Can’t save data” problem, (sequences are out of sync).

Servoy Server (you also use Server in a special mode when using Developer) keeps track of the servoy sequences.
When you connect a different instance of servoy to that same data source you might end up with servoy sequences out of sync.
Of course using any third-party tool to add records to the data source will also result in sequences out of sync.

Otherwise Servoy doesn’t need a special saveData() function call to fetch the new PK that are managed by Servoy itself.

Hope this helps.

Thanks for that. Regarding using DB sequences instead of Servoy sequences, is it required to saveData() after every newRecord()? Any traps for the unwary?

As long as you don’t save to the DB, you don’t have a primary key. Once you start using related data, this, of course, is a problem. So just get used to do this:

controller.newRecord();
controller.saveData();

Then you don’t have to think about anything…

You need to use saveData() only when you also have to add a new related record of the newly created record.

Although in version 3 you can disable the auto-save and Servoy will handle all this in memory using temporary keys and will apply them accordingly when you use saveData() after the data entry/edit.
This technique is especially interesting in combination with transactions because you would only have a transaction open for less than a second or so (during the save), which would prevent most table/row-locking problems.

Hope this helps.

Guys, potential dumb question. I’m not sure what I’m doing wrong here. Servoy 3, Sybase as the backend. I have a form Invoices with a related tab panel Items. As a test, I’ve changed the sequence for items pk items_id to DB Identity. Now with an existing invoice, I create a new Item with

invoices_to_items.newRecord(false,true)
forms.items.controller.saveData()
// also tried 
// controller.saveData()

A new row appears in the items tab, but there’s no sequence number, and the new item ‘record’ (which presumably is just in memory at this stage) disappears as soon as I sort or move off this invoice. Same thing happens if I just create the new item directly with

controller.newRecord(false)
controller.saveData()

If I switch the PK for items back to Servoy managed, it works fine.

Am I meant to do something to the sybase db to get this to work.

Am I meant to do something to the sybase db to get this to work.

Absolutely!
This is something that’s up to you!

From Sybase central, the db already has the items_id columns set as a PK. I’m not sure what else to do (Servoy does such a great job of handling the SQL that I’m not as familiar as I should be with the back end).

Tony,

When you open Sybase Central do the following:

  1. Start up your repository and the db you want to use
  2. Select the table you want to adjust
  3. Double click the table
  4. Select the column with the PK you need
  5. CLick on the button in the Values column
  6. Select the ‘Default value’ radio button in the dialog you now have
  7. Select the ‘System-defined’ radio button that is now enabled
  8. Default value = ‘autoincrement’. This is fine.
  9. Click the OK button
  10. Save the new information
  11. Close Sybase Central

You should now be fine.

Hope this helps

Marcel, thanks as always for getting me on the right track here. I’d wrongly believed that setting a field as a PK in the backend meant it would default to autoincrement. :oops:
Step 7/8 was the missing piece of information. I appreciate your detailed response.

I’m still a little confused regarding autosave and transactions. Would the following be a proper way to handle the adding of a record, assuming I’m using db sequences?

databaseManager.startTransaction();
databaseManager.setAutoSave(false);

// user enters data, then clicks "Add" button
databaseManager.saveData();
databaseManager.commitTransaction();

Or, as ROCLASI is suggesting, something like:

databaseManager.setAutoSave(false);

// user enters data, then clicks "Add" button
databaseManager.startTransaction();
databaseManager.saveData();
databaseManager.commitTransaction();

Dumb question: do we still need transactions if autosave is false?

I have not played with this yet but I would say autosave is something you turn on or off per the database manager. Based on what behaviour you expect from it. Autosave the data or not :)

Basically autosave and transactions have nothing to do with each other although the first sort of mimics the second.

Autosave is really keeping everything you do within the Servoy environment (cache) until you want to save to your backend db. Advantage is that it will do so across all servers you have attached.

Transactions are performed on your backend db itself.

I lean towards the conclusion that when you use the first the second is not needed.

Hi Marcel,

On the surface it seems like autosave(false) replaces the need for any transaction commands, but I just want to be certain. I plan on experimenting with the autosave command soon. Another question: will Servoy grab the next primary key even though I’m not using the saveData command until the end? I think someone earlier in the thread mentioned “temporary” keys. Is that the same thing?