please any one , help me ,
Actually my problem is , I generate next sequence by getNextSequence,
now my next sequence is generated, then i want to insert data to the others fields of that table aginst this sequenc no.
My problem is, when i insert data to the other field I fired newRecord and it increse the sequnce. My all data saved against this sequence rather than the sequence which is generated by getNextSequence
Do you use Servoy sequences or database managed sequences ?
I am using servoy sequence
I just tested this with database managed sequences.
var id = databaseManager.getNextSequence(controller.getServerName(), controller.getTableName(), "tbl_id");
application.output("getNextSequence="+id); // debug
controller.newRecord(true);
tbl_id = id;
controller.saveData()
application.output("Record ID="+tbl_id); // debug
// See if it was updated again...
id = databaseManager.getNextSequence(controller.getServerName(), controller.getTableName(), "tbl_id");
application.output("getNextSequence="id); // debug
This results in the following output:
getNextSequence=15.0
Record ID=15.0
getNextSequence=17.0
As you can see the sequence does get updated even when you insert your own ID value.
Is this what you are seeing too?
In my opinion when you assign a value yourself to the column with a sequence then Servoy shouldn’t trigger/update the sequence. When you do this directly on the database this also doesn’t trigger/update the sequence.
Servoy Developer
Version 3.1.6-build 410
Java version 1.5.0_07-87 (Mac OS X)
Thanks Robert,
In your example you get sequence 15 by getNextSequence and when you save data it generate 16 and you make it 15 but in data bast the current index is 16 and next index will be 17.
So, we mantion a step 1 but user can see a step 2 of the sequence, how we solve this ?
My code was also same as like you
var req = databaseManager.getNextSequence(example_data, tbl_req, req_no)
controller.newRecord();
req_no1 = val1;
req_no2 = val2;
I not assign any sequnce field.
My out put was
req = 15
req_no = 16
I guess the question is why you use the getNextSequence function in the first place
When you use this then it actually updates the sequence and fetches that value.
When you create a new record then Servoy does the same thing and you end up with a sequence that is updated twice.
Is there a reason why you want to fetch the next sequence before you create a new record?
In my example where I do set the id value then Servoy shouldn’t update the sequence. At least I believe that is how it should work because this is how it also works in database servers like PostgreSQL.
I will file a bugreport for this.
Hope this helps.
Actually in case of some order like in servoy sample crm solution where we give the customer , the order no and customer give order against that no.
In my solution the field must be servoy sequence.
I can’t do this by getMaxRecordIndex and then get the sequence value and give the user with 1 increment of last record in a global field and in backend continue with the sequence.
Maybe you should manage this yourself.
Take a look at this thread about invoicenumbers.
http://forum.servoy.com/viewtopic.php?t=3705
Hope this helps.
I received a follow up on my bug report: (emphasis is mine)
Status: closed-invalid
Resolution:
Hello,If we understand the case correctly, you are using databaseManager.getNextSequence and controller.newRecord on the same table.
Both increment the sequence causing the gaps.
This is designed behaviour.If you want to use a sequence value that is also in the table, you can just use the value after calling newrecord.
If you want separate control of sequences, you may want to use a separate sequences-table using databaseManager.getNextSequence and have no sequence on your data-table.
Hope this help,
Servoy Support
Description:
When creating a new record and assigning a value (like fetched via getNextSequence) to a column that has a sequence defined will still trigger the sequence.
Although it doesn’t override my assigned value it does cause the sequence to have gaps since it’s triggered twice (once by using getNextSequence).
When I insert data via a third party tool into the back-end database my database managed sequence won’t be triggered when I assign a value.
So I guess if someone really needs this to work as the back-end database does then file a feature request for this.
Hope this helps.
Thanks Robert ,
Actually i already did that with a help of sequence table and no sequence in data table.
But problem is that we have to use two table.(One helping table).
We can do that another way, table which have no sequence but it store last value and incremented for every new record for data table. This table have only single row and single column.
Hi Robert,
I get null as result by doing:
var vTargetTable = forms[vTargetForm].controller.getTableName()
var vTargetServer = forms[vTargetForm].controller.getServerName()
var vTargetPKField = vTargetTable + '_id'
var vNextSequence = databaseManager.getNextSequence(vTargetServer, vTargetTable, vTargetPKField)
All variables are set correcty, I only don’t get the next sequence.
I use Sybase db-sequences and Servoy Developer
Version 3.5.2_04-build 515
Java version 1.6.0_02-b06 (Windows XP)
Any idea what could be wrong here?
Hi karel,
I am not that familiar with Sybase in combination with db sequences. Does it use sequence names or do you use db identity. If it’s the former does Servoy use the correct sequence name (see dataproviders dialog) ?
Hope this helps.
I’m using db identity, so I guess that doesn’t help, either.
I’ll create a new post in the Issues & Bugs forum.