Created
June 15, 2014 11:20
-
-
Save kaisou4537/37b9cb0ce28aabec08fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 今回は使わない | |
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