Class: KnjDB_mysql::Columns
- Defined in:
- lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb
Defined Under Namespace
Classes: Column
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#driver ⇒ Object
readonly
Returns the value of attribute driver.
Instance Method Summary collapse
- #data_sql(data) ⇒ Object
-
#initialize(args) ⇒ Columns
constructor
A new instance of Columns.
Constructor Details
#initialize(args) ⇒ Columns
Returns a new instance of Columns.
4 5 6 7 8 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb', line 4 def initialize(args) @args = args @db = @args[:db] @driver = @args[:driver] end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
2 3 4 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb', line 2 def db @db end |
#driver ⇒ Object (readonly)
Returns the value of attribute driver.
2 3 4 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb', line 2 def driver @driver end |
Instance Method Details
#data_sql(data) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/knj/knjdb/drivers/mysql/knjdb_mysql_columns.rb', line 10 def data_sql(data) raise "No type given." if !data["type"] data["maxlength"] = 255 if data["type"] == "varchar" and !data.key?("maxlength") sql = "`#{data["name"]}` #{data["type"]}" sql << "(#{data["maxlength"]})" if data["maxlength"] sql << " PRIMARY KEY" if data["primarykey"] sql << " AUTO_INCREMENT" if data["autoincr"] sql << " NOT NULL" if !data["null"] if data.key?("default_func") sql << " DEFAULT #{data["default_func"]}" elsif data.key?("default") and data["default"] != false sql << " DEFAULT '#{@db.escape(data["default"])}'" end sql << " COMMENT '#{@db.escape(data["comment"])}'" if data.key?("comment") sql << " AFTER `#{@db.esc_col(data["after"])}`" if data["after"] and !data["first"] sql << " FIRST" if data["first"] return sql end |