Browse Source

Merge pull request #4894 from cakephp/minor-optimizations

Minor optimizations
José Lorenzo Rodríguez 11 years ago
parent
commit
1bd6571b52
2 changed files with 13 additions and 8 deletions
  1. 12 7
      src/Database/SqlDialectTrait.php
  2. 1 1
      src/Datasource/EntityTrait.php

+ 12 - 7
src/Database/SqlDialectTrait.php

@@ -35,10 +35,16 @@ trait SqlDialectTrait {
 			return '*';
 		}
 
-		if (preg_match('/^[\w-]+(?:\.[^ \*]*)*$/', $identifier)) { // string, string.string
-			if (strpos($identifier, '.') === false) { // string
-				return $this->_startQuote . $identifier . $this->_endQuote;
-			}
+		if ($identifier === '') {
+			return '';
+		}
+
+		// string
+		if (preg_match('/^[\w-]+$/', $identifier)) {
+			return $this->_startQuote . $identifier . $this->_endQuote;
+		}
+
+		if (preg_match('/^[\w-]+\.[^ \*]*$/', $identifier)) { // string.string
 			$items = explode('.', $identifier);
 			return $this->_startQuote . implode($this->_endQuote . '.' . $this->_startQuote, $items) . $this->_endQuote;
 		}
@@ -51,10 +57,9 @@ trait SqlDialectTrait {
 			return $matches[1] . '(' . $this->quoteIdentifier($matches[2]) . ')';
 		}
 
+		// Alias.field AS thing
 		if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+AS\s*([\w-]+)$/i', $identifier, $matches)) {
-			return preg_replace(
-				'/\s{2,}/', ' ', $this->quoteIdentifier($matches[1]) . ' AS  ' . $this->quoteIdentifier($matches[3])
-			);
+			return $this->quoteIdentifier($matches[1]) . ' AS ' . $this->quoteIdentifier($matches[3]);
 		}
 
 		if (preg_match('/^[\w-_\s]*[\w-_]+/', $identifier)) {

+ 1 - 1
src/Datasource/EntityTrait.php

@@ -543,7 +543,7 @@ trait EntityTrait {
 			return isset($this->_dirty[$property]);
 		}
 
-		if (!$isDirty) {
+		if ($isDirty === false) {
 			unset($this->_dirty[$property]);
 			return false;
 		}