Ticket #545 (closed Feature Request: fixed)

Opened 8 months ago

Last modified 5 months ago

Database Expression Library

Reported by: Ryuuzaki Owned by: Shadowhand
Priority: minor Milestone: 2.2
Component: Libraries:Database Version: SVN HEAD
Keywords: Cc:

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.

Change History

Changed 5 months ago by Shadowhand

  • owner changed from zombor to Shadowhand
  • status changed from new to assigned

Changed 5 months ago by Shadowhand

  • 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.

Note: See TracTickets for help on using tickets.