From 5f8adabb6286fdcb0ff8a0ea5d1d58f40eef51f4 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 27 Aug 2012 03:28:16 -0400
Subject: [PATCH] Add simple (constructor) tests for Framework classes

---
 program/include/rcube_db_sqlite.php |   39 ++++++++++++++++++++++++---------------
 1 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/program/include/rcube_db_sqlite.php b/program/include/rcube_db_sqlite.php
index fe6b0dc..a9774cd 100644
--- a/program/include/rcube_db_sqlite.php
+++ b/program/include/rcube_db_sqlite.php
@@ -1,6 +1,6 @@
 <?php
 
-/*
+/**
  +-----------------------------------------------------------------------+
  | program/include/rcube_db_sqlite.php                                   |
  |                                                                       |
@@ -26,24 +26,37 @@
  *
  * This is a wrapper for the PHP PDO
  *
- * @package    Database
- * @version    1.0
+ * @package Database
+ * @version 1.0
  */
 class rcube_db_sqlite extends rcube_db
 {
-
+    /**
+     * Database character set
+     */
     protected function set_charset($charset)
     {
     }
 
+    /**
+     * Prepare connection
+     */
     protected function conn_prepare($dsn)
     {
         // Create database file, required by PDO to exist on connection
         if (!empty($dsn['database']) && !file_exists($dsn['database'])) {
-            touch($dsn['database']);
+            $created = touch($dsn['database']);
+
+            // File mode setting, for compat. with MDB2
+            if (!empty($dsn['mode']) && $created) {
+                chmod($dsn['database'], octdec($dsn['mode']));
+            }
         }
     }
 
+    /**
+     * Configure connection, create database if not exists
+     */
     protected function conn_configure($dsn, $dbh)
     {
         // we emulate via callback some missing functions
@@ -55,14 +68,12 @@
             $data = file_get_contents(INSTALL_PATH . 'SQL/sqlite.initial.sql');
 
             if (strlen($data)) {
-                if ($this->options['debug_mode']) {
-                    $this::debug('INITIALIZE DATABASE');
-                }
+                $this->debug('INITIALIZE DATABASE');
 
                 $q = $dbh->exec($data);
 
                 if ($q === false) {
-                    $error = $this->dbh->errorInfo();
+                    $error = $dbh->errorInfo();
                     $this->db_error = true;
                     $this->db_error_msg = sprintf('[%s] %s', $error[1], $error[2]);
 
@@ -73,7 +84,6 @@
             }
         }
     }
-
 
     /**
      * Callback for sqlite: unix_timestamp()
@@ -94,7 +104,6 @@
         return $ret;
     }
 
-
     /**
      * Callback for sqlite: now()
      */
@@ -102,7 +111,6 @@
     {
         return date("Y-m-d H:i:s");
     }
-
 
     /**
      * Returns list of tables in database
@@ -126,11 +134,10 @@
         return $this->tables;
     }
 
-
     /**
      * Returns list of columns in database table
      *
-     * @param string Table name
+     * @param string $table Table name
      *
      * @return array List of table cols
      */
@@ -161,7 +168,9 @@
         return $columns;
     }
 
-
+    /**
+     * Build DSN string for PDO constructor
+     */
     protected function dsn_string($dsn)
     {
         return $dsn['phptype'] . ':' . $dsn['database'];

--
Gitblit v1.9.1