DB Unit test for a table with a reserved name (`Group`)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DB Unit test for a table with a reserved name (`Group`)

Tan Tan
Hi, 

My problem is as such. 

I'm trying to set up dbunit tests for a project on a legacy database. It all works out great except for one table which is unfortunately called group. Or rather `Group`. Setting up/Creating the Group for the test works just fine via a direct SQL Create. [various selects in my DAO that use this table also run through provided they are ok with the table being empty] 

When I try to insert a dataset I either get 
'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group' at line 1' (when using something along the lines of <group id="myid" name="myname" />)

Or
'java.lang.RuntimeException: org.dbunit.dataset.NoSuchTableException: `Group`' (when using something along the lines of: 
    <table name="`Group`">
        <column>id</column>
        <column>name</column>
        <row>
            <value>myid</value>
            <value>myname</value>
        </row>
    </table> ) 

The table works fine in production since it's always only addressed as `Group`. Is there any way at all to trick DBUnit into working with this table short of renaming the table (again: legacy with lots of handwritten SQL)? 

Thank you for your help. 

Sophie

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: DB Unit test for a table with a reserved name (`Group`)

Darryl L. Pierce-2
On Thu, Feb 10, 2011 at 09:26:07AM +0100, Tan Tan wrote:

> Hi,
>
> My problem is as such.
>
> I'm trying to set up dbunit tests for a project on a legacy database. It all
> works out great except for one table which is unfortunately called group. Or
> rather `Group`. Setting up/Creating the Group for the test works just fine
> via a direct SQL Create. [various selects in my DAO that use this table also
> run through provided they are ok with the table being empty]
>
> When I try to insert a dataset I either get
> 'You have an error in your SQL syntax; check the manual that corresponds to
> your MySQL server version for the right syntax to use near 'group' at line
> 1' (when using something along the lines of <group id="myid" name="myname"
> />)
>
> Or
> 'java.lang.RuntimeException: org.dbunit.dataset.NoSuchTableException:
> `Group`' (when using something along the lines of:
>     <table name="`Group`">
Does it work without the backticks inside of the name? IOW:

<table name="Group">

I've never had to enclose the table name like that before.

>         <column>id</column>
>         <column>name</column>
>         <row>
>             <value>myid</value>
>             <value>myname</value>
>         </row>
>     </table> )
>
> The table works fine in production since it's always only addressed
> as `Group`. Is there any way at all to trick DBUnit into working with this
> table short of renaming the table (again: legacy with lots of handwritten
> SQL)?
>
> Thank you for your help.
>
> Sophie

> ------------------------------------------------------------------------------
> The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
> Pinpoint memory and threading errors before they happen.
> Find and fix more than 250 security defects in the development cycle.
> Locate bottlenecks in serial and parallel code that limit performance.
> http://p.sf.net/sfu/intel-dev2devfeb

> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user


--
Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc.
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user

attachment0 (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: DB Unit test for a table with a reserved name (`Group`)

Roberto Lo Giacco
In reply to this post by Tan Tan
I had your same problem with two tables in the SmartWeb AUTH module on a PostgreSQL database: user and group.

As you can see from here I was able to use the group and user table names directly in flat xml datasets https://smartweb.svn.sourceforge.net/svnroot/smartweb/trunk/modules/auth/res/dataset.xml

I think I've used the following dbUnit property/feature to dbunit to actually escape schemas AND table names...


connection.getConfig().setProperty(DatabaseConfig.PROPERTY_ESCAPE_PATTERN, dialect.openQuote() + "?" + dialect.closeQuote());

On Thu, Feb 10, 2011 at 15:56, Darryl L. Pierce <[hidden email]> wrote:
On Thu, Feb 10, 2011 at 09:26:07AM +0100, Tan Tan wrote:
> Hi,
>
> My problem is as such.
>
> I'm trying to set up dbunit tests for a project on a legacy database. It all
> works out great except for one table which is unfortunately called group. Or
> rather `Group`. Setting up/Creating the Group for the test works just fine
> via a direct SQL Create. [various selects in my DAO that use this table also
> run through provided they are ok with the table being empty]
>
> When I try to insert a dataset I either get
> 'You have an error in your SQL syntax; check the manual that corresponds to
> your MySQL server version for the right syntax to use near 'group' at line
> 1' (when using something along the lines of <group id="myid" name="myname"
> />)
>
> Or
> 'java.lang.RuntimeException: org.dbunit.dataset.NoSuchTableException:
> `Group`' (when using something along the lines of:
>     <table name="`Group`">

Does it work without the backticks inside of the name? IOW:

<table name="Group">

I've never had to enclose the table name like that before.

>         <column>id</column>
>         <column>name</column>
>         <row>
>             <value>myid</value>
>             <value>myname</value>
>         </row>
>     </table> )
>
> The table works fine in production since it's always only addressed
> as `Group`. Is there any way at all to trick DBUnit into working with this
> table short of renaming the table (again: legacy with lots of handwritten
> SQL)?
>
> Thank you for your help.
>
> Sophie


------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user