Results for “when”
Small, practical examples. Search by task or narrow things down below.
Append text only when the destination has enough capacity
C: Check the combined lengths including the terminator before using strcat.
C✓ Tested
Apply a default when an insert omits a column
SQL: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.
SQL✓ Tested
Apply a default when an insert omits a column
SQL Server: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.
SQL Server✓ Tested
Apply a default when an insert omits a column
Postgres: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.
Postgres✓ Tested
Apply a default when an insert omits a column
SQLite: A default supplies an omitted value; an explicit NULL still follows the column’s nullability rules.
SQLite✓ Tested
Apply an enhancement only when a feature is supported
CSS: A supports rule preserves the baseline outside browsers that understand the selected declaration.
CSS✓ Tested
Attach configuration when registering a handler
jQuery: event.data carries the registration-time data object.
jQuery✓ Tested
Clean up a subscription when a child unmounts
Clean up a subscription when a child unmounts with a small React component and explicit browser behavior.
React✓ Tested
Count a result even when it is empty or has one item
PowerShell: Wrap pipeline results in an array subexpression for consistent Count behavior.
PowerShell✓ Tested
Create a file only when it does not exist
C#: FileMode.CreateNew prevents accidental replacement of existing content.
C#✓ Tested
Initialize a map entry only when absent
Java: Use computeIfAbsent when creating a collection for a new key.
Java✓ Tested
Insert a map value only when a key is absent
C++: try_emplace preserves the old value when insertion does not take place.
C++✓ Tested