databaseManager.saveData(); Is doing weird things ??

Hi,
There seems to be a problem with ```
databaseManager.saveData()


var vRecord = arguments[0];
var vTable = ‘sales_rep_line_items’;
var vFoundsetRel = databaseManager.getFoundSet(currentcontroller.getServerName(),vTable);

vFoundsetRel.find();
vFoundsetRel.quotesid = vRecord.quotesid;
var vCount = vFoundsetRel.search();

if(vCount){ //update related records

for(var i=1; i<=vFoundsetRel.getSize(); i++)
{
    
    vFoundsetRel.setSelectedIndex(i);
   
	vFoundsetRel.sales_order_date = vRecord.ordered_date;
	vFoundsetRel.jon_number = vRecord.jon;
    vFoundsetRel.sales_order_total = vRecord.quote_total_inc;

	databaseManager.saveData();
    databaseManager.recalculate(vFoundsetRel.getRecord(1));
  
} 

} else {
return;
};

saveData returns a boolean value. Try setting this to a variable and see if you are getting a true or false value. If you are getting a false value, then there is something not allowing the save to continue.

Jason

Hi Jason,
That is the funny thing I have tried that and it returns true, but the data was not saved to the database??

What is the database platform? What JDBC driver are you using? What is the operating system? What versions?

If the statement returns true, I would lean to something going on at the database server level.

Jason

My Details,

Servoy Developer
Version 3.5.10-build 524
Java version 10.0-b23
Windows XP
MySQL 5.0.51
JDBC - mysql-connector-java-5.0.8-bin

Maybe a work around, should it be ok to do the following ?? as this seems to give more reliable results.

var vRecord = arguments[0];
var vTable = 'sales_rep_line_items';
var vFoundsetRel = databaseManager.getFoundSet(currentcontroller.getServerName(),vTable);

vFoundsetRel.find();
vFoundsetRel.quotesid = vRecord.quotesid;
var vCount = vFoundsetRel.search();

var vDateString = utils.dateFormat(vRecord.invoice_date,'yyyy/MM/dd 00:00:00');
var vFormDate = new Date(vDateString);

if(vCount){ 

var fsUpdater = databaseManager.getFoundSetUpdater(vFoundsetRel);
fsUpdater.setColumn('sales_order_date',vFormDate);
fsUpdater.setColumn('jon_number',vRecord.jon);
fsUpdater.setColumn('sales_order_total',vRecord.quote_total_inc);
var vSaved = fsUpdater.performUpdate();

databaseManager.recalculate(vFoundsetRel);

return vSaved;

} else {

return;
};

Hi

is this column: sales_order_date

a DATETIME column or a TEXT?

because if it is a DATETIME column your are putting a string in it, which does not work, because you do: var vDateString = utils.dateFormat(vRecord.invoice_date,‘yyyy/MM/dd 00:00:00’);

that could be the reason, that it is not saved?

UPDATE: I just see that you convert it back to datetime object…
Maybe comment out, 2 of the 3 update lines

fsUpdater.setColumn('sales_order_date',vFormDate);
//fsUpdater.setColumn('jon_number',vRecord.jon);
//fsUpdater.setColumn('sales_order_total',vRecord.quote_total_inc);

and see which columns give you the problem…

Hi Harjo,
Thanks for the reply, I posted the second method as a solution to my problem as it seems to work reliably. But I am not sure why databaseManager.saveData(); does not behaive in the same way as fsUpdater.performUpdate(); both should force a update statement to the database, but in my method only fsUpdater.performUpdate(); does. The reason I am processing the dates this way is to set the time component to 00:00:00 it seems a bit messy but maybe you could suggest a cleaner way ??

var vDateString = utils.dateFormat(vRecord.invoice_date,'yyyy/MM/dd 00:00:00');
var vFormDate = new Date(vDateString);

Thanks Again

Maybe you use some events on the table, that does something else?

using the foundsetUpdater skips those.

Harjo:
Maybe you use some events on the table, that does something else?

using the foundsetUpdater skips those.

OK, that is interesting, I do use table events, but does that mean there is a problem combining table events and databaseManager.saveData ??.

what do you do in those table events?

if you return false then the record will not be saved but then saveData() should return false