Hi Rob,
your comment sounds reasonable.
I will finish the implementation and create a script a you recommended.
At first, I will change the DataTypes by a conservative way, so that the
actual behaviour will not be changed. In a future step it seems, that
some DataTypes which doesn't support the where clause at the moment,
could change their behaviour.
But first I will ensure the actual functionality with PreparedStatements.
OK - so far...
Stefan
Am 2010-11-04 01:40, schrieb Robert Manning:
> Setfan,
>
> Thinking about this more, I agree that this change would be beneficial
> in the ways you have described. However, it is a bit like major
> surgery and presents a bit of risk to include in the 3.2 release which
> we are currently preparing. If Gerd agrees, I would like to see this
> as a patch soon after we release 3.2. One other thing; it would be
> nice to demonstrate how effective this implementation is on various
> databases. I am thinking perhaps 1) simple SQL script to create a
> table and populate it with data that needs to be quoted and 2) a test
> driver that connects and verifies that the PreparedStatement approach
> works as expected. If such a test existed I have a number of
> databases setup to verify it against. I know that this sounds like
> more of a test for JDBC drivers, but as SQuirreL depends on the
> driver, it is affected by the bugs they have. Does that sound
> reasonable ?
>
> Rob
>
> On Mon, Oct 25, 2010 at 10:14 AM, Stefan Willinger<ste...@ao...> wrote:
>
>> Hi Rob,
>>
>> we have already discussed the reason, why Squirrel cannot edit db-fields
>> with an backslash on an MySql-DB.
>>
>> It seems that for an PostgresSQL-DB the same problem was solved by using
>> an DatabaseSpecificEscape e.g. PostgreSQLEscape
>>
>> Now sure, we could do the same for an MySql-DB like this:
>>
>> private static class MySqlSQLEscape implements IEscape
>> {
>> public boolean productMatches(ISQLDatabaseMetaData md)
>> {
>> return DialectFactory.isMySQL5(md);
>> }
>> /**
>> * For a MySQL Database we need to escape some characters.
>> *<a
>> href="http://dev.mysql.com/doc/refman/5.1/de/string-syntax.html">See the
>> MySQL Manual</a
>> * @see
>> net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DatabaseSpecificEscape.IEscape#escapeSQL(java.lang.String)
>> */
>> public String escapeSQL(String sql)
>> {
>> return sql.replaceAll("\\\\","\\\\\\\\");
>> }
>> }
>>
>> Sure, this code would be very simple, but it doesn't work on all MySql
>> DB-Configuration. At an MySQL DB you can set the SQL-MODE to
>> NO_BACKSLASH_ESCAPES. Enabling this mode, than an escaped Backslash
>> would be treated as two backslashes. Then this code would fail.
>>
>> Sure, Squirrel could check, if escaping an Backslash is necessary. e.g .
>> with this SQL: SELECT @@SESSION.sql_mode
>>
>> Another drawback of using an DatabaseSpecificEscape is, that the
>> escapeSQL(string) method is applied to the whole where clause, not only
>> to string-fields, which might be a problem.
>>
>> *Another solution:*
>> On the other side, when using PreparedStatements, then the DB-Driver is
>> responsible for escaping special characters. But what changes would this
>> mean:
>>
>> * Changing the signature of
>> IDataTypeComponent.getWhereClauseValue(Object, ISQLDatabaseMetaData)
>> * Changing the implementation of all DataTypes
>> * Changing the implementation of DataSetUpdateableTableModelImpl
>> o deleteRows
>> o getWarningOnCurrentData
>> o getWarningOnProjectedUpdate
>> o getWhereClause
>> o reReadDatum
>> o updateTableComponent
>>
>> When doing so, some duplicate code about counting affected rows could be
>> removed.
>>
>> The solution I would discuss is following:
>>
>> * The DataType should return an Interface WhereClausePart instead of
>> an String representation like column=value.
>> * The WhereClausePart should have following methods
>> o public String getWhereClause();
>> o public void appendToClause(StringBuilder whereClause);
>> o public void setParameter(PreparedStatement pstmt, int
>> position) throws SQLException;
>> o public boolean isParameterUsed();
>> * The WhereClausePart could have several implementations:
>> o AbstractWhereClausePart: Basic implementation which have a
>> reference to IDataTypeComponent for the capability to set
>> the parameters into the PreparedStatements.
>> o NopWhereClausePart: Instead of returning an empty String,
>> Return this for an "No Operation" meaning.
>> o IsNullWhereClausePart: This part of the where-clause
>> represents an "is null" statement
>> o ParameterWhereClausePart: This clause use an JDBC-Parameter
>> for the where clause
>> o NoParameterWhereClausePart: For all special situations like
>> DataTypeDate with the trunc-method. The benefit of this
>> class is, that each DataType could decide if it want to use
>> an parameter or the hard-coded part of the where clause.
>> * Change DataSetUpdateableTableModelImpl to use PreparedStatements.
>>
>> So, what did you think, is this an appropriated solution for this bug
>> and an additional value for Squirrel?
>>
>> When yes, let it me know, I have already done most of the work :-)
>>
>> Stefan
>> ------------------------------------------------------------------------------
>> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
>> Create new apps& games for the Nokia N8 for consumers in U.S. and Canada
>> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
>> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
>> http://p.sf.net/sfu/nokia-dev2dev
>> _______________________________________________
>> Squirrel-sql-develop mailing list
>> Squ...@li...
>> https://lists.sourceforge.net/lists/listinfo/squirrel-sql-develop
>>
>>
>
|