Module: Sqlyzer::Parameter::Types::VarChar

Defined in:
lib/sqlyzer/parameters.rb

Overview

Sql Varchar type Mixin

Instance Method Summary collapse

Instance Method Details

#/(default) ⇒ Object

Overload default parameter assigment for setting VarChar capacity with a Ruby Range object.



92
93
94
95
# File 'lib/sqlyzer/parameters.rb', line 92

def     /(default)
  @capacity = default.max
  super ''
end

#to_sql(owner) ⇒ Object

Ruby String to Sql Varchar serialization like Text, but truncate the String if too long.



97
98
99
100
101
102
103
# File 'lib/sqlyzer/parameters.rb', line 97

def     to_sql(owner)
  if @capacity.nil?
    "E'#{super(owner).to_s.gsub "'", "\\'"}'"
  else
    "E'#{super(owner).to_s[0..@capacity - 1].gsub "'", "\\'"}'"
  end
end

#to_sql_typeObject

Return VARCHAR if no capacity was specified by the user.



87
88
89
90
# File 'lib/sqlyzer/parameters.rb', line 87

def     to_sql_type
  return 'VARCHAR' if @capacity.nil?
  "VARCHAR(#{@capacity})"
end