MCPcopy
hub / github.com/jOOQ/jOOQ / parseInsert

Method parseInsert

jOOQ/src/main/java/org/jooq/impl/ParserImpl.java:2440–2616  ·  view source on GitHub ↗
(WithImpl with, boolean parseResultQuery)

Source from the content-addressed store, hash-verified

2438 }
2439
2440 private final Query parseInsert(WithImpl with, boolean parseResultQuery) {
2441 scope.scopeStart();
2442 parseKeywordUndocumentedAlternatives("INSERT", "INS");
2443 parseKeywordIf("INTO");
2444 Table<?> table = parseTableNameIf();
2445 if (table == null)
2446 table = table(parseSelect());
2447
2448 Name alias;
2449 if (parseKeywordIf("AS"))
2450 table = table.as(parseIdentifier());
2451 else if (!peekKeyword("DEFAULT VALUES", "SEL", "SELECT", "SET", "VALUES")
2452 && (alias = parseIdentifierIf()) != null)
2453 table = table.as(alias);
2454
2455 scope.scope(table);
2456
2457 InsertSetStep<?> s1 = (with == null ? dsl.insertInto(table) : with.insertInto(table));
2458 Field<?>[] fields = null;
2459
2460 if (!peekSelectOrWith(true) && parseIf('(') && !parseIf(')')) {
2461 fields = parseList(',', c -> parseField()).toArray(EMPTY_FIELD);
2462 parse(')');
2463 }
2464
2465 InsertOnDuplicateStep<?> onDuplicate;
2466 InsertReturningStep<?> returning;
2467
2468 try {
2469 // [#11821] The Teradata INSERT INTO t (1, 2) syntax can be recognised:
2470 // When there are non-references fields
2471 boolean hasExpressions = anyMatch(fields, f -> !(f instanceof TableField));
2472
2473 if (hasExpressions || parseKeywordIf("VALUES")) {
2474 List<List<Field<?>>> allValues = new ArrayList<>();
2475
2476 if (hasExpressions) {
2477 allValues.add(asList(fields));
2478 fields = null;
2479 }
2480
2481 valuesLoop:
2482 do {
2483 if (hasExpressions && !parseIf(','))
2484 break valuesLoop;
2485
2486 parse('(');
2487
2488 // [#6936] MySQL treats an empty VALUES() clause as the same thing as the standard DEFAULT VALUES
2489 if (fields == null && parseIf(')'))
2490 break valuesLoop;
2491
2492 List<Field<?>> values = parseList(',', c -> c.parseKeywordIf("DEFAULT") ? default_() : c.parseField());
2493
2494 if (fields != null && fields.length != values.size())
2495 throw exception("Insert field size (" + fields.length + ") must match values size (" + values.size() + ")");
2496
2497 allValues.add(values);

Callers 2

parseQueryMethod · 0.95
parseWithMethod · 0.95

Calls 15

parseKeywordIfMethod · 0.95
parseTableNameIfMethod · 0.95
parseSelectMethod · 0.95
parseIdentifierMethod · 0.95
peekKeywordMethod · 0.95
parseIdentifierIfMethod · 0.95
peekSelectOrWithMethod · 0.95
parseListMethod · 0.95
parseFieldMethod · 0.95
parseMethod · 0.95
parseSetClauseListMethod · 0.95

Tested by

no test coverage detected