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
This class represents the statement
INSERT
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Column[]
private ResultTarget
private HashMap
<Column, Expression> For MySQL-style INSERT ...private boolean
For MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING.private boolean
private Value[]
private Boolean
private Query
private long
private Table
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Add the row to the result set.void
collectDependencies
(HashSet<DbObject> dependencies) Find and collect all DbObjects, this Prepared depends on.getOnDuplicateKeyValue
(int columnIndex) Get the value to use for the specified column in case of a duplicate key.getPlanSQL
(int sqlFlags) Get the SQL statement with the execution plan.long
Get the number of rows.Return the name of this statement.getTable()
Return the target table.int
getType()
Get the command type as defined in CommandInterfaceprivate boolean
handleOnDuplicate
(DbException de, Value[] currentRow) private long
boolean
void
A hint that sorting, offset and limit may be ignored by this result because they were applied during the query.void
prepare()
Prepare this statement.private Expression
prepareUpdateCondition
(Index foundIndex, Expression[] row) 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
void
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, queryMeta, update
Methods inherited from class org.h2.command.Prepared
checkCanceled, checkParameters, getCteCleanups, getCurrentRowNumber, getObjectId, getParameters, getPersistedObjectId, getSession, getSimpleSQL, getSQL, getSQLTokens, isQuery, isReadOnly, needRecompile, query, setCteCleanups, setCurrentRowNumber, setParameterList, setPersistedObjectId, setPrepareAlways, setRow, setSession, setSQL, toString
-
Field Details
-
table
-
columns
-
query
-
rowNumber
private long rowNumber -
insertFromSelect
private boolean insertFromSelect -
overridingSystem
-
duplicateKeyAssignmentMap
For MySQL-style INSERT ... ON DUPLICATE KEY UPDATE .... -
onDuplicateKeyRow
-
ignore
private boolean ignoreFor MySQL-style INSERT IGNORE and PostgreSQL-style ON CONFLICT DO NOTHING. -
deltaChangeCollector
-
deltaChangeCollectionMode
-
-
Constructor Details
-
Insert
-
-
Method Details
-
setCommand
Description copied from class:Prepared
Set the command.- Overrides:
setCommand
in classPrepared
- Parameters:
command
- the new command
-
getTable
Description copied from class:DataChangeStatement
Return the target table.- Specified by:
getTable
in classDataChangeStatement
- Returns:
- the target table
-
setTable
-
setColumns
-
setIgnore
public void setIgnore(boolean ignore) Sets MySQL-style INSERT IGNORE mode or PostgreSQL-style ON CONFLICT DO NOTHING.- Parameters:
ignore
- ignore duplicates
-
setQuery
-
setOverridingSystem
-
addAssignmentForDuplicate
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 columnexpression
- 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 classDataChangeStatement
- Parameters:
deltaChangeCollector
- target resultdeltaChangeCollectionMode
- collection mode- Returns:
- the update count
-
insertRows
private long insertRows() -
addRow
Description copied from interface:ResultTarget
Add the row to the result set.- Specified by:
addRow
in interfaceResultTarget
- Parameters:
values
- the values
-
getRowCount
public long getRowCount()Description copied from interface:ResultTarget
Get the number of rows.- Specified by:
getRowCount
in interfaceResultTarget
- 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 interfaceResultTarget
-
getPlanSQL
Description copied from class:Prepared
Get the SQL statement with the execution plan.- Overrides:
getPlanSQL
in classPrepared
- Parameters:
sqlFlags
- formatting flags- Returns:
- the execution plan
-
prepare
public void prepare()Description copied from class:Prepared
Prepare this statement. -
getType
public int getType()Description copied from class:Prepared
Get the command type as defined in CommandInterface -
getStatementName
Description copied from class:DataChangeStatement
Return the name of this statement.- Specified by:
getStatementName
in classDataChangeStatement
- Returns:
- the short name of this statement.
-
setInsertFromSelect
public void setInsertFromSelect(boolean value) -
isCacheable
public boolean isCacheable()- Overrides:
isCacheable
in classDataChangeStatement
-
handleOnDuplicate
- Parameters:
de
- duplicate key exceptioncurrentRow
- current row values (optional)- Returns:
true
if row was updated,false
if row was ignored
-
prepareUpdateCondition
-
getOnDuplicateKeyValue
Get the value to use for the specified column in case of a duplicate key.- Parameters:
columnIndex
- the column index- Returns:
- the value
-
collectDependencies
Description copied from class:Prepared
Find and collect all DbObjects, this Prepared depends on.- Overrides:
collectDependencies
in classPrepared
- Parameters:
dependencies
- collection of dependencies to populate
-