public function UnitsConstantMathematicalExpression::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
- ./
units.module, line 1872 - Provide API for managing and converting units of measurement.
Class
- UnitsConstantMathematicalExpression
- Implementation of "mathematical expression" interface for a constant.
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_CONSTANT,
'mathematical_expression_id' => $mathematical_expression_id,
$this->constant == UNITS_QUANTITY ? 'value_string' : 'value_numeric' => $this->constant,
'postfix_order' => ++$order,
))
->execute();
return $mathematical_expression_id;
}