currently I have the following code:
String select = qry.substring('select '.length(),qry2.indexOf(' from ')); String[] attrs = select.split(',');
which works for the most parts but fails if given the following:
qry = 'select a,b,c,DATETOSTRING(date_attr_name,'mm/dd/yyyy') from tbl_a';
what I’m looking for is the regex to feed to String.split() which will hande that situation, and for that matter any other special cases you might be able to think of that I’m missing.
Should do it nicely provided you always add a final ‘,’ to your select string:
would fail to split the last ‘fff’ attributes, but:
would captures it. So a little pre-processing would smooth things out.
Caveat: this does not take into account expression within expression
Tell me if that can happen in the queries you have to process.
Caveat bis: since this needs a true regexp and not a simple separator expected by split(), you must use a Matcher, based on the pattern
[^,]+\([^\)]+\)|[^,]),, and iterate on Matcher.find() to fill the array of attributesattrs.In short, with split() function, there is no single simple separator that might do the trick.