Max Column Value

I am using the following to try and find the maximum value of a column so I can increment it by one. I am reporting to a lbl for my ref.

var vQuery = 'SELECT MAX(project_number) FROM project';
var max_number = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), vQuery, null, 1) ;
forms.project_dlg_quick.elements.lbl_value.text = max_number

Why is this returning “BufferedDataSet{[100500]}”. (100500 is the correct max value)

Hi James,

databaseManager.getDataSetByQuery() returns what the functions says…a DataSet.
Check the databaseManager node to see what the DataSet has for methods to get the value(s).

Hope this helps.

try this:

var vQuery = 'SELECT MAX(project_number) FROM project';
var max_number = databaseManager.getDataSetByQuery(currentcontroller.getServerName(), vQuery, null, 1) ;
forms.project_dlg_quick.elements.lbl_value.text = max_number.getValue(1,1)

Thanks to you both. I did work out my answer was: ```
project_number = vDataset.getValue(1,1)+ 1


Have a great weekend.

oke, I see what you are doing,

but if you don’t want to get into trouble, with not unique projectnumbers, you have to do some record locking.

for instance, 2 or more people, can do this query exactly the same time, than you will end up with not unique projectnumbers.

hope this helps ;-)

I have a unique index on the column. I was going to have servoy capture any sql errors on save, if it can. Would file locking be a better option?

The safest way is to define your column as sequence in the column properties, if you don’t want this another option is to define an unused column as Servoy Sequence on a dummy or sequence table and use databaseManager.getNextSequence(‘myserver’,‘mySequenceTable’,‘sequenceX’)