This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 225079

Summary: SQLIdentifiers.Quoter does not correctly quote identifiers containing the quote character itself
Product: db Reporter: ebakke
Component: CodeAssignee: Jaroslav Havlin <jhavlin>
Status: RESOLVED FIXED    
Severity: normal Keywords: NETFIX
Priority: P3    
Version: 7.2.1   
Hardware: PC   
OS: Mac OS X   
Issue Type: DEFECT Exception Reporter:
Attachments: proposed patch v1 part 1
proposed patch v1 part 2

Description ebakke 2013-01-18 23:14:12 UTC
The default implementation of org.netbeans.api.db.sql.support.SQLIdentifiers.Quoter does not correctly quote/unquote identifiers that contains the quote string itself. The correct way to do quote the quote string is, as far as I know, to include it twice (at least for MySQL and Postgres--I just tried it).

For instance, in MySQL, the quote string is "`" (a single backtick character), and so a table named "Table with `Backticks` and Spaces" should be quoted as "`Table with ``Backticks`` and Spaces`".

The bug can be exhibited for instance by creating a table in MySQL with a name containing a backtick character, then connecting to the database from NetBeans, and then clicking "View Data..." on the table to see the generated query with the incorrect quoting.

The methods that need updating are Quoter.doQuote(), Quoter.unquote(), and probably DatabaseMetaDataQuoter.needToQuote() (the latter to ensure that the identifier does not contain the quote string).

(As an aside: I wonder if there are databases out there that quote the quote character differently...)
Comment 1 matthias42 2013-01-19 21:04:26 UTC
Created attachment 130405 [details]
proposed patch v1 part 1

The diagnosis is correct and reproducible. The first attached patch fixes this and adds a unit-test for this.
Comment 2 matthias42 2013-01-19 21:12:09 UTC
Created attachment 130406 [details]
proposed patch v1 part 2

Part 2 of the patch - the lexer did not correctly worked with identifier quoting characters other than ". The patch includes a modified unit-test.
Comment 3 ebakke 2013-01-20 18:19:20 UTC
Thanks--I'm impressed by the swift response :-)

(I take back my earlier suggestion that DatabaseMetaDataQuoter.needToQuote() needed to be changed--the patch looks good.)
Comment 4 Jaroslav Havlin 2013-02-08 11:20:01 UTC
Integrated as http://hg.netbeans.org/core-main/rev/2faf2562a671

Thank you very much for reporting, Ebakke, and for the patch, Matthias!
Comment 5 Quality Engineering 2013-02-10 01:41:23 UTC
Integrated into 'main-golden', will be available in build *201302092300* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/2faf2562a671
User: Jaroslav Havlin <jhavlin@netbeans.org>
Log: #225079: SQLIdentifiers.Quoter does not correctly quote identifiers containing the quote character itself