From 9e99d14ab446b661345945f59ef3500336d44e33 Mon Sep 17 00:00:00 2001 From: rainbowsoft Date: Thu, 5 Dec 2024 16:11:50 +0800 Subject: [PATCH] =?UTF-8?q?SQL=5F=5FGlobal=E7=B1=BB=E7=94=9F=E6=88=90trunc?= =?UTF-8?q?ate=E8=AF=AD=E5=8F=A5=E6=97=B6=E5=81=9A=E4=BA=86=E8=B0=83?= =?UTF-8?q?=E6=95=B4;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/phpunit/ClassSQL__MySQLTest.php | 5 +++++ tests/phpunit/ClassSQL__PostgreSQLTest.php | 5 +++++ tests/phpunit/ClassSQL__SQLiteTest.php | 5 +++++ zb_system/function/lib/sql/global.php | 7 ++++++- 4 files changed, 21 insertions(+), 1 deletion(-) 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(); }