scquery

scquery is a tool to run predefined MySQL queries. These queries are defined in a queries file, which should generally / MUST? be named ~/.seiscomp/queries.cfg.

Options

scquery supports command line options as well as configuration files (scquery.cfg). Queries are defined in the queries file queries.cfg (see below).

Command line options

In addition to the standard options, the following are supported:

-Q, --query arg
Execute the given query from the command line.
--showqueries
Show the stored queries in queries.cfg
Configuration
database.type <string>
e.g. "mysql"
database.parameters <string|
e.g. "sysop:sysop@localhost/seiscomp3"

Queries file queries.cfg

This file begins with a list of query names which will be defined:

queries = filter1, filter2, ...

For each filter, there should be a plain text description, and the filter itself, as an SQL query string:

query.filter1.description = "Returns all events that..."
query.filter1 = "select code, latitude, longitude from Station where ..."

Parameters for the query may by given as strings enclosed in hash signs ('#') of the form ##parameter##. The values of these parameters are supplied on the command line when scquery is invoked.

Example

In queries.cfg:

queries = lastevents_mysql
query.lastevents_mysql.description = "Returns the n last events"
query.lastevents_mysql = \
"select PEvent.publicID, Origin.time_value, Origin.evaluationMode, \
Origin.quality_usedPhaseCount, ROUND(Magnitude.magnitude_value,1), \
Magnitude.type, Magnitude.stationCount, \
IF(Origin.latitude_value < 0, CONCAT(ABS(ROUND(Origin.latitude_value,2)), ' S'), \
CONCAT(ABS(ROUND(Origin.latitude_value,2)), ' N')), \
IF(Origin.longitude_value < 0, CONCAT(ABS(ROUND(Origin.longitude_value,2)), ' W'),\
CONCAT(ABS(ROUND(Origin.longitude_value,2)), ' E')), \
CONCAT(ROUND(Origin.depth_value), ' km'), \
EventDescription.text from Event, PublicObject as PEvent, EventDescription, Origin, \
PublicObject as POrigin, Magnitude, PublicObject as PMagnitude where Event._oid=PEvent._oid \
and Origin._oid=POrigin._oid and Magnitude._oid=PMagnitude._oid and \
Event.preferredOriginID=POrigin.publicID and Event.preferredMagnitudeID=PMagnitude.publicID \
and Event._oid=EventDescription._parent_oid and EventDescription.type='region name' order \
by Origin.time_value desc limit 0,##numberOfEvents##"

Here ##numberOfEvents## is a parameter supplied to the query from the command line. To obtain information about the queries which are defined:

> scquery --showqueries
[ 1 queries found ]

Query name: lastevents_mysql
Description: Returns the last n events
number of parameter: 1
Parameter: numberOfEvents 

Executing this query to show the last 4 events:

scquery lastevents_mysql 4

produces output of the form:

gfz2011uwxu | 2011-10-25 08:18:46 | automatic | 11 | 6.9 | M | 11 | 21.82 S | 5.52 E   | 10 km  | South Atlantic Ocean            
gfz2011uwuk | 2011-10-25 06:36:36 | automatic | 34 | 4.1 | M | 34 | 39.59 N | 43.72 E  | 101 km | Turkey                          
gfz2011uwtl | 2011-10-25 06:07:36 | automatic | 58 | 5.4 | M | 55 | 11.75 S | 13.97 W  | 10 km  | Ascension Island Region         
gfz2011uwpb | 2011-10-25 03:54:09 | automatic | 10 | 4.4 | M | 6  | 35.72 N | 141.57 E | 109 km | Near East Coast of Honshu, Japan