MAP-QUERY — Map a function over all the tuples from a query
Function
A sequence type specifier or nil.
A function designator. function must take as many arguments as are attributes in the result set returned by executing the SQL query-expression.
An sql expression that represents an SQL query which is expected to return a (possibly empty) result set, where each tuple has as many attributes as function takes arguments.
A database object. This will default to the value of *default-database*.
A field type specififier. The default is NIL. See query for the semantics of this argument.
If output-type-spec is a type specifier other than nil, then a sequence of the type it denotes. Otherwise nil is returned.
Applies function to the attributes of successive tuples in the result set returned by executing the SQL query-expression. If the output-type-spec is nil, then the result of each application of function is discarded, and map-query returns nil. Otherwise the result of each successive application of function is collected in a sequence of type output-type-spec, where the jths element is the result of applying function to the attributes of the jths tuple in the result set. The collected sequence is the result of the call to map-query.
If the output-type-spec is a subtype of list, the result will be a list.
If the result-type is a subtype of vector, then if the implementation can determine the element type specified for the result-type, the element type of the resulting array is the result of upgrading that element type; or, if the implementation can determine that the element type is unspecified (or *), the element type of the resulting array is t; otherwise, an error is signaled.
(map-query 'list #'(lambda (salary name) (declare (ignorable name)) (read-from-string salary)) "select salary,name from simple where salary > 8000") => (10000.0 8000.5) (map-query '(vector double-float) #'(lambda (salary name) (declare (ignorable name)) (let ((*read-default-float-format* 'double-float)) (coerce (read-from-string salary) 'double-float)) "select salary,name from simple where salary > 8000")) => #(10000.0d0 8000.5d0) (type-of *) => (SIMPLE-ARRAY DOUBLE-FLOAT (2)) (let (list) (values (map-query nil #'(lambda (salary name) (push (cons name (read-from-string salary)) list)) "select salary,name from simple where salary > 8000") list)) => NIL => (("Hacker, Random J." . 8000.5) ("Mai, Pierre" . 10000.0))
If the execution of the SQL query leads to any errors, an error of type clsql-sql-error is signalled.
An error of type type-error must be signaled if the output-type-spec is not a recognizable subtype of list, not a recognizable subtype of vector, and not nil.
An error of type type-error should be signaled if output-type-spec specifies the number of elements and the size of the result set is different from that number.