Skip to content

Commit cc3c6ef

Browse files
committed
InsertUpdateStatement::setMask has not worked. Added corresponding test
1 parent 394d036 commit cc3c6ef

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/Builder/InsertUpdateStatement.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ protected function buildFieldList(array $fields, array $query = array()) {
3535
if($fieldValue instanceof DefaultValue) {
3636
$fieldValue = 'DEFAULT';
3737
}
38+
if(is_array($this->mask) && !in_array($fieldName, $this->mask)) {
39+
continue;
40+
}
3841
if (is_int($fieldName)) {
3942
$query[] = "\t{$fieldValue}";
4043
} else {

tests/Builder/InsertTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,14 @@ public function testAddOrUpdateAll() {
129129
->asString();
130130
$this->assertEquals("INSERT INTO\n\ttravis_test.test1\nSET\n\t`field1`='123'\nON DUPLICATE KEY UPDATE\n\t`field1`='123'\n;\n", $query);
131131
}
132+
133+
public function testMask() {
134+
$sql = TestInsert::create()
135+
->into('test')
136+
->addOrUpdate('field1', 1)
137+
->addOrUpdate('field2', 2)
138+
->setMask(['field1'])
139+
->asString();
140+
$this->assertEquals("INSERT INTO\n\ttest\nSET\n\t`field1`='1'\nON DUPLICATE KEY UPDATE\n\t`field1`='1'\n;\n", $sql);
141+
}
132142
}

tests/Builder/UpdateTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,16 @@ public function testLimit() {
111111
->asString();
112112
$this->assertEquals("UPDATE\n\ttest1\nSET\n\t`field1`='1'\nLIMIT\n\t10\nOFFSET\n\t10\n;\n", $sql);
113113
}
114+
115+
public function testMask() {
116+
$sql = TestUpdate::create()
117+
->table('test1')
118+
->set('field1', 1)
119+
->set('field2', 2)
120+
->setMask(['field1'])
121+
->limit(10)
122+
->asString();
123+
$this->assertEquals("UPDATE\n\ttest1\nSET\n\t`field1`='1'\nLIMIT\n\t10\n;\n", $sql);
124+
}
114125
}
115126

0 commit comments

Comments
 (0)