Queries a database and returns a list of values.
sql
query sql-exp &key database result-types flatp => result-list, field-names
sql-exp⇩ |
A SQL query statement or a prepared-statement containing a query. |
database⇩ |
A database. |
result-types⇩ |
A list of symbols. |
flatp⇩ |
A boolean. |
result-list⇩ |
A list of values. |
field-names⇩ |
A list of strings. |
The function query
is the basic SQL query function. It queries the database specified by database with a SQL query statement given by sql-exp.
The argument database defaults to *default-database*.
result-types is a list of symbols such as :string
and :integer
, one for each field in the query, which are used to specify the types to return. It is ignored if sql-exp is a prepared-statement.
flatp is used as in select and is ignored if sql-exp is a prepared-statement.
result-list is a list of values as per select, and field-names is a list of field names selected in sql-exp.
The following two queries, on a table whose second column contains dates that we want to return as strings, are equivalent:
(sql:query "select * from some_table" :result-types '(nil :string)) (sql:query [select [*] :from [some_table] :result-types '(nil :string)])
do-query
execute-command
lob-stream
Loop Extensions in Common SQL
map-query
prepare-statement
select
simple-do-query
LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:56