LCOV - code coverage report
Current view: top level - spectrallines/Splatalogue/SQLiteSearch - DatabaseConnector.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 25 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 5 0.0 %

          Line data    Source code
       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: casa-feedback@nrao.edu.
      20             : //#        Postal address: AIPS++ Project Office
      21             : //#                        National Radio Astronomy Observatory
      22             : //#                        520 Edgemont Road
      23             : //#                        Charlottesville, VA 22903-2475 USA
      24             : //#
      25             : 
      26             : #include "DatabaseConnector.h"
      27             : #include <sys/stat.h>
      28             : #include <sqlite3.h>
      29             : #include <iostream>
      30             : using namespace std;
      31             : 
      32             : namespace casa {
      33             : 
      34             : DatabaseConnector* DatabaseConnector::connection = NULL;
      35             : bool DatabaseConnector::successfulOpen = true;
      36             : 
      37             : string DatabaseConnector::databasePath = "";
      38             : 
      39           0 : DatabaseConnector::DatabaseConnector( const string& path ) {
      40           0 :         databasePath = path;
      41           0 :         int rc = sqlite3_open( databasePath.c_str(), &db );
      42           0 :         if ( rc != SQLITE_OK ){
      43           0 :                 successfulOpen = false;
      44           0 :                 cout << "Problem opening database: "<<sqlite3_errmsg(db) << endl;
      45           0 :                 sqlite3_close( db );
      46             :         }
      47           0 : }
      48             : 
      49           0 : string DatabaseConnector::getCreatedDate(){
      50             :         struct tm* clock;
      51             :         struct stat attrib;
      52           0 :         stat(databasePath.c_str(), &attrib );
      53           0 :         clock = gmtime(&(attrib.st_mtime));
      54           0 :         char* timeStr = asctime( clock );
      55           0 :         string fileDate( timeStr );
      56           0 :         return fileDate;
      57             : }
      58             : 
      59           0 : sqlite3* DatabaseConnector::getDatabase( const string& path){
      60           0 :         if ( connection == NULL ){
      61           0 :                 connection = new DatabaseConnector( path );
      62             :         }
      63           0 :         sqlite3* dbConnection = NULL;
      64           0 :         if ( successfulOpen ){
      65           0 :                 dbConnection =connection->db;
      66             :         }
      67           0 :         return dbConnection;
      68             : }
      69             : 
      70           0 : DatabaseConnector::~DatabaseConnector() {
      71           0 :         if ( db != NULL ){
      72           0 :                 sqlite3_close( db );
      73             :         }
      74           0 : }
      75             : 
      76             : }

Generated by: LCOV version 1.16