Skip to content

Instantly share code, notes, and snippets.

@kaisou4537
Created June 15, 2014 11:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaisou4537/37b9cb0ce28aabec08fb to your computer and use it in GitHub Desktop.
Save kaisou4537/37b9cb0ce28aabec08fb to your computer and use it in GitHub Desktop.
# 今回は使わない
columns = []
# データ格納
datas = []
first = true
File::open('sample.txt','r') do |f|
while line = f.gets
strs = line.strip.split("\t")
data = []
strs.each do |str|
if first then
columns << str
else
data << str
end
if !first then
datas << data
end
end
first = false
end
end
puts columns
puts datas
query = "Insert into T_hoge Values\n"
first = true
datas.each do |data|
add_query = ""
if first then
add_query = "("
first = false
else
add_query = ",("
end
query_first = true
data.each do |str|
if query_first then
add_query += "'#{str.strip}'"
query_first = false
else
add_query += ",'#{str.strip}'"
end
end
add_query += ")"
query += add_query + "\n"
end
puts query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment