|I have been trying for a while to write a quine query in SQL. For the geeks who care what I'm talking about but don't know what a quine is, read about it here.|
Anyway, quines are usually written by assigning part of the code to a string variable and writing it more than once in the program's output: once for the actual code and once for the literal assigning the string variable.
Now, there are probably ways to cheat and write an easy quine in SQL Server that uses some internal command to display the contents of a view or stored procedure.
And I know that a quine could be written as a stored procedure, since stored procedures can assign local variables and execute complex logic.
However, I wanted to write the quine using a single SELECT query. Recently, I stumbled upon a quine written in Perl which uses string matching and replacement to create a single-expression quine. I was inspired, and I realized that this form of quine could be adapted into any SQL language with a string-replacement function.
Anyway, here's what I came up with:
SELECT REPLACE(REPLACE('SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine',CHAR(34),CHAR(39)),CHAR(36),'SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine') AS Quine
When executing this against any SQL Server database, the following rowset is returned:
|SELECT REPLACE(REPLACE('SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine',CHAR(34),CHAR(39)),CHAR(36),'SELECT REPLACE(REPLACE("$",CHAR(34),CHAR(39)),CHAR(36),"$") AS Quine') AS Quine|
Try it for yourself if you have a copy of SQL Server or MSDE running somewhere. It shouldn't be hard to port this to PL/SQL (Oracle), but it's getting late.
Now to get to work on a non-trivial regular expression that only matches itself. Wow, is that even possible!? I know that you could use
"trivial" to match the string trivial, but what about more complicated expressions? I don't think it is possible, but can it be proven? Maybe just a regex that matches itself and other strings. Once again, it would have to be less trivial than something like
".*" (which would of course match ANY string). On second thought, that's a pretty stupid idea. Forget I mentioned it.
Beware the Muuj
Comments on this post are closed.
|I think they're trying to write a bbcode quine!|
|I think they're trying to get their URLs banned.|
Should I just ban "http://%.info/%"?
|.biz too. and .li. Nothing good ever came out of Liechtenstein.|
|I think the .info, .biz, and .cc just might be the second, lower tier of the Internet we've all been hearing about...|
|Maybe I'll just block any attempts to use bbcode URL tags.|