Module: OrientDB::SQL::UtilsMixin

Included in:
BundledFunctionExtension, ConditionalExtension, Delete, FieldOperatorExtension, Insert, Query, Query, Update
Defined in:
lib/orientdb/sql/common.rb

Instance Method Summary collapse

Instance Method Details

#field_name(name) ⇒ Object



9
10
11
# File 'lib/orientdb/sql/common.rb', line 9

def field_name(name)
  name.to_s.split('__').join('.')
end

#quote(value) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/orientdb/sql/common.rb', line 13

def quote(value)
  case value
    when Numeric, Symbol
      value.to_s
    when String
      quote_string(value)
    when Array
      "[" + value.map { |x| quote(x) }.join(", ") + "]"
    when Regexp
      quote_regexp(value)
    when OrientDB::SQL::LiteralExpression
      value.to_s
    else
      quote value.to_s
  end
end

#quote_regexp(regexp) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/orientdb/sql/common.rb', line 41

def quote_regexp(regexp)
  regexp      = regexp.inspect
  left_index  = regexp.index('/') + 1
  right_index = regexp.rindex('/') - 1
  str         = regexp[left_index..right_index]
  "'#{str}'"
end

#quote_string(str) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/orientdb/sql/common.rb', line 30

def quote_string(str)
  str = str.dup
  return str if str[0, 1] == "'" && str[-1, 1] == "'"
  last_pos = 0
  while (pos = str.index("'", last_pos))
    str.insert(pos, "\\") if pos > 0 && str[pos - 1, 1] != "\\"
    last_pos = pos + 1
  end
  "'#{str}'"
end

#select_single_string(arg) ⇒ Object



5
6
7
# File 'lib/orientdb/sql/common.rb', line 5

def select_single_string(arg)
  arg.to_s.split('___').join(' AS ').split('__').join('.')
end