From: Bart Visscher Date: Thu, 25 Apr 2013 16:16:09 +0000 (+0200) Subject: Merge branch 'master' into doctrine X-Git-Tag: v6.0.0alpha2~444^2~29 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc9792910ae5d714daefd0840d702550b91bae41;p=nextcloud-server.git Merge branch 'master' into doctrine Conflicts: 3rdparty lib/MDB2/Driver/sqlite3.php lib/db.php --- bc9792910ae5d714daefd0840d702550b91bae41 diff --cc 3rdparty index 93f76b4392b,a13af72fbe8..40be157ee23 --- a/3rdparty +++ b/3rdparty @@@ -1,1 -1,1 +1,1 @@@ - Subproject commit 93f76b4392b9e6b60fe0d052793741f348cb2536 -Subproject commit a13af72fbe8983686fc47489a750e60319f68ac2 ++Subproject commit 40be157ee23753c02481c02e1b60ae699202bf78 diff --cc lib/db.php index 3aff9cc68ae,8f6f50bda6e..7db7711b376 --- a/lib/db.php +++ b/lib/db.php @@@ -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" ); @@@ -393,20 -647,20 +396,20 @@@ $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() . '"
'; $entry .= 'Offending command was: ' . $query . '
'; 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; } @@@ -420,23 -675,20 +424,21 @@@ } $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() . '"
'; $entry .= 'Offending command was: ' . $query.'
'; 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; } + /** + * 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]}", PDO::FETCH_NUM); ++ $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 */