Skip to content

Instantly share code, notes, and snippets.

@akehoyayoi
Created September 17, 2015 00:44
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 akehoyayoi/e0bc942e72001e816027 to your computer and use it in GitHub Desktop.
Save akehoyayoi/e0bc942e72001e816027 to your computer and use it in GitHub Desktop.
convert data from SQLServer to MySQL
def convertLine(line)
line = line.gsub("]","").gsub("[","")
line = line.gsub(" +09:00","")
# 変換候補文字列を抽出
# ex. N'POINT (0 0)' -> GeomFromText('POINT (0 0)')
points = line.scan(/N'POINT \(.+?\)'/)
points.each do |point|
line = line.gsub(point,point.gsub("N'","GeomFromText('").gsub(")'",")')"))
end
line + ";"
end
def convertSQL(path)
File.open(path, 'r:utf-8') do |f|
f.each_line do |line|
puts convertLine(line)
end
end
end
convertSQL(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment