diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index b2ec554..d692890 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -448,7 +448,7 @@ public function set( $args ) { $statement = $key === 'raw' ? [ $arg_value ] : [ - sprintf( '%s', $key ), + sprintf( '`%s`', $key ), '=', is_array( $value ) && array_key_exists( 'raw', $value ) ? $value['raw'] @@ -493,7 +493,7 @@ public function values( $args ) { $arg_value = $this->sanitize_value( $sanitize_callback, $arg_value ); } - $preparedKey = sprintf( '%s', $key ); + $preparedKey = sprintf( '`%s`', $key ); if ( is_array( $value ) && array_key_exists( 'raw', $value ) ) { $this->builder['values'][ $preparedKey ] = $value['raw']; diff --git a/tests/cases/QueryBuilderOperationsTest.php b/tests/cases/QueryBuilderOperationsTest.php index d65c226..2af1382 100644 --- a/tests/cases/QueryBuilderOperationsTest.php +++ b/tests/cases/QueryBuilderOperationsTest.php @@ -302,7 +302,7 @@ public function testUpdate() $this->assertIsBool( $var ); $this->assertTrue( $var ); $this->assertEquals( - 'UPDATE prefix_up SET a = %s', + 'UPDATE prefix_up SET `a` = %s', $wpdb->get_query() ); } diff --git a/tests/cases/QueryBuilderStatementsTest.php b/tests/cases/QueryBuilderStatementsTest.php index 13892cc..21d5511 100644 --- a/tests/cases/QueryBuilderStatementsTest.php +++ b/tests/cases/QueryBuilderStatementsTest.php @@ -1006,7 +1006,7 @@ public function testUpdateSetTypes() ->update(); // Assert $this->assertEquals( - 'UPDATE prefix_set1 SET a = %s,b = %d,c = null,d = \'7,8\'', + 'UPDATE prefix_set1 SET `a` = %s,`b` = %d,`c` = null,`d` = \'7,8\'', $wpdb->get_query() ); } @@ -1034,7 +1034,7 @@ public function testUpdateSetRaw() ->update(); // Assert $this->assertEquals( - 'UPDATE prefix_set2 SET c = 1,b = c+1', + 'UPDATE prefix_set2 SET c = 1,`b` = c+1', $wpdb->get_query() ); } @@ -1062,7 +1062,7 @@ public function testUpdateSetForceString() ->update(); // Assert $this->assertEquals( - 'UPDATE prefix_set2 SET a = %s', + 'UPDATE prefix_set2 SET `a` = %s', $wpdb->get_query() ); } @@ -1098,7 +1098,7 @@ public function testUpdateJoinWhere() ->update(); // Assert $this->assertEquals( - 'UPDATE prefix_u1,prefix_u2 JOIN prefix_u2 ON u1.id = u2.id SET u1.title = u2.title,u1.parent = %s WHERE u1.status = %s', + 'UPDATE prefix_u1,prefix_u2 JOIN prefix_u2 ON u1.id = u2.id SET u1.title = u2.title,`u1.parent` = %s WHERE u1.status = %s', $wpdb->get_query() ); } diff --git a/tests/cases/TraitModelTest.php b/tests/cases/TraitModelTest.php index 57171d0..5d11179 100644 --- a/tests/cases/TraitModelTest.php +++ b/tests/cases/TraitModelTest.php @@ -130,7 +130,7 @@ public function testUpdate() $this->assertIsBool( $flag ); $this->assertTrue( $flag ); $this->assertEquals( - 'UPDATE prefix_' . Model::TABLE . ' SET status = %s', + 'UPDATE prefix_' . Model::TABLE . ' SET `status` = %s', $wpdb->get_query() ); } @@ -149,7 +149,7 @@ public function testUpdateWhere() $flag = Model::update_all( ['status' => 'active'], ['type' => 'yolo'] ); // Assert $this->assertEquals( - 'UPDATE prefix_' . Model::TABLE . ' SET status = %s WHERE type = %s', + 'UPDATE prefix_' . Model::TABLE . ' SET `status` = %s WHERE type = %s', $wpdb->get_query() ); }