Page 1 of 1

Using Math Functions in ZeosLib SQLite3 SQL Statement

Posted: 21.09.2012, 11:04
by BytePlayer
I found the function definitions in ZFunctionsMath and they SEEM to be created but whenever I try to use them in an SQL Statement it fails, badly. ASC() however seems to work.

I am using Delphi EX2 and SQLite3 in case that makes a difference.

Thanks in advance,

Ken

Posted: 21.09.2012, 13:48
by EgonHugeist
BytePlayer,

i have no idea what you are trying to do. Can you give us a code snipped to show what you are trying to do? These funtions are mainly made for our internal resultsets, there filters and sorting orders. But they are not useable for a statment..

Posted: 21.09.2012, 21:36
by BytePlayer
SELECT *, SIN(LONGITUDE-655)*COS(LATITTUDE-32) as Distance FROM CITIES ORDER BY Distance

Obviously the math there I just made up :D but that's the idea of what I want to do.

Or another example which does work as is, but would be much cleaner if I had access to SQUARE function for example

SELECT *, (((LONGITUDE-655)* (LONGITUDE-655)) + ((LATITTUDE-32)*(LATITTUDE-32))) as Distance FROM CITIES ORDER BY Distance

I would prefer:

SELECT *, (SQUARE(LONGITUDE-655) + SQUARE(LATITTUDE-32)) as Distance FROM CITIES ORDER BY Distance

Posted: 23.09.2012, 09:48
by EgonHugeist
BytePlayer,

Well this i understand. But you are talking with the database not with zeos in this case. It can work properly if you know the values LONGITUDE and LATITTUDE before..

Posted: 23.09.2012, 22:33
by BytePlayer
I'm not following -- basically I want to do a query which returns the closest city to a given longitude and latitude. The Table of Cities contains, CityName, ClityLongitude and CityLatitude.

The accurate calculation of distance is a mess of squares, sins, cos arctan2, sqrt and it seems like they should be definable with
the sqlite3_create_function() -- is there a wrapper for this within ZeosLib?

Posted: 24.09.2012, 11:31
by EgonHugeist
BytePlayer,

i do understand what you wnat to do. A wrapper makes sence IF you know then values of CITIES.LONGITUDE and CITIES.LATITTUDE before sendinig a request to the database.

You cant wrapp functions from your/Zeos source code to the database. Other database do support stored procedures/funtions which you can create before and call them as DDL in your request. But there is no way to use database unknown functions/procedures. OR do i missunderstand you completely?