2 messages in com.mysql.lists.gui-toolsPatch: Make inline editing work with ...
FromSent OnAttachments
Adam Hooper18 Apr 2002 20:22 
Adam Hooper19 Apr 2002 03:48 
Subject:Patch: Make inline editing work with NULL, strings with apostrophes
From:Adam Hooper (ada@densi.com)
Date:04/18/2002 08:22:51 PM
List:com.mysql.lists.gui-tools

Hello!

This is a lot of firsts: My first time hacking MyCC, my first time using bk...
even my first time using C++! So please correct me if I do something weird in my
patch (though it seems okay to me).

I only edited one file, CSqlTable.cpp, and I only changed around 10 lines, so I
couldn't have done THAT much wrong ;). I ran "bk diffs" in the src directory for
the output shown below, hope that's how I'm supposed to do it...

Anyway, the patch! Pretty self-explanitory:

1. Makes sure you don't input queries like "UPDATE `table` SET `value` = 'blah'
WHERE `value` = 'NULL' (which won't work). Makes it "IS NULL" instead.

2. Escapes quotation marks, so "WHERE `value` = 'foo'bar'" becomes "WHERE
`value` = 'foo''bar'"

3. Adds a "LIMIT 1" to the end of the allFields query -- if the table has no
primary key, it's possible that many rows have the exact same contents. You only
want to edit one. And since they are all identical, it doesn't matter which one
you edit so long as it is ONLY one, so a LIMIT works.

There is still a slight problem: Try editing a field, "Apply"-ing, and editing
again. The value in the text box does not match the value in the table - it's as
if the displayed value changes, but not the stored value. I'll look into that
this weekend if you want :).

Anyway, without farther ado, my first bk/C++/MyCC patch is below :).

--------------- Adam Hooper ada@densi.com

[adam@hera src]$ /opt/bitkeeper/bk diffs ===== CSqlTable.cpp 1.31 vs edited ===== 968c968,979 < QString key = m_pDatabaseConnection->Quote(fieldName) + "='" +
(const char *)value.local8Bit() + "'";

QString key;

// format the string according to what data type it is if (value.isNull()) key = m_pDatabaseConnection->Quote(fieldName) + " IS
NULL"; else if (Query->Fields[i].flags & NUM_FLAG) key = m_pDatabaseConnection->Quote(fieldName) + "
= " + (const char *)value.local8Bit(); else // string/other: Delimited with single quotes, and
any single quotes must be doubled. key = m_pDatabaseConnection->Quote(fieldName) + "
= '" + (const char
*)value.local8Bit().replace(QRegExp("'"), "''") + "'"; 1010a1022 allFields.append(" LIMIT 1");