Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
1771bfc2
Commit
1771bfc2
authored
Sep 09, 2014
by
Robin Appelman
Committed by
Thomas Müller
Sep 16, 2014
Browse files
Introduce cross-db ILIKE
parent
1978d3d6
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/private/db/adaptermysql.php
0 → 100644
View file @
1771bfc2
<?php
/**
* Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
namespace
OC\DB
;
class
AdapterMySQL
extends
Adapter
{
public
function
fixupStatement
(
$statement
)
{
$statement
=
str_replace
(
' ILIKE '
,
' COLLATE utf8_general_ci LIKE '
,
$statement
);
return
$statement
;
}
}
lib/private/db/adapteroci8.php
View file @
1771bfc2
...
...
@@ -11,18 +11,20 @@ namespace OC\DB;
class
AdapterOCI8
extends
Adapter
{
public
function
lastInsertId
(
$table
)
{
if
(
$table
!==
null
)
{
if
(
$table
!==
null
)
{
$suffix
=
'_SEQ'
;
$table
=
'"'
.
$table
.
$suffix
.
'"'
;
$table
=
'"'
.
$table
.
$suffix
.
'"'
;
}
return
$this
->
conn
->
realLastInsertId
(
$table
);
}
const
UNIX_TIMESTAMP_REPLACEMENT
=
"(cast(sys_extract_utc(systimestamp) as date) - date'1970-01-01') * 86400"
;
public
function
fixupStatement
(
$statement
)
{
$statement
=
str_replace
(
'`'
,
'"'
,
$statement
);
$statement
=
str_ireplace
(
'NOW()'
,
'CURRENT_TIMESTAMP'
,
$statement
);
$statement
=
str_ireplace
(
'UNIX_TIMESTAMP()'
,
self
::
UNIX_TIMESTAMP_REPLACEMENT
,
$statement
);
$statement
=
preg_replace
(
'/`(\w+)` ILIKE \?/'
,
'REGEXP_LIKE(`$1`, TRIM(BOTH \'%\' FROM ?), \'i\')'
,
$statement
);
$statement
=
str_replace
(
'`'
,
'"'
,
$statement
);
$statement
=
str_ireplace
(
'NOW()'
,
'CURRENT_TIMESTAMP'
,
$statement
);
$statement
=
str_ireplace
(
'UNIX_TIMESTAMP()'
,
self
::
UNIX_TIMESTAMP_REPLACEMENT
,
$statement
);
return
$statement
;
}
}
lib/private/db/adaptersqlite.php
View file @
1771bfc2
...
...
@@ -11,6 +11,7 @@ namespace OC\DB;
class
AdapterSqlite
extends
Adapter
{
public
function
fixupStatement
(
$statement
)
{
$statement
=
str_replace
(
' ILIKE '
,
' LIKE '
,
$statement
);
$statement
=
str_replace
(
'`'
,
'"'
,
$statement
);
$statement
=
str_ireplace
(
'NOW()'
,
'datetime(\'now\')'
,
$statement
);
$statement
=
str_ireplace
(
'UNIX_TIMESTAMP()'
,
'strftime(\'%s\',\'now\')'
,
$statement
);
...
...
lib/private/db/connectionfactory.php
View file @
1771bfc2
...
...
@@ -26,7 +26,7 @@ class ConnectionFactory {
'wrapperClass'
=>
'OC\DB\Connection'
,
),
'mysql'
=>
array
(
'adapter'
=>
'\OC\DB\Adapter'
,
'adapter'
=>
'\OC\DB\Adapter
MySQL
'
,
'charset'
=>
'UTF8'
,
'driver'
=>
'pdo_mysql'
,
'wrapperClass'
=>
'OC\DB\Connection'
,
...
...
tests/lib/db.php
View file @
1771bfc2
...
...
@@ -263,4 +263,19 @@ class Test_DB extends PHPUnit_Framework_TestCase {
$query
=
OC_DB
::
prepare
(
"UPDATE `*PREFIX*
{
$this
->
table2
}
` SET `uri` = ? WHERE `fullname` = ?"
);
return
$query
->
execute
(
array
(
$uri
,
$fullname
));
}
public
function
testILIKE
()
{
$table
=
"*PREFIX*
{
$this
->
table2
}
"
;
$query
=
OC_DB
::
prepare
(
"INSERT INTO `
$table
` (`fullname`, `uri`, `carddata`) VALUES (?, ?, ?)"
);
$query
->
execute
(
array
(
'fooBAR'
,
'foo'
,
'bar'
));
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `
$table
` WHERE `fullname` LIKE ?"
);
$result
=
$query
->
execute
(
array
(
'foobar'
));
$this
->
assertCount
(
0
,
$result
->
fetchAll
());
$query
=
OC_DB
::
prepare
(
"SELECT * FROM `
$table
` WHERE `fullname` ILIKE ?"
);
$result
=
$query
->
execute
(
array
(
'foobar'
));
$this
->
assertCount
(
1
,
$result
->
fetchAll
());
}
}
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