Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-22-2007, 05:20 AM   #1 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
jdbc

My company use Maven to run a DBRefresh goal. There are prepared .sql bootstrap file that need to be run when installing the product. I wrote a framework that automates the setup and execution of the junit funcitonal tests.

My problem now is that the java class that was written (I didn't write it) to parse the .sql bootstrap file reads in the .sql file line by line and does some find and replace of a couple of things, and then it will execute the sql statement. The biggest problem is how it decides when a sql statement is complete.

Here is the code:

Code:
if (!isComment) {

// Concatenate lines until separator line is reached.
// FIXME: The parsing is quite broken, as it doesn't handle
// things like stored procs and triggers well...  needs to either
// be a proper parser or should just go away and use the vendor's tools
// to run scripts.
  if( trimmed.equals(".") ) {
    multiLine += ";\n";
  } else if ( trimmed.equalsIgnoreCase( "run" ) ) {
    executeStatement( multiLine, continueOnFailure );
    multiLine = "";
  } else if( multiLine.equals( "" ) || currentLine.matches( "^\\s+.*" ) ) {
    multiLine += (currentLine + "\n");
  } else if ( !multiLine.equals( "" ) ) {
    executeStatement( multiLine, continueOnFailure );
    multiLine = trimmed.equals( ";" ) ? "" : currentLine + "\n";
  }
}
( "^\\s+.*" ) So when the code find a line with whitespace and some number of characters after it will concatenate it to the previous line. This means we have to make sure anyone who changes the schema must put at least a single whitespace character before the next line of their statement. I do not what to make the developers do this. The file is a valid sql file because I ran it through sqlplus and it execute flawlessly.

I am hoping there is someway I can just execute an entire sql file through jdbc or some other mechanism? I can use ant's replace functionality to edit the file as needed but I have no idea how to parse the sql file without make a whole bunch of rules.

-Toe
__________________
toe_cutter is offline   Reply With Quote
Old 03-22-2007, 05:11 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
Do all the valid SQL statements end in ";"?
__________________
GitS
Belisarius is offline   Reply With Quote
Old 03-27-2007, 11:42 AM   #3 (permalink)
toe_cutter
Code Monkey
 
Join Date: Aug 2002
Location: Boston, MA
Posts: 79
toe_cutter is on a distinguished road
Send a message via ICQ to toe_cutter Send a message via AIM to toe_cutter Send a message via Yahoo to toe_cutter
Quote:
Originally Posted by Belisarius View Post
Do all the valid SQL statements end in ";"?
Yes they do, but there can be a problem of queries inside queries.

I solved it by not using Java at all. I wrote a maven plugin that installs the oracle instant client which allows you to run sqlplus commands to a remote host.

-Toe
__________________
toe_cutter is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JDBC: Insert ID sde Java 12 06-21-2004 08:23 PM


All times are GMT -8. The time now is 10:10 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting