diff --git a/tests/phpunit/ClassSQL__MySQLTest.php b/tests/phpunit/ClassSQL__MySQLTest.php index e8f4ba8b2..ab9e43601 100644 --- a/tests/phpunit/ClassSQL__MySQLTest.php +++ b/tests/phpunit/ClassSQL__MySQLTest.php @@ -16,6 +16,11 @@ public function tearDown(): void self::$db = null; } + public function testTruncate(): void + { + $this->assertEquals('TRUNCATE TABLE zbp_post ', self::$db->truncate("zbp_post")->sql); + } + public function testExist(): void { self::$db->exist('zbp_post', 'zbphp'); diff --git a/tests/phpunit/ClassSQL__PostgreSQLTest.php b/tests/phpunit/ClassSQL__PostgreSQLTest.php index 4798c7373..47c182f0c 100644 --- a/tests/phpunit/ClassSQL__PostgreSQLTest.php +++ b/tests/phpunit/ClassSQL__PostgreSQLTest.php @@ -22,6 +22,11 @@ public function testExist() $this->assertEquals('SELECT COUNT(*) FROM information_schema.tables WHERE table_schema=\'public\' AND table_name =\'zbp_post\'', self::$db->sql); } + public function testTruncate(): void + { + $this->assertEquals('TRUNCATE TABLE zbp_post ', self::$db->truncate("zbp_post")->sql); + } + public function testIndex() { self::$db->create('zbp_post')->index(array('indexname' => array('ddd', 'eee', 'eeee'))); diff --git a/tests/phpunit/ClassSQL__SQLiteTest.php b/tests/phpunit/ClassSQL__SQLiteTest.php index 4e1e3e33b..91ffa8e19 100644 --- a/tests/phpunit/ClassSQL__SQLiteTest.php +++ b/tests/phpunit/ClassSQL__SQLiteTest.php @@ -22,6 +22,11 @@ public function testExist() $this->assertEquals('SELECT COUNT(*) FROM sqlite_master WHERE type=\'table\' AND name=\'zbp_post\'', self::$db->sql); } + public function testTruncate(): void + { + $this->assertEquals('DELETE FROM zbp_post ', self::$db->truncate("zbp_post")->sql); + } + public function testIndex() { self::$db->create('zbp_post')->index(array('indexname' => array('ddd', 'eee', 'eeee'))); diff --git a/zb_system/function/lib/sql/global.php b/zb_system/function/lib/sql/global.php index 577a572ed..1609ecaf8 100644 --- a/zb_system/function/lib/sql/global.php +++ b/zb_system/function/lib/sql/global.php @@ -1285,7 +1285,12 @@ protected function buildInsert() protected function buildTRUNCATE() { $sql = &$this->pri_sql; - $sql[] = 'TABLE'; + if (get_class($this) == 'SQL__SQLite') { + $sql = array('DELETE'); + $sql[] = 'FROM'; + } else { + $sql[] = 'TABLE'; + } $this->buildTable(); }