Class: FlareUp::Command::CreateTable

Inherits:
Base
  • Object
show all
Defined in:
lib/flare_up/command/create_table.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#table_name

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ CreateTable

Returns a new instance of CreateTable.



7
8
9
10
# File 'lib/flare_up/command/create_table.rb', line 7

def initialize(*args)
  @columns = []
  super
end

Instance Attribute Details

#columnsObject

Returns the value of attribute columns.



5
6
7
# File 'lib/flare_up/command/create_table.rb', line 5

def columns
  @columns
end

Instance Method Details

#execute(connection) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/flare_up/command/create_table.rb', line 32

def execute(connection)
  begin
    connection.execute(get_command)
    []
  rescue PG::InternalError => e
    case e.message
      when /Check 'stl_load_errors' system table for details/
        return STLLoadErrorFetcher.fetch_errors(connection)
      when /PG::SyntaxError/
        matches = /syntax error (.+) \(PG::SyntaxError\)/.match(e.message)
        raise SyntaxError, "Syntax error in the CREATE TABLE command: [#{matches[1]}]."
      else
        raise e
    end
  end
end

#get_commandObject



14
15
16
# File 'lib/flare_up/command/create_table.rb', line 14

def get_command
  "CREATE TABLE #{@table_name} #{get_columns} #{@options}"
end