Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
grifart libs
tables
Commits
1dc27c12
Verified
Commit
1dc27c12
authored
2 years ago
by
Jan Kuchař
Committed by
Jiří Pudil
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Draft: Tried to fix CompositeType to use PostgreSQL native syntax of ROW(1,'a',null)::"someType"
parent
66845d06
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!40
CompositeType: add explicit type cast to support composite values in WHERE clause
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Types/CompositeType.php
+24
-28
24 additions, 28 deletions
src/Types/CompositeType.php
tests/Types/CompositeTypeTest.phpt
+3
-3
3 additions, 3 deletions
tests/Types/CompositeTypeTest.phpt
with
27 additions
and
31 deletions
src/Types/CompositeType.php
+
24
−
28
View file @
1dc27c12
...
...
@@ -45,37 +45,33 @@ abstract class CompositeType implements Type
protected
function
tupleToDatabase
(
array
$value
):
Literal
{
\assert
(
\count
(
$value
)
===
\count
(
$this
->
types
));
$dbValue
=
\sprintf
(
'(%s)'
,
\implode
(
','
,
map
(
$value
,
function
(
$item
,
$index
)
{
if
(
$item
===
null
)
{
return
''
;
}
$mappedItem
=
$this
->
types
[
$index
]
->
toDatabase
(
$item
);
if
(
$mappedItem
===
''
)
{
return
'""'
;
}
if
(
\preg_match
(
'/[,\s"()]/'
,
(
string
)
$mappedItem
))
{
return
\sprintf
(
'"%s"'
,
\str_replace
([
'\\'
,
'"'
],
[
'\\\\'
,
'\\"'
],
(
string
)
$mappedItem
),
);
}
return
$mappedItem
;
},
return
new
Literal
(
\sprintf
(
'ROW(%s)::%s'
,
\implode
(
','
,
map
(
$value
,
function
(
$item
,
$index
)
{
if
(
$item
===
null
)
{
return
'null'
;
}
$result
=
$this
->
types
[
$index
]
->
toDatabase
(
$item
);
// @todo: we need connection here to call escape functiom ?!
if
(
is_string
(
$result
))
{
// @todo remove me! This is re-implementation of escaping
// @todo Should be escaped by TestType at a first place, hmm?
// @todo Shouldn't there be Literal as a required return type of toDatabse?
return
"'"
.
str_replace
(
"'"
,
"
\\
'"
,
$result
)
.
"'"
;
}
return
$result
;
},
),
),
$this
->
databaseType
->
toSql
()
)
);
return
new
Literal
(
\sprintf
(
'%s::%s'
,
$dbValue
,
$this
->
databaseType
->
toSql
()));
}
/**
...
...
This diff is collapsed.
Click to expand it.
tests/Types/CompositeTypeTest.phpt
+
3
−
3
View file @
1dc27c12
...
...
@@ -45,8 +45,8 @@ $composite = new class extends CompositeType {
}
};
$dbValue
=
$composite
->
toDatabase
([
42
,
null
,
'com\\ple"x'
,
'('
,
''
,
null
]);
$dbValue
=
$composite
->
toDatabase
([
42
,
null
,
'com\\ple"
\'
x'
,
'('
,
''
,
null
]);
Assert
::
type
(
Literal
::
class
,
$dbValue
);
Assert
::
same
(
'(42,,"
com\\
\\
ple\
\"x","(","",
)::"databaseType"
'
,
(
string
)
$dbValue
);
Assert
::
same
(
"ROW(42,null,'
com
\\
ple
\
"\\
'x','(','',null
)::
\
"
databaseType
\"
"
,
(
string
)
$dbValue
);
Assert
::
same
([
42
,
null
,
'com\\ple"x'
,
'('
,
''
,
null
],
$composite
->
fromDatabase
(
'(42,,"com\\\\ple""x","(","",)'
));
Assert
::
same
([
42
,
null
,
'com\\ple"
\'
x'
,
'('
,
''
,
null
],
$composite
->
fromDatabase
(
'(42,,"com\\\\ple""
\'
x","(","",)'
));
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment