Skip to content

Commit

Permalink
Merge branch '3.0/develop' into 3.1/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Feb 1, 2011
2 parents bd29aba + a2de18c commit 4b240a3
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 54 deletions.
35 changes: 20 additions & 15 deletions classes/kohana/database/mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function connect()
// No connection exists
$this->_connection = NULL;

throw new Database_Exception(':error', array(
throw new Database_Exception('[:code] :error', array(
':code' => mysql_errno(),
':error' => mysql_error(),
),
mysql_errno());
));
}

// \xFF is a better delimiter, but the PHP driver uses underscore
Expand All @@ -93,9 +93,10 @@ protected function _select_db($database)
if ( ! mysql_select_db($database, $this->_connection))
{
// Unable to select database
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
throw new Database_Exception('[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
}

Database_MySQL::$_current_databases[$this->_connection_id] = $database;
Expand Down Expand Up @@ -144,9 +145,10 @@ public function set_charset($charset)

if ($status === FALSE)
{
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
throw new Database_Exception('[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
}
}

Expand Down Expand Up @@ -176,9 +178,11 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
Profiler::delete($benchmark);
}

throw new Database_Exception(':error [ :query ]',
array(':error' => mysql_error($this->_connection), ':query' => $sql),
mysql_errno($this->_connection));
throw new Database_Exception('[:code] :error ( :query )', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
':query' => $sql,
));
}

if (isset($benchmark))
Expand Down Expand Up @@ -417,9 +421,10 @@ public function escape($value)

if (($value = mysql_real_escape_string( (string) $value, $this->_connection)) === FALSE)
{
throw new Database_Exception(':error',
array(':error' => mysql_errno($this->_connection)),
mysql_error($this->_connection));
throw new Database_Exception('[:code] :error', array(
':code' => mysql_errno($this->_connection),
':error' => mysql_error($this->_connection),
));
}

// SQL standard is to use single-quotes for all values
Expand Down
20 changes: 9 additions & 11 deletions classes/kohana/database/pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ public function connect()
}
catch (PDOException $e)
{
throw new Database_Exception(':error', array(
':error' => $e->getMessage(),
),
$e->getCode(),
$e);
throw new Database_Exception('[:code] :error', array(
':code' => $e->getMessage(),
':error' => $e->getCode(),
));
}

if ( ! empty($this->_config['charset']))
Expand Down Expand Up @@ -111,12 +110,11 @@ public function query($type, $sql, $as_object = FALSE, array $params = NULL)
}

// Convert the exception in a database exception
throw new Database_Exception(':error [ :query ]', array(
':error' => $e->getMessage(),
':query' => $sql
),
$e->getCode(),
$e);
throw new Database_Exception('[:code] :error ( :query )', array(
':code' => $e->getMessage(),
':error' => $e->getCode(),
':query' => $sql,
));
}

if (isset($benchmark))
Expand Down
32 changes: 13 additions & 19 deletions classes/kohana/database/query/builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,24 @@ protected function _compile_conditions(Database $db, array $conditions)
// BETWEEN always has exactly two arguments
list($min, $max) = $value;

if (is_string($min) AND array_key_exists($min, $this->_parameters))
if ((is_string($min) AND array_key_exists($min, $this->_parameters)) === FALSE)
{
// Set the parameter as the minimum
$min = $this->_parameters[$min];
// Quote the value, it is not a parameter
$min = $db->quote($min);
}

if (is_string($max) AND array_key_exists($max, $this->_parameters))
if ((is_string($max) AND array_key_exists($max, $this->_parameters)) === FALSE)
{
// Set the parameter as the maximum
$max = $this->_parameters[$max];
// Quote the value, it is not a parameter
$max = $db->quote($max);
}

// Quote the min and max value
$value = $db->quote($min).' AND '.$db->quote($max);
$value = $min.' AND '.$max;
}
else
elseif ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
{
if (is_string($value) AND array_key_exists($value, $this->_parameters))
{
// Set the parameter as the value
$value = $this->_parameters[$value];
}

// Quote the entire value normally
// Quote the value, it is not a parameter
$value = $db->quote($value);
}

Expand Down Expand Up @@ -157,13 +151,13 @@ protected function _compile_set(Database $db, array $values)
// Quote the column name
$column = $db->quote_column($column);

if (is_string($value) AND array_key_exists($value, $this->_parameters))
if ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
{
// Use the parameter value
$value = $this->_parameters[$value];
// Quote the value, it is not a parameter
$value = $db->quote($value);
}

$set[$column] = $column.' = '.$db->quote($value);
$set[$column] = $column.' = '.$value;
}

return implode(', ', $set);
Expand Down
6 changes: 5 additions & 1 deletion classes/kohana/database/query/builder/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function compile(Database $db)
$query .= ' LIMIT '.$this->_limit;
}

return $query;
$this->_sql = $query;

return parent::compile($db);
}

public function reset()
Expand All @@ -83,6 +85,8 @@ public function reset()

$this->_parameters = array();

$this->_sql = NULL;

return $this;
}

Expand Down
16 changes: 10 additions & 6 deletions classes/kohana/database/query/builder/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ public function compile(Database $db)
$groups = array();
foreach ($this->_values as $group)
{
foreach ($group as $i => $value)
foreach ($group as $offset => $value)
{
if (is_string($value) AND isset($this->_parameters[$value]))
if ((is_string($value) AND array_key_exists($value, $this->_parameters)) === FALSE)
{
// Use the parameter value
$group[$i] = $this->_parameters[$value];
// Quote the value, it is not a parameter
$group[$offset] = $db->quote($value);
}
}

$groups[] = '('.implode(', ', array_map($quote, $group)).')';
$groups[] = '('.implode(', ', $group).')';
}

// Add the values
Expand All @@ -153,7 +153,9 @@ public function compile(Database $db)
$query .= (string) $this->_values;
}

return $query;
$this->_sql = $query;

return parent::compile($db);;
}

public function reset()
Expand All @@ -165,6 +167,8 @@ public function reset()

$this->_parameters = array();

$this->_sql = NULL;

return $this;
}

Expand Down
6 changes: 5 additions & 1 deletion classes/kohana/database/query/builder/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ public function compile(Database $db)
}
}

return $query;
$this->_sql = $query;

return parent::compile($db);
}

public function reset()
Expand All @@ -434,6 +436,8 @@ public function reset()

$this->_parameters = array();

$this->_sql = NULL;

return $this;
}

Expand Down
6 changes: 5 additions & 1 deletion classes/kohana/database/query/builder/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public function compile(Database $db)
$query .= ' LIMIT '.$this->_limit;
}

return $query;
$this->_sql = $query;

return parent::compile($db);
}

public function reset()
Expand All @@ -123,6 +125,8 @@ public function reset()

$this->_parameters = array();

$this->_sql = NULL;

return $this;
}

Expand Down

0 comments on commit 4b240a3

Please sign in to comment.