Issue using function LN, EXP, Power in sql query

Discussions about CSEntry
Post Reply
thierryt
Posts: 52
Joined: April 26th, 2017, 12:17 pm

Issue using function LN, EXP, Power in sql query

Post 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.
htuser
Posts: 687
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

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

Post 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,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1947
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

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

Post 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)")));
thierryt
Posts: 52
Joined: April 26th, 2017, 12:17 pm

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

Post 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
Post Reply