
Here is my code
import java.io.* ;
import java.util.*;
import java.text.*;
/*class QS1
{
String[] buf = new String[50];
// String[]buf={"select * from emp;"};
}*/
class QS2
{
String type;
String contents;
QS2 nestedquery;
QS2 next;
String[] buf;
QS2(String t,String c,QS2 n,QS2 nx){
type=t;
contents=c;
nestedquery=n;
next=nx;
}
}
public class GenerateGLL {
///private static class generateQueryStrcture {
//public generateQueryStrcture() {
//}
// QS1 qs = new QS1();
int count = 0 ;
// static String[] token;
public static void main(String args[])
{
generateQueryStrcture r=new generateQueryStrcture();
QS2 generateQueryStrcture = r.generateQueryStrcture();
//FormsPlSql p = new FormsPlSql();
//String tokens[] = p.parseAndGenerateTokens("select * from emp where name='abc';");
}
}
class generateQueryStrcture
{
generateQueryStrcture()
{
}
public QS2 generateQueryStrcture() {
QS2 qs1 = null,qs2 = null,qs3=null;
// QS2 qs = null;
//String[] buf = new String[50];
//String[] tokens = {"select","lid,bid","from","emp","where","emp.id<5 and name='abc'",";"};
//tail=null;
//tokens[] = { "select * from emp;" };
FormsPlSql t = new FormsPlSql();
String tokens[] = t.parseAndGenerateTokens("select * from emp where name='abc';");
int count = 0;
int i;
for( i = 0 ;i < tokens.length ; i++){
if(tokens[i].equalsIgnoreCase("select"))
{
qs1 = new QS2("SELECT",null, null, null);
count = i;
while(!tokens[i].equalsIgnoreCase("from"))
{
if(tokens[i].equals("("))
{
}
qs1.contents = tokens[i];
i++;
}
qs1.next = qs2;
break;
}
}
for( i = count ;i < tokens.length ; i++){
if(tokens[i].equalsIgnoreCase("from"))
{
qs2 = new QS2("FROM",null, null, null);
// handle nesting..
count = i;
while(!tokens[i].equalsIgnoreCase("where"))
{
qs2.contents = tokens[i];
i++;
}
qs1.next = qs2;
break;
}
}
for( i = 0 ;i < tokens.length ; i++){
if(tokens[i].equalsIgnoreCase("where"))
{
qs3 = new QS2("WHERE",null, null, null);
// handle nesting..
//count = i;
while(!tokens[i].equals(";"))
{
qs3.contents = tokens[i];
i++;
}
qs2.next = qs3;
//QS2 tail = new QS2(null, null, null, null);
//qs3.next = tail;
break;
}
}
qs1.next = qs2;
qs2.next = qs3;
QS2 tail = new QS2(null, null, null, null);
qs3.next = tail;
for(QS2 q=qs1; q.next!=null; q=q.next){
System.out.println("Type "+q.type);
System.out.println("Content : "+q.contents);
System.out.println("=============");
}
return qs1;
}
}
//System.out.println(qs1);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.