Class: RakeDotNet::BcpCmd

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 = {}) ⇒ BcpCmd

Returns a new instance of BcpCmd.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rake_dotnet.rb', line 139

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=>'bcp.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

	@database = params[:database] unless params[:database].nil?
	@schema = params[:schema] || 'dbo'
	@table = params[:table] unless params[:table].nil?
	@direction = params[:direction] unless params[:direction].nil?
	@file = params[:file] unless params[:file].nil?
end

Instance Attribute Details

#databaseObject

Returns the value of attribute database.



137
138
139
# File 'lib/rake_dotnet.rb', line 137

def database
  @database
end

#directionObject

Returns the value of attribute direction.



137
138
139
# File 'lib/rake_dotnet.rb', line 137

def direction
  @direction
end

#field_terminatorObject

Returns the value of attribute field_terminator.



136
137
138
# File 'lib/rake_dotnet.rb', line 136

def field_terminator
  @field_terminator
end

#fileObject

Returns the value of attribute file.



137
138
139
# File 'lib/rake_dotnet.rb', line 137

def file
  @file
end

#keep_identity_valuesObject

Returns the value of attribute keep_identity_values.



136
137
138
# File 'lib/rake_dotnet.rb', line 136

def keep_identity_values
  @keep_identity_values
end

#keep_null_valuesObject

Returns the value of attribute keep_null_values.



136
137
138
# File 'lib/rake_dotnet.rb', line 136

def keep_null_values
  @keep_null_values
end

#native_typeObject

Returns the value of attribute native_type.



136
137
138
# File 'lib/rake_dotnet.rb', line 136

def native_type
  @native_type
end

#schemaObject

Returns the value of attribute schema.



137
138
139
# File 'lib/rake_dotnet.rb', line 137

def schema
  @schema
end

#tableObject

Returns the value of attribute table.



137
138
139
# File 'lib/rake_dotnet.rb', line 137

def table
  @table
end

#wide_character_typeObject

Returns the value of attribute wide_character_type.



136
137
138
# File 'lib/rake_dotnet.rb', line 136

def wide_character_type
  @wide_character_type
end

Instance Method Details

#cmdObject



210
211
212
# File 'lib/rake_dotnet.rb', line 210

def cmd
	return "#{super} #{db_object} #{direction} #{path} #{server} #{credentials} #{keep_identity_values} #{keep_null_values} #{wide_character_type} #{field_terminator} #{native_type}"
end

#credentialsObject



166
167
168
169
170
171
172
# File 'lib/rake_dotnet.rb', line 166

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

#db_objectObject



182
183
184
# File 'lib/rake_dotnet.rb', line 182

def db_object
	return "[#{@database}].[#{@schema}].[#{@table}]"
end

#pathObject



186
187
188
# File 'lib/rake_dotnet.rb', line 186

def path
	return '"' + File.expand_path(@file).gsub('/', '\\') + '"'
end

#revert_optionalsObject



214
215
216
217
218
219
220
221
# File 'lib/rake_dotnet.rb', line 214

def revert_optionals
	@keep_identity_values = nil
	@keep_null_values = nil
	@wide_character_type = nil
	@field_terminator = nil
	@native_type = nil
	@direction = nil
end

#runObject



223
224
225
226
227
# File 'lib/rake_dotnet.rb', line 223

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

#serverObject



174
175
176
# File 'lib/rake_dotnet.rb', line 174

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