Class: MyObfuscate::SqlServer
- Inherits:
-
Object
- Object
- MyObfuscate::SqlServer
- Defined in:
- lib/my_obfuscate/sql_server.rb
Constant Summary collapse
- INSERT_REGEX =
/^\s*INSERT (?:INTO )?\[dbo\]\.\[(.*?)\] \((.*?)\) VALUES\s*/i
Instance Method Summary collapse
- #make_insert_statement(table_name, column_names, values_strings) ⇒ Object
- #make_valid_value_string(value) ⇒ Object
- #parse_insert_statement(line) ⇒ Object
- #rows_to_be_inserted(line) ⇒ Object
Instance Method Details
#make_insert_statement(table_name, column_names, values_strings) ⇒ Object
29 30 31 |
# File 'lib/my_obfuscate/sql_server.rb', line 29 def make_insert_statement(table_name, column_names, values_strings) "INSERT [dbo].[#{table_name}] ([#{column_names.join("], [")}]) VALUES #{values_strings};" end |
#make_valid_value_string(value) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/my_obfuscate/sql_server.rb', line 19 def make_valid_value_string(value) if value.nil? "NULL" elsif value.match(/^[A-Z]+\(.*?\)$/) value else "N'#{value}'" end end |
#parse_insert_statement(line) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/my_obfuscate/sql_server.rb', line 5 def parse_insert_statement(line) if regex_match = INSERT_REGEX.match(line) { :table_name => regex_match[1].to_sym, :column_names => regex_match[2].split(/\]\s*,\s*\[/).map { |col| col.gsub(/[\[\]]/, "").to_sym } } end end |
#rows_to_be_inserted(line) ⇒ Object
14 15 16 17 |
# File 'lib/my_obfuscate/sql_server.rb', line 14 def rows_to_be_inserted(line) line = line.gsub(INSERT_REGEX, '').gsub(/\s*;?\s*$/, '').gsub(/^\(/, '').gsub(/\)$/, '') context_aware_sql_server_string_split(line) end |