Sha256: cfe30b5e0eb7fefedbbea3859f10c87c621f229b50b1287c96bc1aab3854b0fc

Contents?: true

Size: 1.32 KB

Versions: 30

Compression:

Stored size: 1.32 KB

Contents

module Myreplicator
  class VerticaSql
  
    def self.create_table_stmt options
      sql = "CREATE TABLE IF NOT EXISTS #{options[:vertica_db]}."
      sql += "#{options[:vertica_schema]}." if options[:vertica_schema]
      sql += "#{options[:table]} ("

      index = 1
      primary_set = false

      options[:columns].each do |column|
        sql += "\"#{column['column_name']}\" "

        sql += data_type(column['data_type'], column['column_type'])
        sql += " "

        if column['column_key'] == "PRI"
          sql += key(column['column_key']) + " " unless primary_set # set only one primary key
          primary_set = true
        end

        sql += nullable(column['is_nullable'])
        sql += " "

        if index < options[:columns].size
          sql += ", "
        else
          sql += ");"
        end
        index += 1
      end
 
      puts sql
    
      return sql
    end
  
    def self.nullable is_nullable
      if is_nullable == "YES"
        return "NULL"
      elsif is_nullable == "NO"
        return "NOT NULL"
      end
      return ""
    end
 
    def self.data_type type, col_type
      type = VerticaTypes.convert type, col_type
      result = " #{type} "
      return result
    end

    def self.key col_key
      col_key = VerticaTypes.convert_key col_key
      return  "#{col_key} "
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
myreplicator-1.1.31 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.30 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.29 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.28 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.27 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.26 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.25 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.24 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.23 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.22 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.21 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.20 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.19 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.18 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.17 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.16 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.15 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.13 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.12 lib/loader/vertica/vertica_sql.rb
myreplicator-1.1.11 lib/loader/vertica/vertica_sql.rb