What is best practice for referencing data rows within stored procedures – via PK, code column or data value?

Suppose you have a table for colours with columns:

  • id = automatically incrementing integer, primary key
  • code = short code reference for the colour, unique
  • colour = human-readable name of colour, unique

Example values might be:

  • 1, BL, Blue
  • 2, GR, Green

Now imagine you have a stored procedure that, at some point, needs to reference this table. Let’s say the business logic says to obtain the colour "Green". To achieve this, you could have any of the following three WHERE clauses:

  • WHERE id = 2
  • WHERE code = GR
  • WHERE colour = Green

Now, if the system is designed such that it is agreed that a code value, once created, never changes, then, in my view, that is the best column to reference because:

  • It is an alternate key
  • It is human-readable for people who maintain the code
  • It will not be impacted when the business decides to change the colour value to ‘Sea Green’

However, if a legacy table lacks such code values, what, in your opinion, is best practice? To reference the id column, or the colour column?

If you reference the id column, the code is not readable unless you then also add comments – you shouldn’t have to comment simple things like this. It sucks figuring out what statements like WHERE id not in (1, 7, 17, 24, 56) mean.

I’m not sure how often, in reality, the id value might change – but consider if you run a script during development to insert new colours but then delete those and insert some more. If your stored procedure references the id values from that last set of colours inserted but when you create your new colours in your next environment you skip the step that inserted the colours which ended up deleted, then the id values won’t match in that next environment. Bad practice, but it can happen – a developer develops their script on a dev instance not thinking that the id values will conflict with production (which, for example, may have had additional colours created manually by the business before your colour creation script runs).

If you reference the colour column, you run the risk that if the business does ask to update the description from ‘Green’ to ‘Sea Green’, that your procedure will begin to fail.

I suppose a further solution is to implement the code column when you need it, if it isn’t there already – probably the best solution?

How do I hide the event description within template of The Events Calenar using Ultimate Member shortcode?

OK, so the goal is to hide the event description with Ultimate Member shortcode [um_loggedin].

I tried doing echo do_shortcode but it’s not working…

This is the code I used within wp-content/themes/hello-elementor/tribe-events/single-event.php:

<?php echo do_shortcode('[um_loggedout]'."Sorry, but only loggedin users are allowed to access the details".'[/um_loggedout]');?>

<?php echo do_shortcode('[um_loggedin]'.the_content().'[/um_loggedin]');?>

Using dynamic tags within text

So I created some dynamic tags. After my Gravity Form is submitted it creates a post. The post has the contents of the dynamic tags listed under the body so this is all working fine. The question is, can I insert a dynamic tag within other text? For example, I have a dynamic tag called "author" and "publishing_date". In my body of text, I want to use the sentence "The book was written by {dynamic tag author} in {dynamic tag publishing_date}.

Is Exit (no square brackets) equivalent to Quit[] for refreshing the Kernel from within an Evaluation Notebook?

I prefer to use Exit as it conveniently requires fewer key presses over Quit[]. But before I use it regularly I need to know if there any subtle differences between Quit[] and Exit. The Wolfram documentation pages for Quit and Exit appear to be very similar and even call these two functions synonymous but I just need to be sure.


Dispel a self targeting spell emanating from within an antimagic field

So, a character has an artifact granting the ability to cast Holy Aura. Another character casts Antimagic Field and the two effects overlap, so that the origins of both spells are within both spell effects.

Can someone cast Dispel Magic on the Holy Aura effect since its radius (30ft) exceeds that of the Antimagic Field (10ft)?

The argument raised against being able to dispel it, is that since the effect is active on a creature, then it is the creature that must be targeted, differentiating this case from a Grease spell for example.

How to make goalKeeper move within post but not move towards to the player?

Hello so basically I make a 2d top-down soccer game but I have to trouble with GK AI, I want to GK is followed the ball but not move toward on it

let say (Enemy = GK) enter image description here

enter image description here

so when the player moves to the left or right the enemy will follow to the right or left not The Yaxis but in X-axis with guarding the post or Y=0

my default enemy movement is like this :

if (gameObject.CompareTag("GK"))         {              anim.SetBool("GKRun", false);             gkballInRange = Physics2D.OverlapCircle(transform.position, gkballRange, playerMask);             float distancePlayer = Vector2.Distance(target.position, transform.position);              if (gkballInRange)             {                 if (distancePlayer <= gkballRange)                 {                     //Animation                     anim.SetBool("GKRun", true);                     transform.Translate(0, -speed * Time.deltaTime, 0);                 }             }          } 

in that scrip, when the ball is on the range the GK is moving to the ball just that. maybe anyone can explain to me how to do it?

Where is Gralhund Villa located within Waterdeep?

In Waterdeep: Dragon Heist, a significant portion of one of the chapters takes place in "Gralhund Villa".

There are locations given for several of the noble Houses in the first chapter, but I can’t find anything giving even an approximate location for Gralhund Villa. I’ve marked this question as 5e, but will accept information from any edition.

Where is Gralhund Villa located within Waterdeep?

Trying to run a add_action within a function to run a woocomerce function on a ajax request

I am able to get a ajax request to work properly on a woocommerce checkout form page, now I want to update the price of the checkout in that ajax request. My add_action is in the function that is fired by the ajax request.

This is all done in a custom plugin as well

Here is my code this far, it doesn’t seem like the function request_gift_card ever fires

 function gift_card_redeem(){      if(!empty($  _SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($  _SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {     error_log("test !empty");          add_action( 'woocommerce_before_calculate_totals', 'request_gift_card', 99 );      function request_gift_card($  cart_object){       if( !WC()->session->__isset( "reload_checkout" )) {           /* Gift wrap price */           $  additionalPrice = 5;           error_log($  cart_object);           foreach ( $  cart_object->cart_contents as $  key => $  value ) {               if( isset( $  value["embossing_fee"] ) ) {                   // Turn $  value['data']->price in to $  value['data']->get_price()                   $  orgPrice = floatval( $  value['data']->get_price() );                   $  discPrice = $  orgPrice + $  additionalPrice;                   $  value['data']->set_price($  discPrice);               }           }       }     }      $  result['type'] = "success";     $  result = json_encode($  result);     echo $  result;   }   else {     error_log("test else");       header("Location: ".$  _SERVER["HTTP_REFERER"]);   }    die(); } 

If your target has an enemy within 5ft, can you sneak attack without using a finesse or ranged weapon?

A rogue and fighter are engaged in melee combat with a goblin. The rogue is unarmed. Can the rogue activate Sneak Attack?

The rules for Sneak Attack state:

Beginning at 1st level, you know how to strike subtly and exploit a foe’s distraction. Once per turn, you can deal an extra 1d6 damage to one creature you hit with an attack if you have advantage on the attack roll. The attack must use a finesse or a ranged weapon.

You don’t need advantage on the attack roll if another enemy of the target is within 5 feet of it, that enemy isn’t incapacitated, and you don’t have disadvantage on the attack roll.

The question arises from the difficulty in parsing the bolded sentence. I have heard 2 interpretations:

  1. You can sneak attack if (you have advantage and the attack is made using a finesse or ranged weapon) or (an enemy of the target is within 5ft, etc).
  2. You can sneak attack if ((you have advantage) or (an enemy of the target is within 5ft, etc)) and the attack is made using a finesse or ranged weapon.

The first interpretation hinges on the idea that when the second paragraph says "on the attack roll" it is still talking about the same "attack" as in the first paragraph. The second interpretation hinges on the idea that the first interpretation is bizarre and unnatural – if that was the intent, there are many ways that it could have been worded to be clearer.

Thematically, I am leaning towards the first – not having a finesse or ranged weapon shouldn’t stop the rogue from exploiting a distracted foe.

Considering RAW only (no twitter please), how should this feature be interpreted?