Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how write code to escape sql comments

 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want search for some strings in lot of sql files, could you please show me how to escape the sql comments like this :

---------------------------------------------
this package declaration is used to declare record types used by other
--functions
-- t_check_list is used in FN_SUBPLAN_CHK
---------------------------------------------

Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Apache Commons StringEscapeUtils. It has what you need and it's pretty darned simple.
 
majid nakit
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and thank you for your help, I just read the API of StringEscapeUtils, but don't understand what to use to escape comments in sql.
Please I will appreciate if you can give me an example.
thanks
 
Srikanth Ramu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you want to remove all the comments from a file containing sqls then search for the string. You may read the file line by line and check if the line starts with SQLs (SELECT, INSERT etc) add the lines to a StringBuffer till you reach the delimitor (semicolon,go,new empty line etc ). You might need to handle cases if comments appear with 1 sql statement. hope this helps
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, my bad on StringEscapeUtils. I went by the topic title, not by the example.

I've done just what Srikanth suggested when reading SQL statements from a file. Read past the comments, read and concatenate lines until you find a semicolon.

One time I had a convention of a name for the statement in the comments. I kept all the statements in a map keyed by statement name. Then it looked more like:

Is that the kind of thing you need?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic