Concatenation issue
Posted: Sat Feb 29, 2020 12:18 am
Greeting and happy Friday.
I have an issue where when I build a SQL statement (yes, it should be a parameterized stored proc but this is a test) in Live Code. As most know, when searching a varchar value in a database you have to have the value surrounded by apostrophes (single quotes as some call it). I have tried this in both Live Code Community and Indy 9.51 and the same issue occurs. Here is the code:
if field "fieldUPC" is not empty then
put field("fieldUPC") & "'" into sQL
answer sQL <--just to peek
put "SELECT * FROM inventory_orders.pd_supplier_product where UPC='" & sQL into tSQL
answer tSQL <--Just to peek
put testQuery(tSQL) into rtData
Sample "fieldUPC" value: 656295060238
The first time you start live code and run, it will work fine. After that, until you restart LC, it will not add the second apostrophe at the end of the string. I find if I put a regular string (say an alpha-numeric instead of just numeric type entry), it will work fine. It seems to be a typing issue (in this untyped language). Has anyone else run into this? I could pass the value as a numeric and then CAST() the value to a string. But this seems like this is a bug in LC. Suggestions? TIA.
I have an issue where when I build a SQL statement (yes, it should be a parameterized stored proc but this is a test) in Live Code. As most know, when searching a varchar value in a database you have to have the value surrounded by apostrophes (single quotes as some call it). I have tried this in both Live Code Community and Indy 9.51 and the same issue occurs. Here is the code:
if field "fieldUPC" is not empty then
put field("fieldUPC") & "'" into sQL
answer sQL <--just to peek
put "SELECT * FROM inventory_orders.pd_supplier_product where UPC='" & sQL into tSQL
answer tSQL <--Just to peek
put testQuery(tSQL) into rtData
Sample "fieldUPC" value: 656295060238
The first time you start live code and run, it will work fine. After that, until you restart LC, it will not add the second apostrophe at the end of the string. I find if I put a regular string (say an alpha-numeric instead of just numeric type entry), it will work fine. It seems to be a typing issue (in this untyped language). Has anyone else run into this? I could pass the value as a numeric and then CAST() the value to a string. But this seems like this is a bug in LC. Suggestions? TIA.