Newbie: Writing the FlatXml file to a database?

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

Newbie: Writing the FlatXml file to a database?

Mark Spezzano-4

Hi,

 

I read in data from a database X and write it out into a flat xml file called DATABASE_DUMP.xml

 

How can I then get this database .xml file and the WRITE/copy it into another database Y? (a “unit test” database) (so that Y now contains a pruned-out version of what was in X)

 

Or am I missing something about the intended operation of DbUnit?

 

Thanks for your help,

 

Mark

 


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

John Hurst-2
Have you looked at the DbUnit Ant tasks?

  http://www.dbunit.org/anttask.html

You can use the <export> task to export from a database to an XML file. You can then use an <operation type="CLEAN_INSERT"> to import to another database. See the examples online.

Regards

John Hurst

On Mon, Nov 2, 2009 at 4:43 PM, Mark Spezzano <[hidden email]> wrote:

Hi,

 

I read in data from a database X and write it out into a flat xml file called DATABASE_DUMP.xml

 

How can I then get this database .xml file and the WRITE/copy it into another database Y? (a “unit test” database) (so that Y now contains a pruned-out version of what was in X)

 

Or am I missing something about the intended operation of DbUnit?

 

Thanks for your help,

 

Mark

 


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

Mark Spezzano-4

Hi John,

 

Thanks for the quick reply.

 

Yes, I looked at this. Unfortunately this poses two unrelated issues, namely:

 

a)      My database contains a table called USER which is also a keyword and so the export fails

b)      Does the CLEAN_INSERT actually recreate the database schema in full? That is, with all of the tables and their relationships populated with the correct data?

 

Thanks for your advice,

 

Mark

 

From: John Hurst [mailto:[hidden email]]
Sent: Monday, 2 November 2009 5:05 PM
To: [hidden email]
Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?

 

Have you looked at the DbUnit Ant tasks?

  http://www.dbunit.org/anttask.html

You can use the <export> task to export from a database to an XML file. You can then use an <operation type="CLEAN_INSERT"> to import to another database. See the examples online.

Regards

John Hurst

On Mon, Nov 2, 2009 at 4:43 PM, Mark Spezzano <[hidden email]> wrote:

Hi,

 

I read in data from a database X and write it out into a flat xml file called DATABASE_DUMP.xml

 

How can I then get this database .xml file and the WRITE/copy it into another database Y? (a “unit test” database) (so that Y now contains a pruned-out version of what was in X)

 

Or am I missing something about the intended operation of DbUnit?

 

Thanks for your help,

 

Mark

 


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

John Hurst-2
Not sure about the USER issue. What database are you using? If USER is a valid table or column name in your database, then DbUnit ought to support it. If not, let me know details.

CLEAN_INSERT, and DbUnit generally, is limited to dealing with contents of tables, not structure. That is, it will not create tables.

DbUnit has two purposes:
  - Prime a (already existing) database with known test data before running some kind of test, and
  - Verify database content after running a test.

You can find other tools for creating database tables or cloning tables, structure and all, from one database to another.

Regards

John Hurst

On Mon, Nov 2, 2009 at 8:15 PM, Mark Spezzano <[hidden email]> wrote:

Hi John,

 

Thanks for the quick reply.

 

Yes, I looked at this. Unfortunately this poses two unrelated issues, namely:

 

a)      My database contains a table called USER which is also a keyword and so the export fails

b)      Does the CLEAN_INSERT actually recreate the database schema in full? That is, with all of the tables and their relationships populated with the correct data?

 

Thanks for your advice,

 

Mark

 

From: John Hurst [mailto:[hidden email]]
Sent: Monday, 2 November 2009 5:05 PM
To: [hidden email]
Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?

 

Have you looked at the DbUnit Ant tasks?

  http://www.dbunit.org/anttask.html

You can use the <export> task to export from a database to an XML file. You can then use an <operation type="CLEAN_INSERT"> to import to another database. See the examples online.

Regards

John Hurst

On Mon, Nov 2, 2009 at 4:43 PM, Mark Spezzano <[hidden email]> wrote:

Hi,

 

I read in data from a database X and write it out into a flat xml file called DATABASE_DUMP.xml

 

How can I then get this database .xml file and the WRITE/copy it into another database Y? (a “unit test” database) (so that Y now contains a pruned-out version of what was in X)

 

Or am I missing something about the intended operation of DbUnit?

 

Thanks for your help,

 

Mark

 


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

Roberto Lo Giacco-4
On Mon, Nov 2, 2009 at 08:28, John Hurst <[hidden email]> wrote:
> Not sure about the USER issue. What database are you using? If USER is a
> valid table or column name in your database, then DbUnit ought to support
> it. If not, let me know details.

Well, I've the same problem with postgres and a table of mine named
"user". I solved the problem using fully qualified names, which always
prepend the schema name, and the escaped table names, which encloses
the table names in escaping chars, resulting in "auth"."user" which is
no more confusing for the database and dbunit.

> CLEAN_INSERT, and DbUnit generally, is limited to dealing with contents of
> tables, not structure. That is, it will not create tables.
>
> DbUnit has two purposes:
>   - Prime a (already existing) database with known test data before running
> some kind of test, and
>   - Verify database content after running a test.
>
> You can find other tools for creating database tables or cloning tables,
> structure and all, from one database to another.

Structural statements, aka DDL, are too much rdbms related: if you use
the same rdbms on both environments I suggest to export your database
structure and recreate it on the second database: db structures should
not vary often... if your structure vary often I think you are missing
the data analysis phase in your development cycle.

Roberto Lo Giacco

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

Mark Spezzano-4
In reply to this post by John Hurst-2

Hi

 

I have a database schema containing the table USER. Unfortunately we’re using MS SQL Server which uses USER as a keyword.

 

So I can export the USER table like this:

 

dataSet.addTable("USER]", "SELECT * FROM " + "\"USER\"");

 

which results in XML like this:

 

<"USER" loginName="mark"/>

 

But then my unit test tries to read in the XML and says that:

 

java.sql.SQLException: Incorrect syntax near the keyword USER

 

--obviously it’s interpreting the USER as a keyword instead of a table.

 

Can I put some kind of escape characters around USER so that it reads in USER as a table?

 

Thanks

 

Mark Spezzano

 

 

From: John Hurst [mailto:[hidden email]]
Sent: Monday, 2 November 2009 5:58 PM
To: [hidden email]
Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?

 

Not sure about the USER issue. What database are you using? If USER is a valid table or column name in your database, then DbUnit ought to support it. If not, let me know details.

CLEAN_INSERT, and DbUnit generally, is limited to dealing with contents of tables, not structure. That is, it will not create tables.

DbUnit has two purposes:
  - Prime a (already existing) database with known test data before running some kind of test, and
  - Verify database content after running a test.

You can find other tools for creating database tables or cloning tables, structure and all, from one database to another.

Regards

John Hurst

On Mon, Nov 2, 2009 at 8:15 PM, Mark Spezzano <[hidden email]> wrote:

Hi John,

 

Thanks for the quick reply.

 

Yes, I looked at this. Unfortunately this poses two unrelated issues, namely:

 

a)      My database contains a table called USER which is also a keyword and so the export fails

b)      Does the CLEAN_INSERT actually recreate the database schema in full? That is, with all of the tables and their relationships populated with the correct data?

 

Thanks for your advice,

 

Mark

 

From: John Hurst [mailto:[hidden email]]
Sent: Monday, 2 November 2009 5:05 PM
To: [hidden email]
Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?

 

Have you looked at the DbUnit Ant tasks?

  http://www.dbunit.org/anttask.html

You can use the <export> task to export from a database to an XML file. You can then use an <operation type="CLEAN_INSERT"> to import to another database. See the examples online.

Regards

John Hurst

On Mon, Nov 2, 2009 at 4:43 PM, Mark Spezzano <[hidden email]> wrote:

Hi,

 

I read in data from a database X and write it out into a flat xml file called DATABASE_DUMP.xml

 

How can I then get this database .xml file and the WRITE/copy it into another database Y? (a “unit test” database) (so that Y now contains a pruned-out version of what was in X)

 

Or am I missing something about the intended operation of DbUnit?

 

Thanks for your help,

 

Mark

 


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user




--
Life is interfering with my game


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user
Reply | Threaded
Open this post in threaded view
|

Re: Newbie: Writing the FlatXml file to a database?

Roberto Lo Giacco-4
If you put in your XML

<SCHEMA.USER loginName="mark"/>

and set the dbunit feature
http://www.dbunit.org/features/qualifiedTableNames AND the dbunit
property http://www.dbunit.org/properties/escapePattern you should get
what you need.

Please ignore the notice on the dbunit site stating you cannot mix
this two features (http://www.dbunit.org/properties.html), it's an old
and obsolete notice that will be updated on site republish.

With those two features set you can export your database with the
following statement

dataSet.addTable("USER", "SELECT * FROM SCHEMA.USER");

The schema part was required by my PostgreSQL otherwise it was
failing, may be you do not need the SCHEMA and the related feature,
give it a try and let us know.

   Roberto Lo Giacco



On Wed, Nov 4, 2009 at 06:21, Mark Spezzano <[hidden email]> wrote:

> Hi
>
>
>
> I have a database schema containing the table USER. Unfortunately we’re
> using MS SQL Server which uses USER as a keyword.
>
>
>
> So I can export the USER table like this:
>
>
>
> dataSet.addTable("USER]", "SELECT * FROM " + "\"USER\"");
>
>
>
> which results in XML like this:
>
>
>
> <"USER" loginName="mark"/>
>
>
>
> But then my unit test tries to read in the XML and says that:
>
>
>
> java.sql.SQLException: Incorrect syntax near the keyword USER
>
>
>
> --obviously it’s interpreting the USER as a keyword instead of a table.
>
>
>
> Can I put some kind of escape characters around USER so that it reads in
> USER as a table?
>
>
>
> Thanks
>
>
>
> Mark Spezzano
>
>
>
>
>
> From: John Hurst [mailto:[hidden email]]
> Sent: Monday, 2 November 2009 5:58 PM
>
> To: [hidden email]
> Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?
>
>
>
> Not sure about the USER issue. What database are you using? If USER is a
> valid table or column name in your database, then DbUnit ought to support
> it. If not, let me know details.
>
> CLEAN_INSERT, and DbUnit generally, is limited to dealing with contents of
> tables, not structure. That is, it will not create tables.
>
> DbUnit has two purposes:
>   - Prime a (already existing) database with known test data before running
> some kind of test, and
>   - Verify database content after running a test.
>
> You can find other tools for creating database tables or cloning tables,
> structure and all, from one database to another.
>
> Regards
>
> John Hurst
>
> On Mon, Nov 2, 2009 at 8:15 PM, Mark Spezzano <[hidden email]>
> wrote:
>
> Hi John,
>
>
>
> Thanks for the quick reply.
>
>
>
> Yes, I looked at this. Unfortunately this poses two unrelated issues,
> namely:
>
>
>
> a)      My database contains a table called USER which is also a keyword and
> so the export fails
>
> b)      Does the CLEAN_INSERT actually recreate the database schema in full?
> That is, with all of the tables and their relationships populated with the
> correct data?
>
>
>
> Thanks for your advice,
>
>
>
> Mark
>
>
>
> From: John Hurst [mailto:[hidden email]]
> Sent: Monday, 2 November 2009 5:05 PM
> To: [hidden email]
> Subject: Re: [dbunit-user] Newbie: Writing the FlatXml file to a database?
>
>
>
> Have you looked at the DbUnit Ant tasks?
>
>   http://www.dbunit.org/anttask.html
>
> You can use the <export> task to export from a database to an XML file. You
> can then use an <operation type="CLEAN_INSERT"> to import to another
> database. See the examples online.
>
> Regards
>
> John Hurst
>
> On Mon, Nov 2, 2009 at 4:43 PM, Mark Spezzano <[hidden email]>
> wrote:
>
> Hi,
>
>
>
> I read in data from a database X and write it out into a flat xml file
> called DATABASE_DUMP.xml
>
>
>
> How can I then get this database .xml file and the WRITE/copy it into
> another database Y? (a “unit test” database) (so that Y now contains a
> pruned-out version of what was in X)
>
>
>
> Or am I missing something about the intended operation of DbUnit?
>
>
>
> Thanks for your help,
>
>
>
> Mark
>
>
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
> --
> Life is interfering with my game
>
> ------------------------------------------------------------------------------
> Come build with us! The BlackBerry(R) Developer Conference in SF, CA
> is the only developer event you need to attend this year. Jumpstart your
> developing skills, take BlackBerry mobile applications to market and stay
> ahead of the curve. Join us from November 9 - 12, 2009. Register now!
> http://p.sf.net/sfu/devconference
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>
> --
> Life is interfering with my game
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus
> on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> dbunit-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/dbunit-user
>
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
dbunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/dbunit-user