Examples of Insert


Examples of org.teiid.query.sql.lang.Insert

    @Test public void testFailsIllegalOption(){
        TestParser.helpException("SELECT a from g OPTION xyx");         //$NON-NLS-1$
    }
   
    @Test public void testInsertWithOption() {
        Insert insert = new Insert();
        insert.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
        List vars = new ArrayList();
        vars.add(new ElementSymbol("a"));         //$NON-NLS-1$
        insert.setVariables(vars);
        List values = new ArrayList();
        values.add(new Reference(0));
        insert.setValues(values);
        Option option = new Option();
        option.setNoCache(true);      
        insert.setOption(option);
        TestParser.helpTest("INSERT INTO m.g (a) VALUES (?) OPTION NOCACHE"//$NON-NLS-1$
                 "INSERT INTO m.g (a) VALUES (?) OPTION NOCACHE"//$NON-NLS-1$
                 insert);                    
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

    @Test public void testInsertIntoSelect() {
        GroupSymbol g = new GroupSymbol("sys.groups"); //$NON-NLS-1$
        From from = new From();
        from.addGroup(g);

        Insert insert = new Insert();
        GroupSymbol groupSymbol = new GroupSymbol( "tempA" );   //$NON-NLS-1$
        insert.setGroup(groupSymbol);
       
        Select select = new Select();
//        select.addSymbol( new ExpressionSymbol( new Constant( new Integer(1) ) ) );
        select.addSymbolnew ExpressionSymbol( "exp", new Constant( new Integer(1) ) ) );    //$NON-NLS-1$

        Query query = new Query();
        query.setSelect(select);
       
        insert.setQueryExpression( query );       

        helpTest("insert into tempA SELECT 1"//$NON-NLS-1$
                 "INSERT INTO tempA SELECT 1"//$NON-NLS-1$
                 insert);
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

    helpException("SELECT a, b FROM (SELECT c FROM m.g2)"); //$NON-NLS-1$
  }
       
    /** INSERT INTO m.g (a) VALUES (?) */
    @Test public void testInsertWithReference() {
        Insert insert = new Insert();
        insert.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
        List vars = new ArrayList();
        vars.add(new ElementSymbol("a"));         //$NON-NLS-1$
        insert.setVariables(vars);
        List values = new ArrayList();
        values.add(new Reference(0));
        insert.setValues(values);
        helpTest("INSERT INTO m.g (a) VALUES (?)"//$NON-NLS-1$
                 "INSERT INTO m.g (a) VALUES (?)"//$NON-NLS-1$
                 insert);                    
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

        From from = new From();
        from.addGroup(g);

        ElementSymbol e =  new ElementSymbol("foo"); //$NON-NLS-1$

        Insert query = new Insert(g, new ArrayList(), new ArrayList());
        query.addVariable(e);
        query.addValue(new Constant("bar", String.class)); //$NON-NLS-1$
       
        helpTest("insert into x (\"foo\") values ('bar')"//$NON-NLS-1$
                 "INSERT INTO x (foo) VALUES ('bar')"//$NON-NLS-1$
                 query);               
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

       
        helpTest("select convert(null, blob), convert(null, clob), convert(null, xml)", "SELECT convert(null, blob), convert(null, clob), convert(null, xml)", query); //$NON-NLS-1$ //$NON-NLS-2$
    }

    @Test public void testInsertWithoutColumns() {
        Insert insert = new Insert();
        insert.setGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
        insert.addValue(new Constant("a")); //$NON-NLS-1$
        insert.addValue(new Constant("b")); //$NON-NLS-1$
        helpTest("INSERT INTO m.g VALUES ('a', 'b')"//$NON-NLS-1$
                 "INSERT INTO m.g VALUES ('a', 'b')"//$NON-NLS-1$
                 insert);
    }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

           
            int batchSize = 1;
           
            // ensure that we have the right kind of insert, and that the data for this row is valid
            if (command instanceof Insert) {
              Insert insert = (Insert)command;
              if (insert.isBulk()) {
                    List batch = getBulkRows(insert, insert.getVariables());
                    batchSize = batch.size();
                    assertEquals("Unexpected batch on call " + callCount, expectedBatchSize, batchSize); //$NON-NLS-1$
                   
                    for (int i = 0; i < batchSize; i++) {
                        ensureValue2((List)batch.get(i), 2, ((callCount-1) * batchSize) + i + 1);
                    }
              } else if (insert.getTupleSource() != null) {
                TupleSource ts = insert.getTupleSource();
                List tuple = null;
                int i = 0;
                while ((tuple = ts.nextTuple()) != null) {
                    ensureValue2(tuple, 2, ++i);
                }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

                return null;
              }
            }
      }
    } if (command instanceof Insert) {
      Insert obj = (Insert)command;
      for (int i = 0; i < obj.getVariables().size(); i++) {
        ElementSymbol elem = obj.getVariables().get(i);
            Object metadataID = elem.getMetadataID();           
            if(metadataID instanceof MultiSourceElement) {
              Constant source = (Constant)obj.getValues().get(i);
            obj.getVariables().remove(i);
            obj.getValues().remove(i);
              if (!source.getValue().equals(sourceName)) {
                return null;
              }
            }
      }
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

            return null;
          }
          final String groupKey = group.getNonCorrelationName().toUpperCase();
            final TempTable table = contextStore.getOrCreateTempTable(groupKey, command, bufferManager, false);
          if (command instanceof Insert) {
            Insert insert = (Insert)command;
            TupleSource ts = insert.getTupleSource();
            if (ts == null) {
              List<Object> values = new ArrayList<Object>(insert.getValues().size());
              for (Expression expr : (List<Expression>)insert.getValues()) {
                values.add(Evaluator.evaluate(expr));
          }
              ts = new CollectionTupleSource(Arrays.asList(values).iterator());
            }
            return table.insert(ts, insert.getVariables());
          }
          if (command instanceof Update) {
            final Update update = (Update)command;
            final Criteria crit = update.getCriteria();
            return table.update(crit, update.getChangeList());
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

   
    QueryCommand query = null;
    Map<ElementSymbol, Expression> params = new HashMap<ElementSymbol, Expression>();
   
    if (userCommand instanceof Insert) {
      Insert insert = (Insert)userCommand;
      if (insert.getQueryExpression() != null) {
        query = insert.getQueryExpression();
      } else {
        query = new Query();
        ((Query)query).setSelect(new Select(RuleChooseJoinStrategy.createExpressionSymbols(insert.getValues())));
      }
    } else if (userCommand instanceof Delete) {
      query = createOldQuery(userCommand, ta, metadata, params);
    } else if (userCommand instanceof Update) {
      query = createOldQuery(userCommand, ta, metadata, params);
View Full Code Here

Examples of org.teiid.query.sql.lang.Insert

          }
        }
        //allow implicit temp group definition
        List<ElementSymbol> columns = null;
        if (command instanceof Insert) {
            Insert insert = (Insert)command;
            GroupSymbol group = insert.getGroup();
            if(group.isImplicitTempGroupSymbol()) {
                columns = insert.getVariables();
            }
        }
        if (columns == null) {
          throw new QueryProcessingException(QueryPlugin.Util.getString("TempTableStore.table_doesnt_exist_error", tempTableID)); //$NON-NLS-1$
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.