Page 1 of 1

Issue using function LN, EXP, Power in sql query

Posted: March 28th, 2025, 6:16 am
by thierryt
Hi All,
please I have an issue when I want to execute a query that contains function LN and EXP, using sqlquery.
In fact I want to calculate the geometrical average for a field.
Please any solution about that ?
Thanks.

Re: Issue using function LN, EXP, Power in sql query

Posted: March 28th, 2025, 10:21 am
by htuser
CSPro Logic support all the sql supported by Sqlite. However sometimes, you could need to use some workarounds when writing sql strings in CSPro logic. If you share a small example (demo app) of what you need to do, I'll try to help you writing this query.
Best,

Re: Issue using function LN, EXP, Power in sql query

Posted: March 28th, 2025, 11:16 am
by Gregory Martin
SQLite has a variety of functions that you can use in queries: https://www.sqlite.org/lang_mathfunc.html

However, they are not enabled in the current version of CSPro. I will enable them for CSPro 8.1.

For now, you can mark a CSPro function as usable in a SQLite query: https://www.csprousers.org/help/CSPro/s ... tions.html

For example, here is how you can use exp in a SQLite query:
// SQLite callback function
function sql numeric cs_exp(numeric value)
    exit exp(value);
end;

// ...

// using the CSPro function (displays 148.413159)
errmsg("%v", exp(5));

// using the Action Invoker to query SQLite using a temporary database (displays 148.413159)
numeric dbId = tonumber(CS.Sqlite.open(path := ""));
errmsg("%v", tonumber(CS.Sqlite.exec(db := dbId, sql := "SELECT cs_exp(5)")));

Re: Issue using function LN, EXP, Power in sql query

Posted: March 28th, 2025, 11:45 am
by thierryt
Thanks a lot Greg,
I used one function for expo and another for logarithm as you shown on this example and it runs well