Bug Report #545

Database Expression Library

Added by Ryuuzaki - almost 4 years ago. Updated almost 3 years ago.

Status:Closed Start date:
Priority:Normal Due date:
Assignee:Woody Gilk % Done:

0%

Category:Libraries:Database
Target version:2.3.2
Resolution:fixed Points:

Description

By using the following class, database expressions, arithmetic and functions will be possible without modifying any core files.

// librarires/Database_Expr.php
<?php
class Database_Expr
{
    private $_value = NULL;

    public function +construct($value)
    {
        $this->_value = $value;
    }

    public function +toString()
    {
        return $this->_value;
    }
}

for example, the following code:

Database::instance()->update('anime',
  array(
    'episodes' => new Database_Expr('episodes + 1')
  ),
  array('id' => 1)
);

will produce the following SQL:

UPDATE @anime@ SET @episodes@ = episodes + 1 WHERE @id@ = 1

inserting like:

Database::instance()->insert('anime', array(
  'date' => new Database_Expr('NOW()')
));

works as well.

History

Updated by Woody Gilk over 3 years ago

  • Status changed from New to Assigned

Updated by Woody Gilk over 3 years ago

  • Status changed from Assigned to Closed
  • Resolution set to fixed

This has been added in r2964, which is part of the #204 rebuild of database.

Updated by John Heathco almost 3 years ago

  • Status changed from Closed to Feedback
  • Resolution deleted (fixed)

Updated by John Heathco almost 3 years ago

  • Status changed from Feedback to Closed
  • Resolution set to fixed

Added in r4039 and merged to 2.4 in r4040

Also available in: Atom PDF