Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
19269218
Commit
19269218
authored
Jan 24, 2013
by
Guilherme Blanco
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #253 from jankramer/add-sqlite-guid
Added GUID expression to SQLite platform
parents
f444b115
1bba751b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
0 deletions
+59
-0
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+11
-0
DBAL421Test.php
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php
+48
-0
No files found.
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
19269218
...
...
@@ -46,6 +46,17 @@ class SqlitePlatform extends AbstractPlatform
return
'RLIKE'
;
}
/**
* {@inheritDoc}
*/
public
function
getGuidExpression
()
{
return
"HEX(RANDOMBLOB(4)) || '-' || HEX(RANDOMBLOB(2)) || '-4' || "
.
"SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || "
.
"SUBSTR('89AB', 1 + (ABS(RANDOM()) % 4), 1) || "
.
"SUBSTR(HEX(RANDOMBLOB(2)), 2) || '-' || HEX(RANDOMBLOB(6))"
;
}
/**
* {@inheritDoc}
*/
...
...
tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL421Test.php
0 → 100644
View file @
19269218
<?php
namespace
Doctrine\Tests\DBAL\Functional\Ticket
;
/**
* @group DBAL-421
*/
class
DBAL421Test
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
$platform
=
$this
->
_conn
->
getDatabasePlatform
()
->
getName
();
if
(
!
in_array
(
$platform
,
array
(
'mysql'
,
'sqlite'
)))
{
$this
->
markTestSkipped
(
'Currently restricted to MySQL and SQLite.'
);
}
}
public
function
testGuidShouldMatchPattern
()
{
$guid
=
$this
->
_conn
->
query
(
$this
->
getSelectGuidSql
())
->
fetchColumn
();
$pattern
=
'/[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[8-9A-B][0-9A-F]{3}\-[0-9A-F]{12}/i'
;
$this
->
assertEquals
(
1
,
preg_match
(
$pattern
,
$guid
),
"GUID does not match pattern"
);
}
/**
* This test does (of course) not proof that all generated GUIDs are
* random, it should however provide some basic confidence.
*/
public
function
testGuidShouldBeRandom
()
{
$statement
=
$this
->
_conn
->
prepare
(
$this
->
getSelectGuidSql
());
$guids
=
array
();
for
(
$i
=
0
;
$i
<
99
;
$i
++
)
{
$statement
->
execute
();
$guid
=
$statement
->
fetchColumn
();
$this
->
assertNotContains
(
$guid
,
$guids
,
"Duplicate GUID detected"
);
$guids
[]
=
$guid
;
}
}
private
function
getSelectGuidSql
()
{
return
"SELECT "
.
$this
->
_conn
->
getDatabasePlatform
()
->
getGuidExpression
();
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment