sqlwrite round up number when use in stand alone app

2 views (last 30 days)
I have weird behavior with sqlwrite function when compile as standalone application. I use sqlwrite function to write float number to oracle database using odbc connection. Database is already set corresponding column type to be float(126). When I use function in appdesigner and test in desktop is work fine. Data that write to database was float example I write 123.45 --> database show 123.45.
But when I compile as .exe and test I seem it always round up weirdly. 1.234 --> 1, 14.123 --> 10, 241.123 --> 200. Don't know why it have different output between desktop and .exe.
Anyone have experience?

Answers (2)

Prathamesh on 22 Aug 2023
I understand that you are facing issue with “sqlwrite” function.
It depends on the column type, precision and scale defined, because of which the digits are rounded off or truncated. You can try to set precision of 38 and scale of 16 (or depending on the length of data) for the specific column to fit the data so that it will not get rounded off or truncated.
For example, you can try:
>> execute(conn,'CREATE TABLE testnumeric(COL1 numeric(38,16))')
>> sqlwrite(conn,'testnumeric',table(now,'VariableNames',{'COL1'}))
>> T = sqlread(conn,'testnumeric')
It will give the desired output.
You can also store the data into string in the database and then convert back to float or double in the implementation.
  1 Comment
chanapat pongsapich
chanapat pongsapich on 23 Aug 2023
Thanks for the respond Prathemexh. We have create the database outside matlab also already define the precision as max (126). And the issue is occur only when use in deployed mode (.exe), it work fine when run in Matlab desktop.

Sign in to comment.

Steven Lord
Steven Lord on 23 Aug 2023
I'm guessing that you're computing the values that are being rounded from the input arguments to your application. Is that correct? If so are you taking into account the first point in the "Using a MATLAB File You Plan to Deploy" section on this documentation page?
"The input arguments you pass to your executable from a system prompt are received as character vector input. Thus, if you expect the data in a different format (for example, double), you must first convert the character vector input to the required format in your MATLAB code. For example, you can use STR2NUM to convert the character vector input to numerical data." [Emphasis added.]
  1 Comment
chanapat pongsapich
chanapat pongsapich on 24 Aug 2023
Thanks for answer Steven, but I'm not use it in that way. My standalone app is GUI that build from appdesigner and the number that write to sql database is already been double since it work fine when we run GUI on MATLAB. But it have an issue when we export GUI to be standalone.

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!