Currently, if I change the title of my Droplet from 'My Blog' to 'My blog' it will produce an error, "The title must be unique."

I propose that the matching be case-sensitive.

(see attached)

CommentFileSizeAuthor
mysite_7.patch2.13 KBms2011

Comments

agentrickard’s picture

Two questions:

-- Is this error produced because the title is matching itself, or do you have two Droplets already ('My blog' and 'My Blog')?

I suspect that the error, in fact, is that we need to exclude the current MID from the query:

     $sql = "SELECT mid FROM {mysite_data} WHERE lower(title) = '%s' AND uid = %s";
     $check = db_fetch_object(db_query($sql, trim(strtolower($form_values['title'])), $form_values['uid']));

Should probably be:

     $sql = "SELECT mid FROM {mysite_data} WHERE lower(title) = '%s' AND uid = %d AND mid = %d";
     $check = db_fetch_object(db_query($sql, trim(strtolower($form_values['title'])), $form_values['uid'], $form_values['mid']));

I notice also that uid calls %s instead of %d here, so that's an error as well.

-- Is this sql statement standard across PgSQL and MySQL?

$sql = "SELECT mid FROM {mysite_data} WHERE title = BINARY '%s' AND uid = %s";

I've never seen the BINARY flag before.

BTW: I appreciate these reviews. Welcome aboard.

ms2011’s picture

The error produced because the title is matching itself; there was only one droplet. To reproduce, create a droplet and then try renaming it by changing case only.

The BINARY operator casts the string following it to a binary string; it is the only way to get case-sensitive string matching done in MySQL that I know of. Not familiar enough with PostgreSQL to know whether it would work there or not.

agentrickard’s picture

Status: Needs review » Fixed

I wasn't able to track down any reference to the BINARY syntax in pgSQL. It may be that you have to CAST the data explicitly.

For now I'm going to ignore the case-sensitive part here and just go with the real bug.

     $sql = "SELECT mid FROM {mysite_data} WHERE lower(title) = '%s' AND uid = %d AND mid != %d";
     $check = db_fetch_object(db_query($sql, trim(strtolower($form_values['title'])), $form_values['uid'], $form_values['mid']));

If you find a pgSQL safe version, please post it.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.