Search in sources :

Example 1 with CCJSqlParserManager

use of net.sf.jsqlparser.parser.CCJSqlParserManager in project JSqlParser by JSQLParser.

the class MemoryTest method main.

public static void main(String[] args) throws Exception {
    System.gc();
    System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    /*
         * String longQuery = new String(
         * "select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          " +
         * "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           " +
         * "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             " +
         * "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           " +
         * "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 " +
         * "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      " +
         * "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 " +
         * "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       " +
         * "wct_workflows.active_version_id ))) UNION  SELECT  wct_workflows.workflow_id  as       " +
         * "id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                        " +
         * "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              " +
         * "'W'  or  wct_audit_entry.privilege  =  'C'  )  and  wct_audit_entry.outcome            " +
         * "=  't'  and  wct_audit_entry.transaction_id  =                                         " +
         * "wct_transaction.transaction_id  and  wct_transaction.user_id  = 164 and                " +
         * "afdf=  (  select  wct_audit_entry.object_id  from  wct_audit_entry  ,                  " +
         * "wct_workflow_archive  where  wct_audit_entry.object_id  =                              " +
         * "wct_workflow_archive.archive_id  and  wct_workflows.workflow_id  =                     " +
         * "wct_workflow_archive.workflow_id  )                                                    " +
         * "UNION  SELECT  wct_workflows.workflow_id                                               " +
         * "as  id  ,  wct_transaction.date  as  date  FROM  wct_audit_entry  ,                    " +
         * "wct_transaction  ,  wct_workflows  WHERE  (  wct_audit_entry.privilege  =              " +
         * "'W'  OR  wct_audit_entry.privilege  =  'E'  OR  wct_audit_entry.privilege  =           " +
         * "'A'  )  and  wct_audit_entry.outcome  =  't'  and                                      " +
         * "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 " +
         * "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       " +
         * "wct_workflows.workflow_id    UNION SELECT * FROM interm2  ,  wct_workflow_docs  WHERE  " +
         * "interm2.id  =  wct_workflow_docs.document_id  ORDER BY  id  ,  date  DESC              ");
         */
    String longQuery = "select * from k where ID > 4";
    /*
         * String longQuery = "select  *  from  (  SELECT  intermediate.id  as  id  ,  intermediate.date  as          "
         * + "date  FROM  (  SELECT  DISTINCT   (  id  )   FROM  (  SELECT                           " +
         * "wct_workflows.workflow_id  as  id  ,  wct_transaction.date  as  date  FROM             " +
         * "wct_audit_entry  ,  wct_transaction  ,  wct_workflows  WHERE                           " +
         * "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 " + "'C'  ))))";
         */
    /*
         * String longQuery = "select  *  from  d WHERE                           " +
         * "(  wct_audit_entry.privilege  =  'W'  or  wct_audit_entry.privilege  =                 " +
         * "'C'  )  and  wct_audit_entry.outcome  =  't'  and                                      " +
         * "wct_audit_entry.transaction_id  =  wct_transaction.transaction_id  and                 " +
         * "wct_transaction.user_id  = 164 and  wct_audit_entry.object_id  =                       " +
         * "wct_workflows.active_version_id ";
         */
    StringReader stringReader = new StringReader(longQuery);
    Statement statement = parserManager.parse(stringReader);
    // stringReader = new StringReader(longQuery);
    // Statement statement2 = parserManager.parse(stringReader);
    // stringReader = null;
    // statement2 = null;
    statement = null;
    parserManager = null;
    longQuery = null;
    System.gc();
    System.out.println(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
}
Also used : Statement(net.sf.jsqlparser.statement.Statement) StringReader(java.io.StringReader) CCJSqlParserManager(net.sf.jsqlparser.parser.CCJSqlParserManager)

Example 2 with CCJSqlParserManager

use of net.sf.jsqlparser.parser.CCJSqlParserManager in project InformationSystem by ObeoNetwork.

the class ViewContentProvider method parseViewQuery.

/**
 * Parse the query to find tables and columns used for the view.
 * @param query
 */
public void parseViewQuery(String query) {
    Statement statement;
    CCJSqlParserManager pm = new CCJSqlParserManager();
    try {
        statement = pm.parse(new StringReader(query));
        if (statement instanceof Select) {
            Select selectStatement = (Select) statement;
            ViewContentFinder viewContentFinder = new ViewContentFinder();
            viewContentFinder.parseView(selectStatement);
            for (Table table : viewContentFinder.getTables()) {
                tables.add(table.getName());
            }
            columns = viewContentFinder.getColumns();
        }
    } catch (JSQLParserException e) {
    // nothing to do
    }
}
Also used : Table(net.sf.jsqlparser.schema.Table) Statement(net.sf.jsqlparser.statement.Statement) JSQLParserException(net.sf.jsqlparser.JSQLParserException) StringReader(java.io.StringReader) Select(net.sf.jsqlparser.statement.select.Select) CCJSqlParserManager(net.sf.jsqlparser.parser.CCJSqlParserManager)

Example 3 with CCJSqlParserManager

use of net.sf.jsqlparser.parser.CCJSqlParserManager in project yyl_example by Relucent.

the class JsqlparserExample method main.

public static void main(String[] args) throws Exception {
    String sql = // 
    "update demo_table t1 set " + // 
    "  column1 = '1' " + // 
    " ,column2 = '1' " + // 
    " ,column3 = '2' " + // 
    " ,column4 = '3' " + " where id=0";
    CCJSqlParserManager pm = new CCJSqlParserManager();
    Statement statement = pm.parse(new StringReader(sql));
    if (statement instanceof Update) {
        Update updateStatement = (Update) statement;
        System.out.println(updateStatement.getTable());
        Expression where = updateStatement.getWhere();
        if (where instanceof BinaryExpression) {
            BinaryExpression expression = (BinaryExpression) where;
            System.out.println(expression.getLeftExpression());
            System.out.println(expression.getStringExpression());
            System.out.println(expression.getRightExpression());
        }
    }
}
Also used : BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) Expression(net.sf.jsqlparser.expression.Expression) Statement(net.sf.jsqlparser.statement.Statement) StringReader(java.io.StringReader) Update(net.sf.jsqlparser.statement.update.Update) CCJSqlParserManager(net.sf.jsqlparser.parser.CCJSqlParserManager)

Example 4 with CCJSqlParserManager

use of net.sf.jsqlparser.parser.CCJSqlParserManager in project JSqlParser by JSQLParser.

the class CCJSqlParserManagerTest method testParse.

@Test
public void testParse() throws Exception {
    CCJSqlParserManager parserManager = new CCJSqlParserManager();
    BufferedReader in = new BufferedReader(new InputStreamReader(CreateTableTest.class.getResourceAsStream("/simple_parsing.txt")));
    String statement = "";
    while (true) {
        try {
            statement = CCJSqlParserManagerTest.getStatement(in);
            if (statement == null) {
                break;
            }
            parserManager.parse(new StringReader(statement));
        } catch (JSQLParserException e) {
            throw new TestException("impossible to parse statement: " + statement, e);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) TestException(net.sf.jsqlparser.test.TestException) JSQLParserException(net.sf.jsqlparser.JSQLParserException) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) CCJSqlParserManager(net.sf.jsqlparser.parser.CCJSqlParserManager) CreateTableTest(net.sf.jsqlparser.test.create.CreateTableTest) Test(org.junit.Test)

Aggregations

StringReader (java.io.StringReader)4 CCJSqlParserManager (net.sf.jsqlparser.parser.CCJSqlParserManager)4 Statement (net.sf.jsqlparser.statement.Statement)3 JSQLParserException (net.sf.jsqlparser.JSQLParserException)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)1 Expression (net.sf.jsqlparser.expression.Expression)1 Table (net.sf.jsqlparser.schema.Table)1 Select (net.sf.jsqlparser.statement.select.Select)1 Update (net.sf.jsqlparser.statement.update.Update)1 TestException (net.sf.jsqlparser.test.TestException)1 CreateTableTest (net.sf.jsqlparser.test.create.CreateTableTest)1 Test (org.junit.Test)1