Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.

Issue #129 (MySqlStreamer fails on warning with mysql version 5.6.10) #130

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions lib/etl/control/source/mysql_streamer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'open3'
require 'tempfile'

# Internal: The MySQL streamer is a helper with works with the database_source
# in order to allow you to use the --quick option (which stops MySQL)
Expand Down Expand Up @@ -42,15 +43,7 @@ def mandatory_option!(hash, key)

def each
keys = nil

config = ETL::Base.configurations[@name.to_s]
host = mandatory_option!(config, 'host')
username = mandatory_option!(config, 'username')
database = mandatory_option!(config, 'database')
password = config['password'] # this one can omitted in some cases

mysql_command = """mysql --quick -h #{host} -u #{username} -e \"#{@query.gsub("\n","")}\" -D #{database} --password=#{password} -B"""
Open3.popen3(mysql_command) do |stdin, out, err, external|
run_mysql(:quick, :batch) do |stdin, out, err, external|
until (line = out.gets).nil? do
line = line.gsub("\n","")
if keys.nil?
Expand All @@ -70,4 +63,25 @@ def each
end
end
end
end

private

def run_mysql(*args)
config = ETL::Base.configurations[@name.to_s]
options = args.extract_options!.merge(
'host' => mandatory_option!(config, 'host'),
'user' => mandatory_option!(config, 'username'),
'database' => mandatory_option!(config, 'database'),
'password' => config['password'],
'execute' => "\"#{@query}\"")

Tempfile.open('mysqlstreamer') do |option_file|
option_file.puts '[client]'
args.each {|keyword| option_file.puts keyword}
options.each {|key, value| option_file.puts "#{key}=#{value}"}
option_file.flush

yield Open3.popen3("mysql --defaults-extra-file=#{option_file.path}")
end
end
end