Archives

The List

Haxe: “Invalid Class name” during compilation

By Carsten | December 4, 2008

Did you use the right case? All Haxe class names must start with an uppercase letter. (this is documentet deep within this page)

Topics: Haxe | No Comments »

MySQL Pop Quiz #29

By Carsten | September 25, 2008

Yet another quiz inspired by Freenode#mysql IRC discussions. If you haven’t been around on the channel lately, you should have a peek. Lots of interesting discussions going on!

mysql> SELECT c1, c2 FROM t WHERE c2 LIKE 'a%';
+------+------+
| c1   | c2   |
+------+------+
| a    | abc  |
+------+------+

Is the following construct for the LIKE clause legal?

SELECT c1, c2 FROM t WHERE c2 LIKE CONCAT('a', '%');

And how about this one?

SELECT c1, c2 FROM t WHERE c2 LIKE CONCAT(c1, '%');

Bonus question: Suppose the table has many rows, several more columns and there’s an index on (c2, c1). Could that index be utilized when running the legal versions of the query — and if so, how?

Read the rest of this entry »

Topics: MySQL, Pop Quiz | No Comments »

MySQL Pop Quiz #28

By Carsten | September 24, 2008

Don’t forget to send in your suggestions for new quizzes!

This quiz originated on FreeNode#mysql, where someone asked how to count the number of newline-separated “fields” in a TEXT column. For the purposes of the quiz, I’ve changed the idea slightly but you should be able to appreciate the usefulness of this method for any x-separated data that you have to deal with.

Given the following data…

mysql> SELECT * FROM t;
+-----------+
| s         |
+-----------+
| aba       |
| abacad    |
| abacadaea |
+-----------+

…create a query which counts the number of occurrences of the character ‘a’ in each line, e.g.

mysql> SELECT s, <something> AS count_a
    -> FROM t;
+-----------+---------+
| s         | count_a |
+-----------+---------+
| aba       |       2 |
| abacad    |       3 |
| abacadaea |       5 |
+-----------+---------+

Read the rest of this entry »

Topics: MySQL, Pop Quiz | 3 Comments »

“My turn to play MySQL”

By Carsten | August 28, 2008

[Update: A couple of people have told me they really like "your game". I am not the creator of this game; I merely point to it. To my knowledge, I don't know any of the people involved in creating it.]

“The ATTACK query is an undocumented feature of the development branch of MySQL…”

With the popularity of MySQL I guess it was just a question of time before someone came up with a game not just based on MySQL, but also with the theme of MySQL. In the words of the website…

Read the rest of this entry »

Topics: MySQL, Pop Quiz | 3 Comments »

PHP array_merge is Slow

By Carsten | April 30, 2008

…or I’m doing something stupid, in which case I hope someone would enlighten me.

We grab a number of data from two different MySQL servers, get them back as arrays ($ar1 and $ar2) and then we concatenate the two arrays. $ar1 consists of 30 to 200 elements, sometimes more. $ar2 typically contains 30 elements.

The PHP way of doing this is:

$ar1 = array_merge($ar1, $ar2);

and the home-grown version is

foreach($ar2 as $i) {
 $ar1[] = $i;
}

While I do realize that “the PHP way” involves creating a new copy of $ar1 along the way, my assumption before testing this was that, being an internal function with no further parsing or interpretation to be done, it would be much faster.

Doing some microtime() estimations while keeping $ar2 constant at 30 elements, I found:

Read the rest of this entry »

Topics: MySQL, php | 8 Comments »

MySQL Pop Quiz #27

By Carsten | April 29, 2008

I’m still looking for new entries. I get quite a few suggestions, but not all of them make it into quiz questions. Do send in your suggestions!

This wonderful quiz from Vladimir Kolesnikov is one of those that should make you stop and think for a moment…

Given this table and data:

mysql> SELECT * FROM t;
+------+------+
| i1   | i2   |
+------+------+
|    1 |    2 |
|    2 |    1 |
|    4 |    3 |
|    3 |    4 |
+------+------+
4 rows in set (0.00 sec)

What is the result of the following three statements?

SELECT * FROM t ORDER BY 1
SELECT * FROM t ORDER BY 2
SELECT * FROM t ORDER BY 1+1

Read the rest of this entry »

Topics: MySQL, Pop Quiz | 3 Comments »

DATABASE() :: MySQL Function of the Day

By Carsten | April 29, 2008

Function name: DATABASE()
Aliases: -
Function type: Information function
Purpose: Return the name of the current database

Read the rest of this entry »

Topics: MySQL Function of the day | No Comments »

MySQL Function of the Day: Week Seven

By Carsten | April 28, 2008

The weekly run-down of MFotD

(See this post for background information on MySQL Function of the Day)

Week Seven:

Read the rest of this entry »

Topics: MySQL, MySQL Function of the day | No Comments »

ENCODE() :: MySQL Function of the Day

By Carsten | April 28, 2008

Function name: ENCODE
Aliases: -
Function type: Encryption function
Purpose: Encrypt a string using a password

Read the rest of this entry »

Topics: MySQL Function of the day | No Comments »

MySQL Pop Quiz #26

By Carsten | April 24, 2008

I’m still looking for new entries. I get quite a few suggestions, but not all of them make it into quiz questions. Do send in your suggestions!

Today’s quiz question, which subsequently became three, comes courtesy of Janek Bogucki.

Since questions 2 and 3 contain hints on the other questions, they are embedded within the answers to previous questions.

Question 1: What happens if you throw the following statement at your MySQL server?

CREATE TABLE log(
name CHAR(20) NOT NULL,
count INT UNSIGNED NOT NULL
)

Read the rest of this entry »

Topics: MySQL, Pop Quiz | 2 Comments »

« Previous Entries Next Entries »