Package org.h2.command.dml

# Class Insert

java.lang.Object
org.h2.command.Prepared
org.h2.command.dml.DataChangeStatement
org.h2.command.dml.CommandWithValues
org.h2.command.dml.Insert

All Implemented Interfaces:
  `ResultTarget`

public final class Insert extends CommandWithValues implements ResultTarget
This class represents the statement INSERT

## Field Summary

### Fields inherited from class org.h2.command.dml.CommandWithValues

`valuesExpressionList`

### Fields inherited from class org.h2.command.Prepared

`create, parameters, prepareAlways, session, sqlStatement, sqlTokens`

## Constructor Summary

Constructors
Constructor
Description
`Insert(SessionLocal session)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addAssignmentForDuplicate(Column column, Expression expression)`
Keep a collection of the columns to pass to update if a duplicate key happens, for MySQL-style INSERT ...
`void`
`addRow(Value... values)`
Add the row to the result set.
`void`
`collectDependencies(HashSet<DbObject> dependencies)`
Find and collect all DbObjects, this Prepared depends on.
`Value`
`getOnDuplicateKeyValue(int columnIndex)`
Get the value to use for the specified column in case of a duplicate key.
`StringBuilder`
`getPlanSQL(StringBuilder builder, int sqlFlags)`
Appends the SQL statement with the execution plan.
`long`
`getRowCount()`
Get the number of rows.
`String`
`getStatementName()`
Return the name of this statement.
`Table`
`getTable()`
Return the target table.
`int`
`getType()`
Get the command type as defined in CommandInterface
`boolean`
`isCacheable()`
`void`
`limitsWereApplied()`
A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.
`void`
`setColumns(Column[] columns)`
`void`
`setCommand(Command command)`
Set the command.
`void`
`setIgnore(boolean ignore)`
Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.
`void`
`setInsertFromSelect(boolean value)`
`void`
`setOverridingSystem(Boolean overridingSystem)`
`void`
`setQuery(Query query)`
`void`
`setTable(Table table)`
`long`
`update(ResultTarget deltaChangeCollector, DataChangeDeltaTable.ResultOption deltaChangeCollectionMode)`
Execute the statement with specified delta change collector and collection mode.

### Methods inherited from class org.h2.command.dml.CommandWithValues

`addRow`

### Methods inherited from class org.h2.command.dml.DataChangeStatement

`isTransactional, lockAndRecheckCondition, prepare, queryMeta, update`

### Methods inherited from class org.h2.command.Prepared

`checkCanceled, checkParameters, getCurrentRowNumber, getDatabase, getObjectId, getParameters, getPersistedObjectId, getPlanSQL, getSession, getSimpleSQL, getSQL, getSQLTokens, invalidateCachedResult, isQuery, isReadOnly, isRetryable, isWithParamValues, needRecompile, query, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, setWithParamValues, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### Insert

public Insert(SessionLocal session)

## Method Details

### setCommand

public void setCommand(Command command)
Description copied from class: `Prepared`
Set the command.

Overrides:
  `setCommand` in class `Prepared`
Parameters:
  `command` - the new command

### getTable

public Table getTable()
Description copied from class: `DataChangeStatement`
Return the target table.

Specified by:
  `getTable` in class `DataChangeStatement`
Returns:
  the target table

### setTable

public void setTable(Table table)

### setColumns

public void setColumns(Column[] columns)

### setIgnore

public void setIgnore(boolean ignore)
Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.

Parameters:
  `ignore` - ignore duplicates

### setQuery

public void setQuery(Query query)

### setOverridingSystem

public void setOverridingSystem(Boolean overridingSystem)

### addAssignmentForDuplicate

public void addAssignmentForDuplicate(Column column, Expression expression)
Keep a collection of the columns to pass to update if a duplicate key happens, for MySQL-style INSERT ... ON DUPLICATE KEY UPDATE ....

Parameters:
  `column` - the column
  `expression` - the expression

### update

public long update(ResultTarget deltaChangeCollector, DataChangeDeltaTable.ResultOption deltaChangeCollectionMode)
Description copied from class: `DataChangeStatement`
Execute the statement with specified delta change collector and collection mode.

Specified by:
  `update` in class `DataChangeStatement`
Parameters:
  `deltaChangeCollector` - target result
  `deltaChangeCollectionMode` - collection mode
Returns:
  the update count

### addRow

public void addRow(Value... values)
Description copied from interface: `ResultTarget`
Add the row to the result set.

Specified by:
  `addRow` in interface `ResultTarget`
Parameters:
  `values` - the values

### getRowCount

public long getRowCount()
Description copied from interface: `ResultTarget`
Get the number of rows.

Specified by:
  `getRowCount` in interface `ResultTarget`
Returns:
  the number of rows

### limitsWereApplied

public void limitsWereApplied()
Description copied from interface: `ResultTarget`
A hint that sorting, offset and limit may be ignored by this result because they were applied during the query. This is useful for WITH TIES clause because result may contain tied rows above limit.

Specified by:
  `limitsWereApplied` in interface `ResultTarget`

### getPlanSQL

public StringBuilder getPlanSQL(StringBuilder builder, int sqlFlags)
Description copied from class: `Prepared`
Appends the SQL statement with the execution plan.

Overrides:
  `getPlanSQL` in class `Prepared`
Parameters:
  `builder` - string builder
  `sqlFlags` - formatting flags
Returns:
  the execution plan

### getType

public int getType()
Description copied from class: `Prepared`
Get the command type as defined in CommandInterface

Specified by:
  `getType` in class `Prepared`
Returns:
  the statement type

### getStatementName

public String getStatementName()
Description copied from class: `DataChangeStatement`
Return the name of this statement.

Specified by:
  `getStatementName` in class `DataChangeStatement`
Returns:
  the short name of this statement.

### setInsertFromSelect

public void setInsertFromSelect(boolean value)

### isCacheable

public boolean isCacheable()

Overrides:
  `isCacheable` in class `DataChangeStatement`

### getOnDuplicateKeyValue

public Value getOnDuplicateKeyValue(int columnIndex)
Get the value to use for the specified column in case of a duplicate key.

Parameters:
  `columnIndex` - the column index
Returns:
  the value

### collectDependencies

public void collectDependencies(HashSet<DbObject> dependencies)
Description copied from class: `Prepared`
Find and collect all DbObjects, this Prepared depends on.

Overrides:
  `collectDependencies` in class `Prepared`
Parameters:
  `dependencies` - collection of dependencies to populate