本文整理汇总了PHP中Cake\Database\Schema\Table::truncateSql方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::truncateSql方法的具体用法?PHP Table::truncateSql怎么用?PHP Table::truncateSql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Database\Schema\Table
的用法示例。
在下文中一共展示了Table::truncateSql方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: truncate
/**
* {@inheritDoc}
*/
public function truncate(ConnectionInterface $db)
{
$sql = $this->_schema->truncateSql($db);
foreach ($sql as $stmt) {
$db->execute($stmt)->closeCursor();
}
return true;
}
示例2: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMockBuilder('Cake\\Database\\Connection')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('TRUNCATE "schema_articles" RESTART IDENTITY CASCADE', $result[0]);
}
示例3: testTruncateSqlNoSequences
/**
* Test truncateSql() with no sequences
*
* @return void
*/
public function testTruncateSqlNoSequences()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$statement = $this->getMock('\\PDOStatement', ['execute', 'rowCount', 'closeCursor', 'fetch']);
$driver->connection()->expects($this->once())->method('prepare')->with('SELECT 1 FROM sqlite_master WHERE name = "sqlite_sequence"')->will($this->returnValue($statement));
$statement->expects($this->once())->method('fetch')->will($this->returnValue(false));
$table = new Table('articles');
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('DELETE FROM "articles"', $result[0]);
}
示例4: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMockBuilder('Cake\\Database\\Connection')->disableOriginalConstructor()->getMock();
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('articles');
$result = $table->truncateSql($connection);
$this->assertCount(1, $result);
$this->assertEquals('TRUNCATE TABLE `articles`', $result[0]);
}
示例5: testTruncateSql
/**
* Test truncateSql()
*
* @return void
*/
public function testTruncateSql()
{
$driver = $this->_getMockedDriver();
$connection = $this->getMock('Cake\\Database\\Connection', [], [], '', false);
$connection->expects($this->any())->method('driver')->will($this->returnValue($driver));
$table = new Table('schema_articles');
$table->addColumn('id', 'integer')->addConstraint('primary', ['type' => 'primary', 'columns' => ['id']]);
$result = $table->truncateSql($connection);
$this->assertCount(2, $result);
$this->assertEquals('DELETE FROM [schema_articles]', $result[0]);
$this->assertEquals('DBCC CHECKIDENT([schema_articles], RESEED, 0)', $result[1]);
}