score:1
your code does not show what the querydescription
class does, but i can guess.
in dealing with the where clause, you are looking for three types of nodes:
binarylogicaloperatornode
- this has the and, or, is operators that separate the individual clauses in the where clause.binaryoperatornode
- this has the individual >, <, and other operations.- the constants and column operators.
in your example, you would visit a binaryoperatornode
, with a type of lt
, and the two children would be constantnode
with a value of 5, and a columnreference
node with the value of "d".
note: the parser does not connect the column references to the tables in the tables list. this is a separate step in the query processing. so you will have a columnreference
node, but no link to which table the column is referencing. the reason is the parser does not have enough information to correctly link the "d" column to the correct table.
this is enough to process the simple query you gave in the example. obviously queries can become much more complex.
the one node i would add to the list of checks in the inlistoperatornode
which handles where d in (1,2,3,4)
.
edit to add:
keep in mind the vistor#visit()
method gets called for each and every node in the tree created by the query parser. the visit method will need to check, and set your variables properly, for frombasetable
, constantnode
, columnreference
.
visitor v = new visitor() {
list<string> fromtable = new arraylist<string>();
list<string> fields = new arraylist<string>();
// other visitor methods go here, not copied for conciseness.
@override
public visitable visit(visitable arg0) throws standardexception {
// other code from your visit() method goes here
//
if (arg0 instanceof frombasetable) {
frombasetable table = (frombasetable)arg0;
fromtable.append(table.gettablename());
} else if (arg0 instanceof columnreference) {
columnreference column = (columnreference) arg0;
fields.append(column.getcolumnname())
}
// remove the call to create querydescription
}
public querydescription getquerydescription() {
return new querydescription(se, fromtable, fields)
}
}
then in your main line of code you call:
stmt.accept(v);
querydescription description = v.getquerydescription();
now if you have other parts of the query you are interested in, you need to add those nodes to the visit method, and capture the part of the node (names, values, etc) you are interested in.
Source: stackoverflow.com
Related Query
- FoundationDB SQL Parser to get WHERE clause
- Eclipse: How to get TODOs from SQL and XML files in tasks
- Where to get the jar for openCV?
- Where to get Java eclipse extention\shourtcut for getters setters generation?
- Where do I get the JOGL JAR?
- Where exactly does a jsp page get deployed when run via Netbeans or Eclipse?
- Where can I get the update site for Spring tool suite
- Where can i get the .h file for OpenMP?
- How can I get Eclipse to store .class files in a folder outside the Project folder where I store the .java source files?
- How to get eclipse to mark where a for loop or if statement begins
- Where do Entities get saved if you run a GAE project in development mode?
- where do get ADT 18 for eclipse?
- Where can I get IBM Eclipse Tools for Bluemix for offline installation?
- Where does GWT Program arguments and VM arguments get saved on HDD?
- Where does the Eclipse SQL Explorer Plugin store its preferences?
- How do I get rid of null values in my SQL results in java?
- where can I get plugin.jar
- Where from can I get derby core plugin for eclipse?
- In Eclipse, how can get the SQL text when it's in a Java String?
- Where does Eclipse get list up update sites from?
- Where can I get the OEM driver for an IdeaPad A1-07?
- Where to get HELLO WORLD for .net with M2mQTT
- Should I use preparedStatement in a repetitive query in which where clause predicates change often causing change of plan chosen
- how to get info using ast parser
- Where should i get working URL of Teamprise plugin download for eclipse to access TFS server?
- Where to get the MWE2 libraries
- Spock test: Eclipse doesn't seem to recoganize the data variables in Where clause
- Where can I get previous ftp connections information after resetting workspace in eclipse with aptana plugin?
- How do I get the XML Dom node of where my cursor is in Eclipse?
- Java: Basic agenda program where one can manipulate their events and get notified of current week or day events if wishes to
More Query from same tag
- Incorrect classpath causing java.lang.NoClassDefFoundError
- How to find variable usage in Android Studio? (like Ctrl + Shift + G in Eclipse)
- In Eclipse, How to sort methods by class during auto-complete?
- Eclipse keep splitting my Test annotation
- how to create the webpage in blackberry using java on eclipse?
- Every directory shows up as modified using the Eclipse git plugin
- Modifying foreign Workspaces in RCP Apps
- Eclipse: "Delete" button wants to delete my source files instead of code.. why?
- webdriver API: how to disable verbose error messages?
- Rename and Refactor Class in Eclipse, and Keep SVN History
- Eclipse - PHP Project's Version Number
- Use a single external jar in multiple runnable jars
- Adding LOG.i() to the program
- Error occurred during the build
- Add JBoss 7 server in domain mode to Eclipse
- Calendar.getInstance cannot be resolved to a type
- WARNING: Setting property 'source' to 'org.eclipse.jst.jee.server:appname' did not find a matching property
- Eclipse access to workspace, compiler and export function from code
- eclipse cannot find stdarg.h
- Multiple versions of the same multi-modules maven project under eclipse
- How to get Eclipse to do auto-javadoc comments in Javascript document
- Memory Setting for OC4J in Eclipse
- programmatically change the background color in eclipse
- Reformatting a lot of classes
- JVM crashes while trying to run Junit test case
- How get ctrl + space to autocomplete in eclipse
- Eclipse - Several Errors After Altering Proguard and Manifest Files
- Simplifying fully qualified names in Eclipse
- Develop raspberry pi app with eclipse
- Unused local variable warning in self-executing anonymous function