Class: OracleSqlParser::Util::ParameternizedQuery

Inherits:
Object
  • Object
show all
Defined in:
lib/oracle-sql-parser/util/parameterized_query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original) ⇒ ParameternizedQuery

Returns a new instance of ParameternizedQuery.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/oracle-sql-parser/util/parameterized_query.rb', line 4

def initialize(original)
  @index = 0
  @params = {}
  @ast = original.map_ast do |v|
    case v
    when OracleSqlParser::Ast::NumberLiteral, OracleSqlParser::Ast::TextLiteral
      assign_parameter(v)
    else 
      v
    end
  end
end

Instance Attribute Details

#astObject (readonly)

Returns the value of attribute ast.



3
4
5
# File 'lib/oracle-sql-parser/util/parameterized_query.rb', line 3

def ast
  @ast
end

#paramsObject (readonly)

Returns the value of attribute params.



3
4
5
# File 'lib/oracle-sql-parser/util/parameterized_query.rb', line 3

def params
  @params
end

Instance Method Details

#assign_parameter(value) ⇒ Object



21
22
23
24
25
26
# File 'lib/oracle-sql-parser/util/parameterized_query.rb', line 21

def assign_parameter(value)
  name = "a#{@index}"
  @index += 1
  @params[name] = value
  OracleSqlParser::Ast::Variable[:name =>name] 
end

#to_sqlObject



17
18
19
# File 'lib/oracle-sql-parser/util/parameterized_query.rb', line 17

def to_sql
  ast.to_sql
end