Skip to content

Commit 7940a7c

Browse files
authored
Merge pull request #49 from xp-framework/feature/uuid-support
Add support for util.UUID instances
2 parents 746e91e + b2b0379 commit 7940a7c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/php/rdbms/StatementFormatter.class.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ public function prepare($type, $var) {
128128
$type= 's';
129129
$this->conn->tz && $arg= $this->conn->tz->translate($arg);
130130
$p= $arg->toString($this->dialect->dateFormat);
131+
} else if ($arg instanceof \util\UUID) {
132+
$type= 's';
133+
$p= $arg->hashCode();
131134
} else if ($arg instanceof SQLRenderable) {
132135
$r.= $arg->asSql($this->conn).', ';
133136
continue;

src/test/php/rdbms/unittest/TokenizerTest.class.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use rdbms\{DBConnection, SQLStateException};
44
use unittest\actions\RuntimeVersion;
55
use unittest\{Expect, Test};
6-
use util\Date;
6+
use util\{Date, UUID};
77

88
/**
99
* Test rdbms tokenizer
@@ -165,6 +165,15 @@ public function dateToken() {
165165
);
166166
}
167167

168+
#[Test]
169+
public function uuidToken() {
170+
$t= new UUID('b1e2f772-ae5b-4eba-aca5-174c8d0f4cc1');
171+
$this->assertEquals(
172+
"select * from news where id= 'b1e2f772-ae5b-4eba-aca5-174c8d0f4cc1'",
173+
$this->fixture->prepare('select * from news where id= %s', $t)
174+
);
175+
}
176+
168177
#[Test]
169178
public function timeStampToken() {
170179
$t= (new Date('1977-12-14'))->getTime();

0 commit comments

Comments
 (0)