Class: PLSQL::Table::TableProcedure

Inherits:
Object
  • Object
show all
Defined in:
lib/plsql/table.rb

Overview

wrapper class to simulate Procedure class for ProcedureClass#exec

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, table, operation) ⇒ TableProcedure

Returns a new instance of TableProcedure.



257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/plsql/table.rb', line 257

def initialize(schema, table, operation)
  @schema = schema
  @table = table
  @operation = operation

  @return = [nil]
  @out_list = [[]]

  case @operation
  when :insert
    @argument_list = [[]]
    @arguments = [{}]
    @insert_columns = []
    @insert_values = []
  when :update
    @argument_list = [[]]
    @arguments = [{}]
    @set_sqls = []
    @set_values = []
    @where_sqls = []
    @where_values = []
  end
end

Instance Attribute Details

#argument_listObject (readonly)

:nodoc:



255
256
257
# File 'lib/plsql/table.rb', line 255

def argument_list
  @argument_list
end

#argumentsObject (readonly)

:nodoc:



255
256
257
# File 'lib/plsql/table.rb', line 255

def arguments
  @arguments
end

#out_listObject (readonly)

:nodoc:



255
256
257
# File 'lib/plsql/table.rb', line 255

def out_list
  @out_list
end

#returnObject (readonly)

:nodoc:



255
256
257
# File 'lib/plsql/table.rb', line 255

def return
  @return
end

#schemaObject (readonly)

:nodoc:



255
256
257
# File 'lib/plsql/table.rb', line 255

def schema
  @schema
end

Instance Method Details

#add_insert_arguments(params) ⇒ Object



289
290
291
292
293
294
295
296
# File 'lib/plsql/table.rb', line 289

def add_insert_arguments(params)
  params.each do |k,v|
    raise ArgumentError, "Invalid column name #{k.inspect} specified as argument" unless ( = @table.columns[k])
    @argument_list[0] << k
    @arguments[0][k] = 
    @insert_values << v
  end
end

#add_set_arguments(params) ⇒ Object



298
299
300
301
302
303
304
305
306
# File 'lib/plsql/table.rb', line 298

def add_set_arguments(params)
  params.each do |k,v|
    raise ArgumentError, "Invalid column name #{k.inspect} specified as argument" unless ( = @table.columns[k])
    @argument_list[0] << k
    @arguments[0][k] = 
    @set_sqls << "#{k}=:#{k}"
    @set_values << v
  end
end

#add_where_arguments(params) ⇒ Object



308
309
310
311
312
313
314
315
316
317
318
319
320
321
# File 'lib/plsql/table.rb', line 308

def add_where_arguments(params)
  case params
  when Hash
    params.each do |k,v|
      raise ArgumentError, "Invalid column name #{k.inspect} specified as argument" unless ( = @table.columns[k])
      @argument_list[0] << :"w_#{k}"
      @arguments[0][:"w_#{k}"] = 
      @where_sqls << "#{k}=:w_#{k}"
      @where_values << v
    end
  when String
    @where_sqls << params
  end
end

#argument_valuesObject



323
324
325
326
327
328
329
330
# File 'lib/plsql/table.rb', line 323

def argument_values
  case @operation
  when :insert
    @insert_values
  when :update
    @set_values + @where_values
  end
end

#call_sql(params_string) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
# File 'lib/plsql/table.rb', line 332

def call_sql(params_string)
  case @operation
  when :insert
    "INSERT INTO \"#{@table.schema_name}\".\"#{@table.table_name}\"(#{@argument_list[0].map{|a| a.to_s}.join(', ')}) VALUES (#{params_string});\n"
  when :update
    update_sql = "UPDATE \"#{@table.schema_name}\".\"#{@table.table_name}\" SET #{@set_sqls.join(', ')}"
    update_sql << " WHERE #{@where_sqls.join(' AND ')}" unless @where_sqls.empty?
    update_sql << ";\n"
    update_sql
  end
end

#overloaded?Boolean

Returns:

  • (Boolean)


281
282
283
# File 'lib/plsql/table.rb', line 281

def overloaded?
  false
end

#procedureObject



285
286
287
# File 'lib/plsql/table.rb', line 285

def procedure
  nil
end