Any parser for SQL to read and write in java [message #446587] |
Tue, 09 March 2010 07:37  |
manjukmoorthi
Messages: 20 Registered: February 2010
|
Junior Member |
|
|
Hello,
I want to know if there are any freeware's available to read and write .sql files. I hava a .sql file with set of insert statements and I need to identify the values that are pushed into table, the table name, the inner query clauses etc., from the sql statement.
After identifying, need to translate and push those changes back to the .sql file. Is there any way to do this with help of parsers rather reading the whole of file line by line.
I did come across few parsers like ZQL, sqljep etc., but could not really solve the issue. Please help..
Thanks in advance.
|
|
|
|
Re: Any parser for SQL to read and write in java [message #446682 is a reply to message #446587] |
Tue, 09 March 2010 23:20   |
manjukmoorthi
Messages: 20 Registered: February 2010
|
Junior Member |
|
|
Say I have a line like below,
INSERT INTO soms_user_settings
(user_id,
module_id,
section_id,
key_id,
value_id,
DESCRIPTION,
preference_list,
preference_type,
default_value,
preference_list_local,
default_value_local)
SELECT DISTINCT 'LANGUAGE',
'L',
'system_preferences',
'ATASSht',
'Action Statement Sheet',
'LCO Tracking label for printing Action Statement Sheet',
NULL,
9,
'Action Statement Sheet',
NULL,
NULL
FROM dual
WHERE NOT EXISTS (SELECT *
FROM soms_user_settings
WHERE user_id = 'LANGUAGE'
AND module_id = 'L'
AND section_id = 'system_preferences'
AND key_id = 'ATASSht');
These statements gets repeated in the file consecutively. I need to get the insert column values (like user_id, module_id etc.,) and values that are inserted into the table (like 'LANGUAGE', 'L','system_preferences' etc., ) into any data structure. And also replace the values with translated values in same positions in writing back the values.
|
|
|
Re: Any parser for SQL to read and write in java [message #446689 is a reply to message #446682] |
Wed, 10 March 2010 00:23  |
 |
Michel Cadot
Messages: 68737 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
I think you have to create your own parser.
If the purpose is just this, it is not very difficult to create one using lex and yacc on Unix. I have created a parser for SELECT (which is far more complex) using these tools (more than 15 years ago).
It was in C but I think there would exist the same tools in Java now.
Regards
Michel
|
|
|