Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-07-06 10:45:38 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-07-06 11:25:03 +0300
commitd9435d61218f677395f3b53976a41ac5f361f24b (patch)
treedaeffa17eef21005694cea90eb300b359d433b66 /lib/gitlab/sql
parent2520edefb9a7481f575ac7bcdbcf89cb1432f27d (diff)
Backports for ee-2112
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/2112
Diffstat (limited to 'lib/gitlab/sql')
-rw-r--r--lib/gitlab/sql/glob.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/sql/glob.rb b/lib/gitlab/sql/glob.rb
new file mode 100644
index 00000000000..5e89e12b2b1
--- /dev/null
+++ b/lib/gitlab/sql/glob.rb
@@ -0,0 +1,22 @@
+module Gitlab
+ module SQL
+ module Glob
+ extend self
+
+ # Convert a simple glob pattern with wildcard (*) to SQL LIKE pattern
+ # with SQL expression
+ def to_like(pattern)
+ <<~SQL
+ REPLACE(REPLACE(REPLACE(#{pattern},
+ #{q('%')}, #{q('\\%')}),
+ #{q('_')}, #{q('\\_')}),
+ #{q('*')}, #{q('%')})
+ SQL
+ end
+
+ def q(string)
+ ActiveRecord::Base.connection.quote(string)
+ end
+ end
+ end
+end