casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SearcherSQLite.h
Go to the documentation of this file.
00001 //# Copyright (C) 2004
00002 //# Associated Universities, Inc. Washington DC, USA.
00003 //#
00004 //# This library is free software; you can redistribute it and/or modify it
00005 //# under the terms of the GNU Library General Public License as published by
00006 //# the Free Software Foundation; either version 2 of the License, or (at your
00007 //# option) any later version.
00008 //#
00009 //# This library is distributed in the hope that it will be useful, but WITHOUT
00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012 //# License for more details.
00013 //#
00014 //# You should have received a copy of the GNU Library General Public License
00015 //# along with this library; if not, write to the Free Software Foundation,
00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00017 //#
00018 //# Correspondence concerning AIPS++ should be addressed as follows:
00019 //#        Internet email: aips2-request@nrao.edu.
00020 //#        Postal address: AIPS++ Project Office
00021 //#                        National Radio Astronomy Observatory
00022 //#                        520 Edgemont Road
00023 //#                        Charlottesville, VA 22903-2475 USA
00024 #ifndef SEARCHERSQLITE_H_
00025 #define SEARCHERSQLITE_H_
00026 
00027 #include <spectrallines/Splatalogue/Searcher.h>
00028 #include <spectrallines/Splatalogue/SplatResult.h>
00029 
00030 class sqlite3;
00031 class sqlite3_stmt;
00032 
00033 using namespace std;
00034 
00035 namespace casa {
00041 class SearcherSQLite : public Searcher{
00042 public:
00043         SearcherSQLite( const string& databasePath);
00044 
00049         string tableInfo( const string& tableName, string& errorMsg ) const;
00050 
00054         string getCreatedDate() const;
00055         virtual bool isConnected() const;
00056         virtual void stopSearch();
00057 
00058         //Set all the search parameters back to their defaults.
00059         virtual void reset();
00060 
00061         //Search Paramaters
00062         virtual void setChemicalNames( const vector<string>& chemNames );
00063         virtual void setSpeciesNames( const vector<string>& speciesNames );
00067         virtual void setFrequencyRange( double minValue, double maxValue );
00068         virtual void setIntensityRange( double minValue, double maxValue );
00069         virtual void setSmu2Range( double minValue, double maxValue );
00070         virtual void setLogaRange( double minValue, double maxValue );
00071         virtual void setElRange( double minValue, double maxValue );
00072         virtual void setEuRange( double minValue, double maxValue );
00073         virtual void setQNS( const vector<string>& qns );
00074 
00075 
00076         //Astronomical Filters
00077         virtual void setFilterTop20( bool filter = true );
00078         virtual void setFilterPlanetaryAtmosphere( bool filter = true );
00079         virtual void setFilterHotCores( bool filter = true );
00080         virtual void setFilterDarkClouds( bool filter = true );
00081         virtual void setFilterDiffuseClouds( bool filter = true );
00082         virtual void setFilterComets( bool filter = true );
00083         virtual void setFilterAgbPpnPn( bool filter = true );
00084         virtual void setFilterExtragalactic( bool filter = true );
00085 
00086         //Performing the Search
00094         virtual vector<SplatResult> doSearch( string& errorMsg, int offset );
00095         virtual long doSearchCount( string& errorMsg );
00102         virtual void setSearchResultLimit( int limit );
00103         virtual ~SearcherSQLite();
00104 
00105 private:
00106         bool executeQuery( sqlite3_stmt*& statement, const string& query,
00107                 string& errorMsg ) const;
00108         /*
00109          * Constructs the SQL for a SELECT query based on the search parameters
00110          * that have been previously set.  If 'countOnly' is set to true, the
00111          * query will return the number of rows matching the search criteria;
00112          * otherwise, it will all columns in the rows matching the search criteria.
00113          * The 'offset' parameter indicates the starting index for the first row
00114          * matching the search criteria.
00115          */
00116         string prepareQuery( bool countOnly, int offset ) const;
00117         std::string getTrue() const;
00118         string numToString( double number ) const;
00119         string getBetweenClause( const string& columnName, double low, double high) const;
00120         string getInClause( const string& columnName, const vector<string>& values ) const;
00121 
00122         //Set-up
00123         sqlite3* db;
00124 
00125         //Search parameters
00126         double minValueFreq;
00127         double maxValueFreq;
00128         double minValueIntensity;
00129         double maxValueIntensity;
00130         double minValueSmu2;
00131         double maxValueSmu2;
00132         double minValueLoga;
00133         double maxValueLoga;
00134         double minValueEl;
00135         double maxValueEl;
00136         double minValueEu;
00137         double maxValueEu;
00138         bool recommendedOnly;
00139         vector<string> speciesNames;
00140         vector<string> chemicalNames;
00141         vector<string> qns;
00142 
00143 
00144         enum FILTER_LIST { FILTER_TOP_20, FILTER_PLANETARY_ATMOSPHERE, FILTER_HOT_CORES,
00145                 FILTER_DARK_CLOUDS, FILTER_DIFFUSE_CLOUDS, FILTER_COMETS, FILTER_AGB_PPN_PN,
00146                 FILTER_EXTRAGALACTIC, END_FILTERS };
00147         vector<bool> filters;
00148         static vector<string> filterNames;
00149 
00150         //Table Names
00151         const static std::string TABLE_MAIN;
00152         const static std::string TABLE_SPECIES;
00153 
00154         //Table columns
00155         const static std::string FREQUENCY_COLUMN;
00156         const static std::string SPECIES_ID_COLUMN;
00157         const static std::string SPECIES_COLUMN;
00158         const static std::string SMU2_COLUMN;
00159         const static std::string EL_COLUMN;
00160         const static std::string EU_COLUMN;
00161         const static std::string LOGA_COLUMN;
00162         const static std::string INTENSITY_COLUMN;
00163         const static std::string RESOLVED_QNS_COLUMN;
00164         const static std::string CHEMICAL_NAME_COLUMN;
00165         enum TableColumns { SPECIES_ID_COL, SPECIES_NAME_COL, CHEMICAL_NAME_COL,
00166                 FREQUENCY_COL, RESOLVED_QNS_COL, INTENSITY_COL, SMU2_COL, LOGA_COL, EL_COL,
00167                 EU_COL, END_COL };
00168         static std::vector<string> resultColumns;
00169 
00170 
00171         const static std::string FILTER_KNOWN_AST_COLUMN;
00172         const static std::string FILTER_PLANET_COLUMN;
00173         const static std::string FILTER_HOTCORE_COLUMN;
00174         const static std::string FILTER_DIFFUSECLOUD_COLUMN;
00175         const static std::string FILTER_DARKCLOUD_COLUMN;
00176         const static std::string FILTER_COMET_COLUMN;
00177         const static std::string FILTER_EXTRAGALACTIC_COLUMN;
00178         const static std::string FILTER_AGB_PPN_PN_COLUMN;
00179         const static std::string FILTER_TOP20_COLUMN;
00180 
00181 
00182         //SQL Constants
00183         const static std::string FROM;
00184         const static std::string SELECT;
00185         const static std::string BETWEEN;
00186         const static std::string AND;
00187         const static std::string OPEN_PAREN;
00188         const static std::string CLOSE_PAREN;
00189         const static std::string SINGLE_QUOTE;
00190         const static std::string COMMA;
00191         const static std::string PERIOD;
00192         const static std::string EQUALS;
00193         const static std::string IN;
00194 
00195         const static int DEFAULT_VALUE;
00196 
00197         //Limiting the number of rows returned by a search.
00198         int rowLimit;
00199 };
00200 }
00201 #endif /* SEARCHLOCAL_H_ */