Created
January 28, 2013 16:49
-
-
Save flyingmachine/4657119 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Simple, not robust script for pairing sql fields to values | |
# example usage: pbpaste | ./sql_pairs.rb | |
sql = STDIN.read | |
# sql = %{INSERT INTO "users" ("username", "email") VALUES ('joe schmoe', '[email protected]')} | |
begin | |
fields = /\((.*?)\)/.match(sql)[1].split(",") | |
values = /values \((.*?)\)/i.match(sql)[1].split(",") | |
0.upto(fields.size) do |i| | |
puts "#{fields[i]} => #{values[i]}" | |
end | |
rescue => e | |
puts "Could not find pairs for string: #{sql}" | |
raise e | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment