Using Math Functions in ZeosLib SQLite3 SQL Statement

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
BytePlayer
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 21.09.2012, 10:13

Using Math Functions in ZeosLib SQLite3 SQL Statement

Post 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
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
BytePlayer
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 21.09.2012, 10:13

Post 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
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
BytePlayer
Fresh Boarder
Fresh Boarder
Posts: 24
Joined: 21.09.2012, 10:13

Post 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?
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post 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?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Post Reply