Class: Mkxms::Mssql::AdoptionScriptWriter::CheckConstraintAdoptionChecks
- Inherits:
-
IndentedStringBuilder
- Object
- IndentedStringBuilder
- Mkxms::Mssql::AdoptionScriptWriter::CheckConstraintAdoptionChecks
- Includes:
- SqlStringManipulators
- Defined in:
- lib/mkxms/mssql/adoption_script_writer.rb
Constant Summary
Constants included from SqlStringManipulators
Constants inherited from IndentedStringBuilder
IndentedStringBuilder::NAMED_SUBSTITUTIONS
Instance Attribute Summary collapse
-
#cnstr ⇒ Object
readonly
Returns the value of attribute cnstr.
-
#cnstr_id ⇒ Object
readonly
Returns the value of attribute cnstr_id.
-
#schema_name ⇒ Object
readonly
Returns the value of attribute schema_name.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Instance Method Summary collapse
- #add_named_constraint_tests ⇒ Object
- #add_unnamed_constraint_tests ⇒ Object
- #error_sql(s) ⇒ Object
-
#initialize(cnstr, error_sql_proc) ⇒ CheckConstraintAdoptionChecks
constructor
A new instance of CheckConstraintAdoptionChecks.
Methods included from SqlStringManipulators
#bit_test, #boolean_desc, #dedent, #stresc, #strlit, #unquoted_identifier
Methods inherited from IndentedStringBuilder
dsl, #dsl, #each, #indented, #puts, #to_s
Constructor Details
#initialize(cnstr, error_sql_proc) ⇒ CheckConstraintAdoptionChecks
Returns a new instance of CheckConstraintAdoptionChecks.
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1231 def initialize(cnstr, error_sql_proc) super() @cnstr = cnstr @cnstr_id = "check constraint%s on #{cnstr.qualified_table}" % [ cnstr.name ? cnstr.name + " " : "" ] @error_sql_proc = error_sql_proc @schema_name = unquoted_identifier cnstr.schema @table_name = unquoted_identifier cnstr.table @cnstr_name = unquoted_identifier(cnstr.name) if cnstr.name if cnstr.name add_named_constraint_tests else add_unnamed_constraint_tests end end |
Instance Attribute Details
#cnstr ⇒ Object (readonly)
Returns the value of attribute cnstr.
1251 1252 1253 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1251 def cnstr @cnstr end |
#cnstr_id ⇒ Object (readonly)
Returns the value of attribute cnstr_id.
1251 1252 1253 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1251 def cnstr_id @cnstr_id end |
#schema_name ⇒ Object (readonly)
Returns the value of attribute schema_name.
1251 1252 1253 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1251 def schema_name @schema_name end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
1251 1252 1253 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1251 def table_name @table_name end |
Instance Method Details
#add_named_constraint_tests ⇒ Object
1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1257 def add_named_constraint_tests dsl { puts "IF NOT EXISTS (%s)" do puts dedent %Q{ SELECT * FROM sys.check_constraints cc INNER JOIN sys.tables t ON cc.object_id = t.object_id INNER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = #{strlit schema_name} AND t.name = #{strlit table_name} AND cc.name = #{strlit cnstr_name} } end puts "BEGIN" indented { puts error_sql "#{cnstr_id.capitalize} does not exist." } puts "END ELSE IF NOT EXISTS (%s)" do puts dedent %Q{ SELECT * FROM sys.check_constraints cc INNER JOIN sys.tables t ON cc.parent_object_id = t.object_id INNER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = #{strlit schema_name} AND t.name = #{strlit table_name} AND cc.name = #{strlit cnstr_name} AND cc.definition = #{strlit cnstr.definition} } end puts "BEGIN" indented { puts error_sql "#{cnstr_id.capitalize} does not have expected definition." } puts "END" } end |
#add_unnamed_constraint_tests ⇒ Object
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1292 def add_unnamed_constraint_tests dsl { puts "IF NOT EXISTS (%s)" do puts dedent %Q{ SELECT cc.object_id FROM sys.check_constraints cc INNER JOIN sys.tables t ON cc.parent_object_id = t.object_id INNER JOIN sys.schemas s ON t.schema_id = s.schema_id WHERE s.name = #{strlit schema_name} AND t.name = #{strlit table_name} AND cc.definition = #{strlit cnstr.definition} } end puts "BEGIN".."END" do puts error_sql "Expected #{cnstr_id} does not exist." end } end |
#error_sql(s) ⇒ Object
1253 1254 1255 |
# File 'lib/mkxms/mssql/adoption_script_writer.rb', line 1253 def error_sql(s) @error_sql_proc.call(s) end |