Hi,
I am trying to send data directly between my Servoy back end running on MS SQL to MySQL which is running my client’s web site.
I worked out how to do this by creating something called a ‘Linked Server’, which is using an ODBC connection to MySQL, and then a SQL statement called ‘OPENQUERY’, that uses the Linked Server.
I can do INSERTs without a problem, but I wanted to be able to do UPDATEs based on common keys.
I am trying to do this the correct way, using an arguments array etc., but it isn’t parsing correctly. I have done this directly in the back end tools, obviously using values directly, but wanted to get it working from Servoy.
Here is my code
// globals.ec_update_min_stock_flag(product_id , value);
var lv_serial_no = arguments[0] ;
var lv_flag_value = arguments[1] ;
var args = new Array();
args[0] = lv_serial_no ;
args[1] = lv_flag_value ;
//"UPDATE OPENQUERY(ABRSMPUB, 'SELECT * FROM fm_production WHERE serial_no = \"' + lv_serial_no + '\"' ) SET minStockForWeb = \'" + lv_flag_value + "\' ;") ;
var done = plugins.rawSQL.executeSQL("abrsm",
"products",
"UPDATE OPENQUERY(ABRSMPUB, 'SELECT * FROM fm_production WHERE serial_no = \'\'' + lv_serial_no + '\'\'' ) SET minStockForWeb = \'" + lv_flag_value + "\' ;") ;
if (!done)
{
var msg = plugins.rawSQL.getException().getMessage();
plugins.dialogs.showErrorDialog('Error', 'SQL exception: ' + msg , 'Ok' ) ;
}
I think my string formation isn’t quite correct, as the UPDATE line should be passed as
UPDATE OPENQUERY(ABRSMPUB, 'SELECT * FROM fm_production WHERE serial_no = ''1422''' ) SET minStockForWeb = 'Y' ;
with there being 2 single quotes/apostrophes before the 1422 and 3 after it, and just one before and after the Y
when I send it as above, I get the first error attached and if I add another \' after ```
lv_serial_no +
This code was just to do a test for a single record, but I intend to do it for a foundset of records.
Any help would be greatly appreciated <img src="{SMILIES_PATH}/icon_biggrin.gif" alt=":D" title="Very Happy" />
Thanks,
Rafi
[Screen shot 2009-12-15 at 23.44.05.pdf|attachment](upload://2PfpF0ZCmdz4oOjNs6WDRxePAxB.pdf) (10.7 KB)
[Screen shot 2009-12-15 at 23.43.16.pdf|attachment](upload://bcDdQLoM9C2ktz6UBF3fBVJqkqG.pdf) (12.4 KB)
You have 3 and 4 ’ chars instead of 2 and 3 in there. Try …'' + lv_serial_no + '''…
You can also use ’ directly instead of ' because your outer-most quotes are ". But it should work both ways.
Harjo:
Rafi, your are directly connected to the mySQL database right?
why do that via odbc & linked tables? why not use jdbc directly to mysql?
should be much easier…
just a thought.
sorry for not replying sooner…
Unfortunately I am not able to connect directly to the MySQL database as it requires an SSL connection for which I have been provided the Certificates & Keys (which I can configure the MySQL ODBC driver with…).
If you know of a way I can get Servoy to work with MySQL using SSL certificates etc., I would be very interested to know
I also think it is probably quicker to get the data to transfer directly via SQL statements through the back end.
Hi David,
wow! thanks for all that stuff on MySQL with SSL!
I might give that a go when I am at client next week.
In the mean time, I think I am just managing to get it working without Servoy talking to it directly…