Insert record only if it does not exist in table without unique index

Reference: http://stackoverflow.com/questions/3164505/mysql-insert-record-if-not-exists-in-table/#3164741 Supposing we have a database table named distributor and we wish to insert a record only if there is no existing record with the same name and country code. The table only has a PRIMARY key but no UNIQUE index on (name, country_code) – think “legacy” and “no privileges to modify database” ๐Ÿ˜› …

Regex to match unescaped characters only

Problem: Find key-value pairs separated by : but ignore escaped colons, i.e. \:. Solution: Negative lookbehinds – see Regex Tutorial – Lookaheads and Lookbehinds. “Positive” means “must match”, “Negative” means “must not match”. Over here, we are “looking behind” the backslash to ensure that a colon is not matched. Single match in a string: <?php …

Using COALESCE and logging SQL string in Play Framework 2.x

For future reference…after spending quite some time figuring it out ๐Ÿ˜› package models; import com.avaje.ebean.Model; import com.avaje.ebean.Query; import play.Logger; import play.data.validation.Constraints; import java.util.Date; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity @Table(name = “my_table”) public class MyModel extends Model { @Id public Long id; @Column(name = “name”) public String name; @Constraints.Required @Column(name …