public function UnitsEntity::unitsMathematicalExpressionSave in Units of Measurement 7.2
Save the mathematical expression into database.
Parameters
int $mathematical_expression_id: If the ID of the mathematical expression is known, under which it should be saved, provide it here. Otherwise it will be generated automatically
int $order: Order of this member when the mathematical expression is written down in postfix notation. Primarily this argument is used for internal purposes
Return value
int Mathematical expression ID under which this expression has been save in the database
Overrides UnitsMathematicalExpression::unitsMathematicalExpressionSave
File
- includes/
UnitsEntity.class.inc, line 178 - Definition of UnitsEntity class.
Class
- UnitsEntity
- Units of measurement entity class.
Code
public function unitsMathematicalExpressionSave($mathematical_expression_id, &$order) {
if (!$mathematical_expression_id) {
// TODO: this should be possible to do as: INSERT INTO ... FROM SELECT ... thereby making unnecessary the transaction.
// See https://www.drupal.org/node/310079 for more details.
$transaction = db_transaction();
$select = db_select('units_mathematical_expression_postfix', 'e');
$select
->addExpression('MAX(e.mathematical_expression_id) + 1', 'mathematical_expression_id');
$mathematical_expression_id = $select
->execute()
->fetchField();
if (!$mathematical_expression_id) {
$mathematical_expression_id = 1;
}
}
db_insert('units_mathematical_expression_postfix')
->fields(array(
'type' => UNITS_TOKEN_TYPE_UNIT,
'mathematical_expression_id' => $mathematical_expression_id,
'value_string' => $this
->identifier(),
'postfix_order' => ++$order,
))
->execute();
return $mathematical_expression_id;
}