Class: SQLCmd
- Inherits:
-
Object
- Object
- SQLCmd
- Includes:
- Albacore::RunCommand, Albacore::Task
- Defined in:
- lib/albacore/sqlcmd.rb
Instance Attribute Summary collapse
-
#batch_abort ⇒ Object
Returns the value of attribute batch_abort.
-
#database ⇒ Object
Returns the value of attribute database.
-
#password ⇒ Object
Returns the value of attribute password.
-
#server ⇒ Object
Returns the value of attribute server.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#trusted_connection ⇒ Object
Returns the value of attribute trusted_connection.
-
#username ⇒ Object
Returns the value of attribute username.
Attributes included from Albacore::RunCommand
Attributes included from Logging
Instance Method Summary collapse
- #build_parameter(param_name, param_value) ⇒ Object
- #build_script_list ⇒ Object
- #build_variable_list ⇒ Object
- #check_command ⇒ Object
- #execute ⇒ Object
- #get_authentication_params ⇒ Object
- #get_batch_abort_param ⇒ Object
-
#initialize ⇒ SQLCmd
constructor
A new instance of SQLCmd.
Methods included from Albacore::RunCommand
Methods included from AttrMethods
Methods included from Albacore::Task
clean_dirname, create_rake_task, include_config, included
Methods included from UpdateAttributes
Methods included from YAMLConfig
#configure, #load_config_by_task_name
Methods included from Logging
#create_logger, #log_device=, #log_level, #log_level=
Methods included from Failure
Constructor Details
#initialize ⇒ SQLCmd
Returns a new instance of SQLCmd.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/albacore/sqlcmd.rb', line 11 def initialize @require_valid_command = false @scripts=[] @variables={} @trusted_connection = true @batch_abort = true @severity = nil super() update_attributes Albacore.configuration.sqlcmd.to_hash end |
Instance Attribute Details
#batch_abort ⇒ Object
Returns the value of attribute batch_abort.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def batch_abort @batch_abort end |
#database ⇒ Object
Returns the value of attribute database.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def database @database end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def password @password end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def server @server end |
#severity ⇒ Object
Returns the value of attribute severity.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def severity @severity end |
#trusted_connection ⇒ Object
Returns the value of attribute trusted_connection.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def trusted_connection @trusted_connection end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/albacore/sqlcmd.rb', line 7 def username @username end |
Instance Method Details
#build_parameter(param_name, param_value) ⇒ Object
70 71 72 |
# File 'lib/albacore/sqlcmd.rb', line 70 def build_parameter(param_name, param_value) "-#{param_name} \"#{param_value}\"" end |
#build_script_list ⇒ Object
66 67 68 |
# File 'lib/albacore/sqlcmd.rb', line 66 def build_script_list @scripts.map{|s| "-i \"#{s.strip}\""}.join(" ") end |
#build_variable_list ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/albacore/sqlcmd.rb', line 74 def build_variable_list vars = [] @variables.each do |k,v| vars << "-v #{k}=#{v}" end vars.join(" ") end |
#check_command ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/albacore/sqlcmd.rb', line 53 def check_command sql2012cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','110','tools','binn', 'sqlcmd.exe') sql2008cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','100','tools','binn', 'sqlcmd.exe') sql2005cmdPath = File.join(ENV['SystemDrive'],'program files','microsoft sql server','90','tools','binn', 'sqlcmd.exe') sql2012cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','110','tools','binn', 'sqlcmd.exe') sql2008cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','100','tools','binn', 'sqlcmd.exe') sql2005cmdPathx86 = File.join(ENV['SystemDrive'],'program files (x86)','microsoft sql server','90','tools','binn', 'sqlcmd.exe') @command = [sql2012cmdPath, sql2008cmdPath, sql2005cmdPath, sql2012cmdPathx86, sql2008cmdPathx86, sql2005cmdPathx86].select { |p| File.exist?(p) }.first return true if @command != nil 'SQLCmd.command cannot be nil.' return false end |
#execute ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/albacore/sqlcmd.rb', line 22 def execute return unless check_command cmd_params=[] serverParam = @server.nil? ? build_parameter("S", ".") : build_parameter("S", @server) cmd_params << serverParam cmd_params << build_parameter("d", @database) unless @database.nil? cmd_params << get_authentication_params cmd_params << build_variable_list if @variables.length > 0 cmd_params << get_batch_abort_param cmd_params << build_script_list if @scripts.length > 0 cmd_params << build_parameter("V", @severity) unless @severity.nil? result = run_command "SQLCmd", cmd_params.join(" ") failure_msg = 'SQLCmd Failed. See Build Log For Detail.' failure_msg if !result end |
#get_authentication_params ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/albacore/sqlcmd.rb', line 45 def get_authentication_params integratedParam = "-E" if @trusted_connection if ((!(@username.nil?)) and (!(@password.nil?))) integratedParam = build_parameter("U", @username) + " " + build_parameter("P", @password) end integratedParam end |
#get_batch_abort_param ⇒ Object
41 42 43 |
# File 'lib/albacore/sqlcmd.rb', line 41 def get_batch_abort_param "-b" if (@scripts.length > 1 && @batch_abort) end |