]> source.dussan.org Git - nextcloud-server.git/commitdiff
Merge branch 'master' into doctrine
authorBart Visscher <bartv@thisnet.nl>
Thu, 25 Apr 2013 16:16:09 +0000 (18:16 +0200)
committerBart Visscher <bartv@thisnet.nl>
Thu, 25 Apr 2013 16:16:09 +0000 (18:16 +0200)
Conflicts:
3rdparty
lib/MDB2/Driver/sqlite3.php
lib/db.php

1  2 
3rdparty
lib/base.php
lib/db.php
lib/setup.php

diff --cc 3rdparty
index 93f76b4392b9e6b60fe0d052793741f348cb2536,a13af72fbe8983686fc47489a750e60319f68ac2..40be157ee23753c02481c02e1b60ae699202bf78
+++ b/3rdparty
@@@ -1,1 -1,1 +1,1 @@@
- Subproject commit 93f76b4392b9e6b60fe0d052793741f348cb2536
 -Subproject commit a13af72fbe8983686fc47489a750e60319f68ac2
++Subproject commit 40be157ee23753c02481c02e1b60ae699202bf78
diff --cc lib/base.php
Simple merge
diff --cc lib/db.php
index 3aff9cc68ae6930ab5ca981710ea1936577ea17b,8f6f50bda6e3c51738586b55e4f6512d48a164c2..7db7711b37689896fae70ee976b89812b21c694b
@@@ -229,16 -367,25 +229,18 @@@ class OC_DB 
  
                // Optimize the query
                $query = self::processQuery( $query );
+               if(OC_Config::getValue( "log_query", false)) {
+                       OC_Log::write('core', 'DB prepare : '.$query, OC_Log::DEBUG);
+               }
                self::connect();
                // return the result
 -              if(self::$backend==self::BACKEND_MDB2) {
 -                      $result = self::$connection->prepare( $query );
 -
 -                      // Die if we have an error (error means: bad query, not 0 results!)
 -                      if( PEAR::isError($result)) {
 -                              throw new DatabaseException($result->getMessage(), $query);
 -                      }
 -              }else{
 -                      try{
 +              if (self::$backend == self::BACKEND_DOCTRINE) {
 +                      try {
                                $result=self::$connection->prepare($query);
 -                      }catch(PDOException $e) {
 -                              throw new DatabaseException($e->getMessage(), $query);
 +                      } catch(\Doctrine\DBAL\DBALException $e) {
 +                              throw new \DatabaseException($e->getMessage(), $query);
                        }
 -                      $result=new PDOStatementWrapper($result);
 +                      $result=new DoctrineStatementWrapper($result);
                }
                if ((is_null($limit) || $limit == -1) and self::$cachingEnabled ) {
                        $type = OC_Config::getValue( "dbtype", "sqlite" );
                        $query = substr($query, 0, strlen($query) - 5);
                        try {
                                $stmt = self::prepare($query);
-                               $result = $stmt->execute();
+                               $result = $stmt->execute($inserts);
 -
 -                      } catch(PDOException $e) {
 +                      } catch(\Doctrine\DBAL\DBALException $e) {
                                $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
                                $entry .= 'Offending command was: ' . $query . '<br />';
                                OC_Log::write('core', $entry, OC_Log::FATAL);
                                error_log('DB error: '.$entry);
                                OC_Template::printErrorPage( $entry );
 +                              return false;
                        }
  
-                       if($result->numRows() == 0) {
-                               $query = 'INSERT INTO "' . $table . '" ("'
-                                       . implode('","', array_keys($input)) . '") VALUES("'
-                                       . implode('","', array_values($input)) . '")';
+                       if((int)$result->numRows() === 0) {
+                               $query = 'INSERT INTO `' . $table . '` (`'
+                                       . implode('`,`', array_keys($input)) . '`) VALUES('
+                                       . str_repeat('?,', count($input)-1).'? ' . ')';
                        } else {
                                return true;
                        }
                        }
                        $query = substr($query, 0, strlen($query) - 5);
                        $query .= ' HAVING COUNT(*) = 0';
+                       $inserts = array_merge($inserts, $inserts);
                }
  
-               // TODO: oci should be use " (quote) instead of ` (backtick).
-               //OC_Log::write('core', __METHOD__ . ', type: ' . $type . ', query: ' . $query, OC_Log::DEBUG);
                try {
                        $result = self::prepare($query);
 -              } catch(PDOException $e) {
 +              } catch(\Doctrine\DBAL\DBALException $e) {
                        $entry = 'DB Error: "'.$e->getMessage() . '"<br />';
                        $entry .= 'Offending command was: ' . $query.'<br />';
                        OC_Log::write('core', $entry, OC_Log::FATAL);
                        error_log('DB error: ' . $entry);
                        OC_Template::printErrorPage( $entry );
 +                      return false;
                }
  
-               return $result->execute();
+               return $result->execute($inserts);
        }
  
        /**
@@@ -654,27 -950,6 +656,27 @@@ class DoctrineStatementWrapper 
                $this->statement=$statement;
        }
  
-                       $query = OC_DB::prepare("SELECT COUNT(*) FROM {$output[1]}", PDO::FETCH_NUM);
 +      /**
 +       * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
 +       */
 +      public function __call($name,$arguments) {
 +              return call_user_func_array(array($this->statement,$name), $arguments);
 +      }
 +
 +      /**
 +       * provide numRows
 +       */
 +      public function numRows() {
 +              $regex = '/^SELECT\s+(?:ALL\s+|DISTINCT\s+)?(?:.*?)\s+FROM\s+(.*)$/i';
 +              $queryString = $this->statement->getWrappedStatement()->queryString;
 +              if (preg_match($regex, $queryString, $output) > 0) {
++                      $query = OC_DB::prepare("SELECT COUNT(*) FROM {$output[1]}");
 +                      return $query->execute($this->lastArguments)->fetchColumn();
 +              }else{
 +                      return $this->statement->rowCount();
 +              }
 +      }
 +
        /**
         * make execute return the result instead of a bool
         */
diff --cc lib/setup.php
Simple merge