close Warning: AdminModule failed with TracError: Unable to instantiate component <class 'trac.ticket.admin.MilestoneAdminPanel'> (super(type, obj): obj (type MilestoneAdminPanel) is not an instance or subtype of type (Markup).)

Ignore:
Timestamp:
Aug 26, 2015, 8:14:40 PM (11 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
master
Children:
b38cc03
Parents:
8f38d1e
Message:
  • Finished setup
    • Added tests for setup
    • Added translation to setup
Location:
src/webservice/htdocs/SiWeather/Webservice
Files:
4 added
1 moved

Legend:

Unmodified
Added
Removed
  • src/webservice/htdocs/SiWeather/Webservice/DatabaseHandler.php

    r8f38d1e r8c356c1  
    1919*/
    2020
    21 require_once("config/config.php");
     21namespace SiWeather\Webservice;
    2222
    2323/**
    … …  
    2828        */
    2929class DatabaseHandler {
    30         private $_database;
    31         private $_databaseFile;
    32         private $_lastErrorMessage;
    33 
    3430        function __construct()
    3531        {
     32                $this->_config = new WebserviceConfig();
     33       
    3634                $this->_lastErrorMessage = "";
    3735                $this->_database = null;
    38                 if(!getConfig("dataDirectory")){
     36                if(!$this->_config->dataDirectory()){
    3937                        $this->_lastErrorMessage = "No data directory set!";
    4038                        error_log("Could not connect to the database: "+ $this->lastErrorMessage());
    … …  
    4240                }
    4341                else{
    44                         $this->_databaseFile = getConfig("dataDirectory") ."/siweather.sqlite";
     42                        $this->_databaseFile = $this->_config->dataDirectory() ."/siweather.sqlite";
    4543                }
    4644        }
    … …  
    6664        {
    6765                if(!is_null($this->_database)){
    68                         echo "database is not null";
    6966                        return true;
    7067                }
    … …  
    7572                }
    7673                try {
    77                         $db = new SQLite3($this->_databaseFile);
     74                        $db = new \SQLite3($this->_databaseFile);
    7875                }
    7976                catch(PDOException $exception){
    … …  
    8380                }
    8481                # loading SpatiaLite as an extension
    85                 if(!$db->loadExtension("libspatialite.so.7")){
     82                $extension = $this->_config->getConfig("spatialiteExtension");
     83                if(empty($extension)){
     84                        $this->_lastErrorMessage("No spatialiteExtension set!");
     85                        error_log($this->lastErrorMessage());
     86                        return false;
     87                }
     88                if(!$db->loadExtension($extension)){
    8689                        $this->_lastErrorMessage = "Could not load SpatialLite extension: ". $db->lastErrorMsg();
    8790                        error_log($this->lastErrorMessage());
    … …  
    105108                return false;
    106109        }
     110       
     111        public function exec($query)
     112        {
     113                if(!$this->connect()){
     114                        return false;
     115                }
     116                return $this->_database->exec($query);
     117        }
     118       
     119        public function prepare($query)
     120        {
     121                if(!$this->connect()){
     122                        return false;
     123                }
     124                return $this->_database->prepare($query);
     125        }
     126       
     127        public function versionSpatialite(){
     128                if(is_null($this->_database)){
     129                        $this->_lastErrorMessage("Unknown (No database connection)");
     130                        return 0;
     131                }
     132                if(!$this->connect()){
     133                        return 0;
     134                }
     135                $result = $this->_database->query("SELECT spatialite_version()");
     136                while($row = $result->fetchArray()){
     137                        return $row[0];
     138                }
     139                return 0;
     140        }
     141       
     142        public function versionSqlite(){
     143                if(is_null($this->_database)){
     144                        $this->_lastErrorMessage("Unknown (No database connection)");
     145                        return 0;
     146                }
     147                if(!$this->connect()){
     148                        return 0;
     149                }
     150                $result = $this->_database->query("SELECT sqlite_version()");
     151                while($row = $result->fetchArray()){
     152                        return $row[0];
     153                }
     154                return 0;
     155        }
     156       
     157        private $_database;
     158        private $_databaseFile;
     159        private $_lastErrorMessage;
     160        private $_config;
    107161}
    108162
Note: See TracChangeset for help on using the changeset viewer.