Class: Xlsx2Mysql::MysqlController
- Inherits:
-
Object
- Object
- Xlsx2Mysql::MysqlController
- Defined in:
- lib/xlsx2mysql/mysql_controller.rb
Instance Method Summary collapse
- #acquire_table_fields ⇒ Object
-
#initialize ⇒ MysqlController
constructor
A new instance of MysqlController.
- #insert_one_record(key_values) ⇒ Object
Constructor Details
#initialize ⇒ MysqlController
Returns a new instance of MysqlController.
7 8 9 10 |
# File 'lib/xlsx2mysql/mysql_controller.rb', line 7 def initialize @charset = 'utf8mb4' @port = '3306' end |
Instance Method Details
#acquire_table_fields ⇒ Object
12 13 14 |
# File 'lib/xlsx2mysql/mysql_controller.rb', line 12 def acquire_table_fields describe_table.map {|x| x[0]} end |
#insert_one_record(key_values) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xlsx2mysql/mysql_controller.rb', line 16 def insert_one_record(key_values) connect unless @my raise "MySQL is not connected!" unless @my keys = [] values = [] question_marks = [] key_values.each do |key, value| keys << key question_marks << '?' values << value end keys.map! {|x| '`'+ x + '`'} sql =<<SQL INSERT INTO #{table} (#{keys.join(',')}) VALUES (#{question_marks.join(',')}); SQL @my.prepare(sql).execute(*values) end |