Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
47b3bbcc
Commit
47b3bbcc
authored
10 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
orm: mysql: Fix placement of parameters in compiled query
parent
37df16e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.orm.php
+22
-31
22 additions, 31 deletions
include/class.orm.php
with
22 additions
and
31 deletions
include/class.orm.php
+
22
−
31
View file @
47b3bbcc
...
...
@@ -1770,12 +1770,6 @@ class DbEngine {
class
MySqlCompiler
extends
SqlCompiler
{
// Consts for ::input()
const
SLOT_JOINS
=
1
;
const
SLOT_WHERE
=
2
;
protected
$input_join_count
=
0
;
static
$operators
=
array
(
'exact'
=>
'%1$s = %2$s'
,
'contains'
=>
array
(
'self'
,
'__contains'
),
...
...
@@ -1867,7 +1861,7 @@ class MySqlCompiler extends SqlCompiler {
if
(
$local
[
0
]
==
"'"
)
{
$constraints
[]
=
sprintf
(
"%s.%s = %s"
,
$alias
,
$this
->
quote
(
$right
),
$this
->
input
(
trim
(
$local
,
'\'"'
)
,
self
::
SLOT_JOINS
)
$this
->
input
(
trim
(
$local
,
'\'"'
))
);
}
// Support local constraint
...
...
@@ -1875,7 +1869,7 @@ class MySqlCompiler extends SqlCompiler {
elseif
(
$foreign
[
0
]
==
"'"
&&
!
$right
)
{
$constraints
[]
=
sprintf
(
"%s.%s = %s"
,
$table
,
$this
->
quote
(
$local
),
$this
->
input
(
trim
(
$foreign
,
'\'"'
)
,
self
::
SLOT_JOINS
)
$this
->
input
(
trim
(
$foreign
,
'\'"'
))
);
}
else
{
...
...
@@ -1887,7 +1881,7 @@ class MySqlCompiler extends SqlCompiler {
}
// Support extra join constraints
if
(
$extra
instanceof
Q
)
{
$constraints
[]
=
$this
->
compileQ
(
$extra
,
$model
,
self
::
SLOT_JOINS
);
$constraints
[]
=
$this
->
compileQ
(
$extra
,
$model
);
}
if
(
!
isset
(
$rmodel
))
$rmodel
=
$model
;
...
...
@@ -1911,11 +1905,6 @@ class MySqlCompiler extends SqlCompiler {
* Parameters:
* $what - (mixed) value to be sent to the database. No escaping is
* necessary. Pass a raw value here.
* $slot - (int) clause location of the input in compiled SQL statement.
* Currently, SLOT_JOINS and SLOT_WHERE is supported. SLOT_JOINS
* inputs are inserted ahead of the SLOT_WHERE inputs as the joins
* come logically before the where claused in the finalized
* statement.
*
* Returns:
* (string) token to be placed into the compiled SQL statement. For
...
...
@@ -1934,16 +1923,8 @@ class MySqlCompiler extends SqlCompiler {
return
'NULL'
;
}
else
{
switch
(
$slot
)
{
case
self
::
SLOT_JOINS
:
// This should be inserted before the WHERE inputs
array_splice
(
$this
->
params
,
$this
->
input_join_count
++
,
0
,
array
(
$what
));
break
;
default
:
$this
->
params
[]
=
$what
;
}
return
'?'
;
$this
->
params
[]
=
$what
;
return
':'
.
(
count
(
$this
->
params
));
}
}
...
...
@@ -2251,7 +2232,7 @@ class MySqlCompiler extends SqlCompiler {
}
}
class
My
s
qlExecutor
{
class
My
S
qlExecutor
{
var
$stmt
;
var
$fields
=
array
();
...
...
@@ -2272,17 +2253,28 @@ class MysqlExecutor {
return
$this
->
map
;
}
function
fixupParams
()
{
$self
=
$this
;
$params
=
array
();
$sql
=
preg_replace_callback
(
'/:(\d+)/'
,
function
(
$m
)
use
(
$self
,
&
$params
)
{
$params
[]
=
$self
->
params
[
$m
[
1
]
-
1
];
return
'?'
;
},
$this
->
sql
);
return
array
(
$sql
,
$params
);
}
function
_prepare
()
{
$this
->
execute
();
$this
->
_setup_output
();
}
function
execute
()
{
if
(
!
(
$this
->
stmt
=
db_prepare
(
$this
->
sql
)))
list
(
$sql
,
$params
)
=
$this
->
fixupParams
();
if
(
!
(
$this
->
stmt
=
db_prepare
(
$sql
)))
throw
new
InconsistentModelException
(
'Unable to prepare query: '
.
db_error
()
.
' '
.
$this
->
sql
);
if
(
count
(
$
this
->
params
))
$this
->
_bind
(
$
this
->
params
);
if
(
count
(
$params
))
$this
->
_bind
(
$params
);
if
(
!
$this
->
stmt
->
execute
()
||
!
$this
->
stmt
->
store_result
())
{
throw
new
OrmException
(
'Unable to execute query: '
.
$this
->
stmt
->
error
);
}
...
...
@@ -2393,9 +2385,8 @@ class MysqlExecutor {
function
__toString
()
{
$self
=
$this
;
$x
=
0
;
return
preg_replace_callback
(
'/\?/'
,
function
(
$m
)
use
(
$self
,
&
$x
)
{
$p
=
$self
->
params
[
$x
++
];
return
preg_replace_callback
(
'/:(\d+)/'
,
function
(
$m
)
use
(
$self
)
{
$p
=
$self
->
params
[
$m
[
1
]
-
1
];
return
db_real_escape
(
$p
,
is_string
(
$p
));
},
$this
->
sql
);
}
...
...
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