Apologies to my usual readers, but this post is not going to be technical. It’s about a dream I just had, today, Monday the 27th.
In my dream, I was programming a custom SQL query for some WordPress plugin. The query was an INSERT
statement, that simply passed a vector of strings into a table row of VARCHAR
columns. I remember the code vividly, but table/column names were not important so I don’t remember all of them. There was a first name column, and a last name column. It must have looked something like:
global $wpdb; $query = $wpdb->prepare( "INSERT INTO sometable( firstname, lastname, arg1, arg2, arg3, arg4 ) VALUES( %s, %s, %s, %s, %s, %s )" );
I had dev-tested this in my dream and it was working fine. Until I once passed a string with two words, separated by a space character, into one of those arguments. Then I saw some error in the SQL logs. Turns out, in my dream, the SQL server was happy to accept one-word strings, even without surrounding quotes!!! Kind of like the syntax for strings in CSV. (I know, I have the wildest dreams!)
And to make things even weirder, for some reason, the prepare()
function did not add these quotes; I had to supply them myself. Why, prepare function? WHY? You had ONE job!
Oh well, I thought to myself. Easy fix. I will surround the %s
placeholders with double quotes myself. But as I started to do this, the list of %s
became longer and longer. There must have been like 20 or 30 arguments in that list. Not a job to do by hand.
Naturally, all I had to do is use my editor to auto-replace the %s
, with "%s"
. But then, again, complications arose. The placeholders in the prepare statement were not in the usual sprintf
syntax. Instead of %s
, they conveniently were the Unicode characters for cake, muffin, and other assorted confectioneries. How did I not notice this before?
Oh well, I must have been hungry, because it seemed fairly reasonable at the time, that the prepare statement accepted placeholders like cupcakes, pies, bagels and pancakes. So now the VALUES vector looked more like:
VALUES( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )
I didn’t stop for a second to think about how weird this is, or even to check the wpdb
manual again. Instead, I proceeded to wrap these tasty treats with double quotes.
But lo and behold! Another thing not turning out as usual! The IDE editor had trouble with Unicode characters. I would paste in a cupcake character into the search and replace box, and it would turn into an escape-code. In this case it would have been \U1F95E
. (No, I do not remember the exact code from the dream, I had to look it up.)
As is usual with dreams, I did not stop to think why my IDE doesn’t have Unicode support in 2021. Instead, I shrugged it off as another odd thing that just happened, because reasons. I copied the query into another editor, and started replacing the tasty string placeholders, one by one, in that other editor.
That’s when my girlfriend woke me up. It was Monday morning.
She was somewhat upset, because she had to go to work and she was running late. I, on the other hand, was looking forward for work. After all, who doesn’t like cupcakes, pies, bagels and pancakes?
I know she reads my blog, so I just want to wish her, wholeheartedly, a very, very nice and easy day at work. \U2665
And to anyone else reading this, sorry for wasting your time with my nonsense!