casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SearcherSQLite.h
Go to the documentation of this file.
1 //# Copyright (C) 2004
2 //# Associated Universities, Inc. Washington DC, USA.
3 //#
4 //# This library is free software; you can redistribute it and/or modify it
5 //# under the terms of the GNU Library General Public License as published by
6 //# the Free Software Foundation; either version 2 of the License, or (at your
7 //# option) any later version.
8 //#
9 //# This library is distributed in the hope that it will be useful, but WITHOUT
10 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 //# License for more details.
13 //#
14 //# You should have received a copy of the GNU Library General Public License
15 //# along with this library; if not, write to the Free Software Foundation,
16 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
17 //#
18 //# Correspondence concerning AIPS++ should be addressed as follows:
19 //# Internet email: aips2-request@nrao.edu.
20 //# Postal address: AIPS++ Project Office
21 //# National Radio Astronomy Observatory
22 //# 520 Edgemont Road
23 //# Charlottesville, VA 22903-2475 USA
24 #ifndef SEARCHERSQLITE_H_
25 #define SEARCHERSQLITE_H_
26 
29 
30 class sqlite3;
31 class sqlite3_stmt;
32 
33 using namespace std;
34 
35 namespace casa {
41 class SearcherSQLite : public Searcher{
42 public:
43  SearcherSQLite( const string& databasePath);
44 
49  string tableInfo( const string& tableName, string& errorMsg ) const;
50 
54  string getCreatedDate() const;
55  virtual bool isConnected() const;
56  virtual void stopSearch();
57 
58  //Set all the search parameters back to their defaults.
59  virtual void reset();
60 
61  //Search Paramaters
62  virtual void setChemicalNames( const std::vector<string>& chemNames );
63  virtual void setSpeciesNames( const std::vector<string>& speciesNames );
67  virtual void setFrequencyRange( double minValue, double maxValue );
68  virtual void setIntensityRange( double minValue, double maxValue );
69  virtual void setSmu2Range( double minValue, double maxValue );
70  virtual void setLogaRange( double minValue, double maxValue );
71  virtual void setElRange( double minValue, double maxValue );
72  virtual void setEuRange( double minValue, double maxValue );
73  virtual void setQNS( const std::vector<string>& qns );
74 
75 
76  //Astronomical Filters
77  virtual void setFilterTop20( bool filter = true );
78  virtual void setFilterPlanetaryAtmosphere( bool filter = true );
79  virtual void setFilterHotCores( bool filter = true );
80  virtual void setFilterDarkClouds( bool filter = true );
81  virtual void setFilterDiffuseClouds( bool filter = true );
82  virtual void setFilterComets( bool filter = true );
83  virtual void setFilterAgbPpnPn( bool filter = true );
84  virtual void setFilterExtragalactic( bool filter = true );
85 
86  //Performing the Search
94  virtual std::vector<SplatResult> doSearch( string& errorMsg, int offset );
95  virtual long doSearchCount( string& errorMsg );
102  virtual void setSearchResultLimit( int limit );
103  virtual ~SearcherSQLite();
104 
105 private:
106  bool executeQuery( sqlite3_stmt*& statement, const string& query,
107  string& errorMsg ) const;
108  /*
109  * Constructs the SQL for a SELECT query based on the search parameters
110  * that have been previously set. If 'countOnly' is set to true, the
111  * query will return the number of rows matching the search criteria;
112  * otherwise, it will all columns in the rows matching the search criteria.
113  * The 'offset' parameter indicates the starting index for the first row
114  * matching the search criteria.
115  */
116  string prepareQuery( bool countOnly, int offset ) const;
117  std::string getTrue() const;
118  string numToString( double number ) const;
119  string getBetweenClause( const string& columnName, double low, double high) const;
120  string getInClause( const string& columnName, const std::vector<string>& values ) const;
121  string getLikeClause( const string& columnName, const std::vector<string>& values ) const;
122 
123  //Set-up
124  sqlite3* db;
125 
126  //Search parameters
127  double minValueFreq;
128  double maxValueFreq;
131  double minValueSmu2;
132  double maxValueSmu2;
133  double minValueLoga;
134  double maxValueLoga;
135  double minValueEl;
136  double maxValueEl;
137  double minValueEu;
138  double maxValueEu;
139  //bool recommendedOnly;
140  std::vector<string> speciesNames;
141  std::vector<string> chemicalNames;
142  std::vector<string> qns;
143 
144 
145  enum FILTER_LIST { FILTER_TOP_20, FILTER_PLANETARY_ATMOSPHERE, FILTER_HOT_CORES,
146  FILTER_DARK_CLOUDS, FILTER_DIFFUSE_CLOUDS, FILTER_COMETS, FILTER_AGB_PPN_PN,
147  FILTER_EXTRAGALACTIC, END_FILTERS };
148  std::vector<bool> filters;
149  static std::vector<string> filterNames;
150 
151  //casacore::Table Names
152  const static std::string TABLE_MAIN;
153  const static std::string TABLE_SPECIES;
154 
155  //casacore::Table columns
156  const static std::string FREQUENCY_COLUMN;
157  const static std::string TEMPERATURE_COLUMN;
158  const static std::string SPECIES_ID_COLUMN;
159  const static std::string SPECIES_COLUMN;
160  const static std::string SMU2_COLUMN;
161  const static std::string EL_COLUMN;
162  const static std::string EU_COLUMN;
163  const static std::string LOGA_COLUMN;
164  const static std::string INTENSITY_COLUMN;
165  const static std::string RESOLVED_QNS_COLUMN;
166  const static std::string CHEMICAL_NAME_COLUMN;
167  enum TableColumns { SPECIES_ID_COL, SPECIES_NAME_COL, CHEMICAL_NAME_COL,
168  FREQUENCY_COL, TEMPERATURE_COL, RESOLVED_QNS_COL, INTENSITY_COL, SMU2_COL, LOGA_COL, EL_COL,
169  EU_COL, END_COL };
170  static std::vector<string> resultColumns;
171 
172 
173  const static std::string FILTER_KNOWN_AST_COLUMN;
174  const static std::string FILTER_PLANET_COLUMN;
175  const static std::string FILTER_HOTCORE_COLUMN;
176  const static std::string FILTER_DIFFUSECLOUD_COLUMN;
177  const static std::string FILTER_DARKCLOUD_COLUMN;
178  const static std::string FILTER_COMET_COLUMN;
179  const static std::string FILTER_EXTRAGALACTIC_COLUMN;
180  const static std::string FILTER_AGB_PPN_PN_COLUMN;
181  const static std::string FILTER_TOP20_COLUMN;
182 
183 
184  //SQL Constants
185  const static std::string FROM;
186  const static std::string SELECT;
187  const static std::string BETWEEN;
188  const static std::string AND;
189  const static std::string OPEN_PAREN;
190  const static std::string CLOSE_PAREN;
191  const static std::string SINGLE_QUOTE;
192  const static std::string COMMA;
193  const static std::string PERIOD;
194  const static std::string EQUALS;
195  const static std::string IN;
196  const static std::string LIKE;
197  const static std::string OR;
198 
199  const static int DEFAULT_VALUE;
200 
201  //Limiting the number of rows returned by a search.
202  int rowLimit;
203 };
204 }
205 #endif /* SEARCHLOCAL_H_ */
static const std::string IN
static const std::string SPECIES_ID_COLUMN
static const std::string EL_COLUMN
virtual void reset()
Overrides PlotTool::reset().
static const std::string FILTER_COMET_COLUMN
static const std::string SINGLE_QUOTE
static const int DEFAULT_VALUE
static const std::string SPECIES_COLUMN
static const std::string OPEN_PAREN
static const std::string FILTER_TOP20_COLUMN
static const std::string SELECT
std::vector< string > chemicalNames
static const std::string FILTER_DIFFUSECLOUD_COLUMN
Interface needed to support molecular line searching and identification.
Definition: Searcher.h:35
static const std::string LOGA_COLUMN
std::vector< string > qns
static const std::string OR
static const std::string FILTER_KNOWN_AST_COLUMN
static const std::string TEMPERATURE_COLUMN
static const std::string INTENSITY_COLUMN
std::vector< string > speciesNames
bool recommendedOnly;
Searches a local sqlite database for molecular lines meeting the specified search criteria...
static const std::string FILTER_HOTCORE_COLUMN
sqlite3 * db
Set-up.
static std::vector< string > filterNames
static const std::string COMMA
static const std::string AND
double minValueFreq
Search parameters.
static const std::string FILTER_DARKCLOUD_COLUMN
static const std::string FILTER_AGB_PPN_PN_COLUMN
static const std::string EQUALS
static const std::string BETWEEN
static const std::string EU_COLUMN
std::vector< bool > filters
static const std::string FILTER_PLANET_COLUMN
static const std::string SMU2_COLUMN
static const std::string FREQUENCY_COLUMN
casacore::Table columns
std::set< ScanKey > filter(const std::set< ScanKey > scans, const ArrayKey &arrayKey)
given a set of scan keys, return the subset that matches the given array key
static const std::string FILTER_EXTRAGALACTIC_COLUMN
static const std::string TABLE_SPECIES
static std::vector< string > resultColumns
static const std::string LIKE
static const std::string RESOLVED_QNS_COLUMN
static const std::string CLOSE_PAREN
static const std::string TABLE_MAIN
casacore::Table Names
static const std::string CHEMICAL_NAME_COLUMN
static const std::string PERIOD
static const std::string FROM
SQL Constants.
int rowLimit
Limiting the number of rows returned by a search.