Yii Framework Forum: Support for MySQL INSERT DELAYED - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Support for MySQL INSERT DELAYED Rate Topic: -----

#1 User is offline   pavlepredic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 30-August 11

Posted 28 May 2012 - 07:49 AM

I realize that INSERT DELAYED is a MySQL-specific SQL extension, but it would still be nice for Yii to support it. Overriding CDbCommandBuilder::createInsertCommand() is currently very complicated as it requires overriding a bunch of other classes. All you need to do is add an optional parameter that, when set to true, would result in creation of INSERT DELAYED statement:

-public function createInsertCommand($table,$data)
+public function createInsertCommand($table,$data,$delayed=false)
{
	$this->ensureTable($table);
	$fields=array();
	$values=array();
	$placeholders=array();
	$i=0;
	foreach($data as $name=>$value)
	{
		if(($column=$table->getColumn($name))!==null && ($value!==null || $column->allowNull))
		{
			$fields[]=$column->rawName;
			if($value instanceof CDbExpression)
			{
				$placeholders[]=$value->expression;
				foreach($value->params as $n=>$v)
					$values[$n]=$v;
			}
			else
			{
				$placeholders[]=self::PARAM_PREFIX.$i;
				$values[self::PARAM_PREFIX.$i]=$column->typecast($value);
				$i++;
			}
		}
	}
	if($fields===array())
	{
		$pks=is_array($table->primaryKey) ? $table->primaryKey : array($table->primaryKey);
		foreach($pks as $pk)
		{
			$fields[]=$table->getColumn($pk)->rawName;
			$placeholders[]='NULL';
		}
	}
+	$delayed = ($delayed and $this->getDbConnection()->getDriverName() == 'mysql') ? 'DELAYED' : '';
-	$sql="INSERT INTO {$table->rawName} (".implode(', ',$fields).') VALUES ('.implode(', ',$placeholders).')';
+	$sql="INSERT $delayed INTO {$table->rawName} (".implode(', ',$fields).') VALUES ('.implode(', ',$placeholders).')';
	$command=$this->getDbConnection()->createCommand($sql);

	foreach($values as $name=>$value)
		$command->bindValue($name,$value);

	return $command;
}

0

#2 User is offline   cornernote 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-November 10

Posted 22 October 2012 - 06:27 AM

INSERT DELAYED works only with MyISAM, MEMORY, ARCHIVE, and BLACKHOLE tables. For engines that do not support DELAYED, an error occurs.

http://dev.mysql.com...rt-delayed.html
0

#3 User is offline   pavlepredic 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 39
  • Joined: 30-August 11

Posted 23 October 2012 - 05:47 AM

It is also deprecated, which I was not aware of at the time of writing this, so please ignore this request.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users