-
Notifications
You must be signed in to change notification settings - Fork 767
Add documentation on OQL INSERT statement #10496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
basdebakker
wants to merge
2
commits into
mendix:development
Choose a base branch
from
basdebakker:oql-insert-attributes
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ From Mendix version 11.3, you can also update object attributes in bulk using OQ | |
|
|
||
| From Mendix version 11.4, you can update object associations as well as attributes in bulk using OQL `UPDATE` statements. | ||
|
|
||
| From Mendix version 11.6, you can insert new objects with attributes in bulk using OQL `INSERT` statements. | ||
|
|
||
| {{% /alert %}} | ||
|
|
||
| ## Java API for OQL updates | ||
|
|
@@ -45,13 +47,18 @@ The `execute()` method returns the number of objects that were affected by the s | |
|
|
||
| ## `DELETE` Statement {#oql-delete} | ||
|
|
||
| {{% alert color="info" %}} | ||
| Available from Mendix version 11.1.0 | ||
| {{% /alert %}} | ||
|
|
||
| The syntax of `DELETE` statements is: | ||
|
|
||
| ```sql | ||
| DELETE FROM <entity> WHERE <condition> | ||
| ``` | ||
|
|
||
| `condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where). | ||
| * `entity` is the entity whose objects are being deleted. | ||
| * `condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where). | ||
|
|
||
| ### OQL `DELETE` Limitations | ||
|
|
||
|
|
@@ -61,21 +68,39 @@ DELETE FROM <entity> WHERE <condition> | |
|
|
||
| ## `UPDATE` Statement {#oql-update} | ||
|
|
||
| {{% alert color="info" %}} | ||
| Available from Mendix version 11.3.0 | ||
| {{% /alert %}} | ||
|
|
||
| The syntax of `UPDATE` statements is: | ||
|
|
||
| ```sql | ||
| UPDATE <entity> | ||
| SET { { <attribute> | <association> } = <expression> } [ ,...n ] | ||
| SET { { <attribute> | <association> } = <expression> } [ , …n ] | ||
| WHERE <condition> | ||
| ``` | ||
|
|
||
| `entity` is the entity whose objects are being updated. | ||
| * `entity` is the entity whose objects are being updated. | ||
|
|
||
| * `attribute` is an attribute of the entity that is being updated. | ||
|
|
||
| An attribute of type `autonumber` can not be updated. The `ID` attribute of an entity cannot be updated. | ||
|
|
||
| * `association` is an association that is being updated. Associations can be updated in Mendix version 11.4.0 and above. | ||
|
|
||
| Multiple attributes and associations can be updated in the same statement. | ||
|
|
||
| `attribute` is an attribute of the entity that is being updated. `association` is an association that is being updated. Multiple attributes and associations can be updated in the same statement. An attribute of type `autonumber` can not be updated. The `ID` field of an entity cannot be updated. | ||
| * `expression` is a new value of an attribute or association. Any [OQL expression](/refguide/oql-expressions/) is allowed. | ||
|
|
||
| `expression` is a new value of an attribute or association. Any [OQL expression](/refguide/oql-expressions/) is allowed. When updating attributes, the value type of the expression should match the attribute type according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). When updating an enumeration attribute using a literal, the literal must be a valid value for the enumeration. When updating an enumeration attribute using another enumeration, the expression enumeration must be a subset of the attribute enumeration. When updating a string attribute using a string literal, the literal length must be equal to or less than the length of the attribute. In the case of associations, association and entity expressions must match the target association type. Values of type LONG can also be used as association values, but they must be valid ids of associations which are of the target association type. | ||
| * When updating attributes, the value type of the expression should match the attribute type according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion). | ||
| * When updating an enumeration attribute using a literal, the literal must be a valid value for the enumeration. | ||
| * When updating an enumeration attribute using another enumeration, the expression enumeration must be a subset of the attribute enumeration. | ||
| * When updating a string attribute using a string literal, the literal length must be equal to or less than the length of the attribute. | ||
| * In the case of associations, association and entity expressions must match the target association type. | ||
|
|
||
| Values of type LONG can also be used as association values, but they must be valid ids of associations which are of the target association type. | ||
|
|
||
| `condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where). | ||
| * `condition` can be anything that can appear in an OQL [WHERE clause](/refguide/oql-clauses/#where). | ||
|
|
||
| Example: | ||
|
|
||
|
|
@@ -139,7 +164,48 @@ SET | |
| SpecializationAttribute = 1 | ||
| ``` | ||
|
|
||
| ## Joins | ||
| ## `INSERT` Statement {#oql-insert} | ||
|
|
||
| {{% alert color="info" %}} | ||
| Available from Mendix version 11.6.0 | ||
| {{% /alert %}} | ||
|
|
||
| The syntax of `INSERT` statements is: | ||
|
|
||
| ```sql | ||
| INSERT INTO <entity> ( <attribute> [ , …n ] ) <oql-query> | ||
| ``` | ||
|
|
||
| * `entity` is the entity for which new objects will be created. | ||
|
|
||
| * `attribute` is an attribute of the entity that will be inserted. | ||
|
|
||
| * `oql-query` is any OQL query that returns same number of columns as the number of attributes that will be inserted. | ||
| This query can select data from persistable entities and/or [view entities](/refguide/view-entities/). | ||
|
|
||
| Example: | ||
|
|
||
| ```sql | ||
| INSERT INTO Module.Order ( OrderNumber, CustomerNumber ) | ||
| SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number FROM Loader.TemporaryData | ||
| ``` | ||
|
|
||
| ### OQL `INSERT` Limitations | ||
|
|
||
| * It is not yet possible to insert associations. As a workaround, they can be added after the `INSERT` using an OQL `UPDATE` statement. | ||
| * Attributes of type "Date and time" with a default value of `'[%CurrentDateTime%]'` will not have their default values set when the `INSERT` statement does not specify them. | ||
| As a workaround, explicitly insert the attribute with a value of `'[%CurrentDatetime%]'` in the `SELECT` part. | ||
| * When using Oracle, due to database limitations, inserting attributes of type unlimited string or binary is not supported. | ||
| * The general limitations for OQL statements also apply. See [General Limitations for OQL Statements](#oql-limitations), below. | ||
|
|
||
| ## General Limitations for OQL Statements {#oql-limitations} | ||
|
|
||
| * OQL statements can be used only with persistable entities. | ||
| * Entity access rules are not applied to any OQL statements. | ||
| * No event handlers will be executed. | ||
| * Runtime and client state will not be updated with the changes. | ||
|
|
||
| ### Joins | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've moved this to the General Limitations section as it felt odd in between UPDATE and INSERT |
||
|
|
||
| You cannot directly join other entities in the `FROM` clause of OQL `DELETE` or in the `UPDATE` clause of OQL `UPDATE`. However, you can achieve the same result using long paths or subqueries. For example: | ||
|
|
||
|
|
@@ -160,9 +226,4 @@ WHERE ID IN ( | |
| WHERE Module.Customer/Name = 'Mary' ) | ||
| ``` | ||
|
|
||
| ## General Limitations for OQL Statements {#oql-limitations} | ||
|
|
||
| * OQL statements can be used only with persistable entities. | ||
| * Entity access rules are not applied to any OQL statements. | ||
| * No event handlers will be executed. | ||
| * Runtime and client state will not be updated with the changes. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.