I want to be able to run a rawSQL statement within a read_ws() method. The parameters of read_ws() will be passed to an array called args. Some fields from the table will be pieces of an object and passed to the same array using foundset.
Could it be that the the sql statement calls on too many arguments from the args array?
var sql = 'UPDATE price SET ? = ?, ? = ? WHERE ? = ?'
Am I assigning the database and table correctly?
var databaseProductName = databaseManager.getDatabaseProductName(databaseManager.getDataSourceServerName(databaseManager.getDataSourceTableName(controller.getDataSource())))
var tablename = databaseManager.getDataSourceTableName(controller.getDataSource());
Then I’m not sure if I’m using the rawSQL plugin correctly or flushing
var execute = plugins.rawSQL.executeSQL(databaseProductName,tablename,sql, args)
if(execute)
{
plugins.rawSQL.flushAllClientsCache(databaseProductName,tablename)
If I could get what I’ve done incorrectly pointed out, that would be shweet.
I think this would theoretically work, however, I cannot manage to make it work. The Whole source is below…
/**
* @AllowToRunInFind
*
* // TODO generated, please specify type and doc for the params
*
* @param {Object} id
*
* @param {String} value1
*
* @param {Number} value2
*
* @param {Object} condition
*
* @properties={typeid:24,uuid:"2C0BD4FC-41AB-4DC6-886D-909C947668FA"}
*/
function ws_read(id,value1,value2,condition){
if (id)
{
if (foundset.find())
{
foundset.fld1 = id
if (foundset.search() == 1)
{
var databaseProductName = databaseManager.getDatabaseProductName(databaseManager.getDataSourceServerName(databaseManager.getDataSourceTableName(controller.getDataSource())))
var tablename = databaseManager.getDataSourceTableName(controller.getDataSource());
var part = new Object()
part.partDesc = foundset.fld2
part.partCost = foundset.fld7
part.hardware = foundset.fld1
var args = new Array();
args[0] = part.partDesc
args[1] = value1
args[2] = part.partCost
args[3] = value2
args[4] = part.hardware
args[5] = condition
var sql = 'UPDATE price SET ? = ?, ? = ? WHERE ? = ?'
var execute = plugins.rawSQL.executeSQL(databaseProductName,tablename,sql, args)
if(execute)
{
plugins.rawSQL.flushAllClientsCache(databaseProductName,tablename)
}else{
var msg = plugins.rawSQL.getException().getMessage(); //see exception node for more info about the exception obj
plugins.dialogs.showErrorDialog('Error', 'SQL exception: ' + msg, 'Ok')
}
// Note that when this function is used to create a new table in the database, this table will only be seen by
// the Servoy Application Server when the table name starts with 'temp_', otherwise a server restart is needed.
}
}
}
return null
}