Skip to content

curzon01/lib_mysqludf_astro

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

master License

MySQL sun/moon astronomy functions

This repository contains the source code for a MySQL loadable function library (previously called UDF - User Defined Functions), which provides an additonal SQL astrononmy function to get astro sun and moon information for a given geographical location and time.

The calculations are based on an adaptation of the C++ Astronomy class from ESP32-Astronomie.

If you like lib_mysqludf_astro give it a star or fork it:

GitHub stars GitHub forks

Build instructions for GNU Make

Build and install

From the base directory run:

make clean
make
sudo make install

This will build and install the library file.

Localized binary

To create a country-specific version, call make command with the parameter LANG=-DLANG_xx, where xx is the country code: DE=German, ES=Spanish, FR=French, IT=Italian, NL=Netherlands, EN=English (default).

Example: Create and install a Dutch binary use

make clean
make LANG=-DLANG_NL
sudo make install

Finally we activate the loadable function in MySQL Server (replace username by a local MySQL user which has the permission to create functions, e. g. root)

mysql -u username -p < install.sql

Uninstall

To uninstall first deactive the loadable function within your MySQL server using the SQL queries:

DROP FUNCTION IF EXISTS astro_info;
DROP FUNCTION IF EXISTS astro;

then uninstall the library using command line:

sudo make uninstall

Usage

astro(date, latitude, longitude, timezone)

Returns astro info for given date, geolocation and timezone as JSON string.

Parameter

date

A given valid date in 'YYYY-MM-DD hh:mm:ss' format. Invalid dates results in a NULL value.

latitude

North–south position of a point in degrees format

longitude

East-West position of a point in degrees format

timezone

Time zone offset from UTC in hours

Return

The function returns the astro info as JSON string with the following keys:

JSON Key Description Format/Unit
$.Time Date for the given result 'YYYY-MM-DDThh:mm:ss'
$.Zone Time zone offset from UTC in hours hour
$.Latitude Geographic latitude degrees
$.Longitude Geographic longitude degrees
$.deltaT deltaT decimal
$.JulianDate Julian Date decimal
$.GMST Greenwich sidereal time 'hh:mm:ss'
$.LMST Local sidereal time 'hh:mm:ss'
$