Class: RakeDotNet::SqlCmd

Inherits:
Cli
  • Object
show all
Defined in:
lib/rake_dotnet.rb

Instance Attribute Summary collapse

Attributes inherited from Cli

#bin, #search_paths

Instance Method Summary collapse

Methods inherited from Cli

#exe, #search_for_exe

Constructor Details

#initialize(params = {}) ⇒ SqlCmd

Returns a new instance of SqlCmd.



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/rake_dotnet.rb', line 234

def initialize(params={})
	sps = params[:search_paths] || []
	sps << File.join(TOOLS_DIR, 'sql')
	sps << File.join(ENV['PROGRAMFILES'], 'Microsoft SQL Server', '100', 'tools', 'binn')
	sps << File.join(ENV['PROGRAMFILES'], 'Microsoft SQL Server', '90', 'tools', 'binn')
	sps << File.join(ENV['PROGRAMFILES'], 'Microsoft SQL Server', '80', 'tools', 'binn')
	super(params.merge({:exe_name=>'sqlcmd.exe', :search_paths=>sps}))

	unless params[:trusted].nil?
		@trusted = params[:trusted]
	else
		@trusted = true
	end
	unless @trusted
		@user = params[:user] || DB_USER
		@password = params[:password] || DB_PASSWORD
	end
	@server = params[:server] || DB_SERVER

	#optionals and runtime settable
	@input_file = params[:input_file]
	@query = params[:query]
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



232
233
234
# File 'lib/rake_dotnet.rb', line 232

def database
  @database
end

#input_fileObject

Returns the value of attribute input_file.



232
233
234
# File 'lib/rake_dotnet.rb', line 232

def input_file
  @input_file
end

#queryObject

Returns the value of attribute query.



232
233
234
# File 'lib/rake_dotnet.rb', line 232

def query
  @query
end

Instance Method Details

#cmdObject



286
287
288
# File 'lib/rake_dotnet.rb', line 286

def cmd
	return "#{super} #{server} #{credentials} #{database} #{input_file} #{query}"
end

#credentialsObject



258
259
260
261
262
263
264
# File 'lib/rake_dotnet.rb', line 258

def credentials
	if @trusted
		return '-E'
	else
		return "-U \"#{@user}\" -P \"#{@password}\""
	end
end

#revert_optionalsObject



296
297
298
299
# File 'lib/rake_dotnet.rb', line 296

def revert_optionals
	@query = nil
	@input_file = nil
end

#runObject



290
291
292
293
294
# File 'lib/rake_dotnet.rb', line 290

def run
	puts cmd if VERBOSE == true
	sh cmd
	revert_optionals
end

#serverObject



266
267
268
# File 'lib/rake_dotnet.rb', line 266

def server
	return "-S \"#{@server}\""
end