diff options
author | xuri <xuri.me@gmail.com> | 2022-07-03 15:31:24 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2022-07-03 15:31:24 +0800 |
commit | d74adcbb159280be962918125d20ec8ac67a3f93 (patch) | |
tree | a3cd2c37ec175b8400a9d13eef5c7565aaacca05 /calc.go | |
parent | 695db4eae06fdc2a049fc50f61e6a60f83013290 (diff) |
ref #65, new formula function: DGET
Diffstat (limited to 'calc.go')
-rw-r--r-- | calc.go | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -433,6 +433,7 @@ type formulaFuncs struct { // DEGREES // DELTA // DEVSQ +// DGET // DISC // DMAX // DMIN @@ -18173,6 +18174,32 @@ func (fn *formulaFuncs) DCOUNTA(argsList *list.List) formulaArg { return fn.dcount("DCOUNTA", argsList) } +// DGET function returns a single value from a column of a database. The record +// is selected via a set of one or more user-specified criteria. The syntax of +// the function is: +// +// DGET(database,field,criteria) +// +func (fn *formulaFuncs) DGET(argsList *list.List) formulaArg { + if argsList.Len() != 3 { + return newErrorFormulaArg(formulaErrorVALUE, "DGET requires 3 arguments") + } + database := argsList.Front().Value.(formulaArg) + field := argsList.Front().Next().Value.(formulaArg) + criteria := argsList.Back().Value.(formulaArg) + db := newCalcDatabase(database, field, criteria) + if db == nil { + return newErrorFormulaArg(formulaErrorVALUE, formulaErrorVALUE) + } + value := newErrorFormulaArg(formulaErrorVALUE, formulaErrorVALUE) + if db.next() { + if value = db.value(); db.next() { + return newErrorFormulaArg(formulaErrorNUM, formulaErrorNUM) + } + } + return value +} + // DMAX function finds the maximum value in a field (column) in a database for // selected records only. The records to be included in the calculation are // defined by a set of one or more user-specified criteria. The syntax of the |