On this page:
1.2.1 Basic Queries
query*
query
query0
1.2.2 Query Results
query-result?
1.2.2.1 Result Sets
result-set?
result-set-rows
result-set-field-names
in-result-set
in-result-set/ hash
1.2.2.2 Side Effects
side-effect?
side-effect-affected-rows
side-effect-insert-id
side-effect-warning-count
side-effect-message

1.2 Basic Queries and Query Results

1.2.1 Basic Queries

(query* [#:connection con] sql)  (listof query-result?)
  con : connection? = (current-connection)
  sql : string?
(query [#:connection con] sql)  query-result?
  con : connection? = (current-connection)
  sql : string?
(query0 [#:connection con] sql)  query-result?
  con : connection? = (current-connection)
  sql : string?
Queries the database and returns the query results.

Since a single SQL string may contain multiple SQL statements (delimited by semicolons), query* is the most general of the above procedures, as it will return one query-result for each SQL statement in the sql argument.

query returns only the query-result corresponding to the last SQL statement in sql, whereas query0 returns only the query-result corresponding to the first SQL statement in sql.

1.2.2 Query Results

A basic SQL query will return a value that satisfies query-result? (or a list of such values, if the query* procedure is used). Any such value will additionally satisfy either result-set? or side-effect?.

(query-result? x)  boolean?
  x : any
Returns #t if x represents the results of an SQL statement, #f otherwise.

1.2.2.1 Result Sets

(result-set? x)  boolean?
  x : any
Returns #t if x represents the results of an SQL statement that returns row data, #f otherwise.

(result-set-rows rs)  (listof (vectorof any))
  rs : result-set?
Returns a list of rows, each of which is a vector.

(result-set-field-names rs)  (vectorof string?)
  rs : result-set?
Returns a vector containing the names of the result set’s fields, in order.

(in-result-set rs)  (sequence?)
  rs : result-set?
Returns a sequence of rows, each of which is a vector.

(in-result-set/hash rs)  (sequence?)
  rs : result-set?
Returns a sequence of rows, each of which is a hash table. The hash table’s keys are symbols representing the names of the result set’s fields, and the values are the row data.

1.2.2.2 Side Effects

(side-effect? x)  boolean?
  x : any
Returns #t if x represents the results of an SQL statement that is evaluated for its side effects (e.g., an UPDATE or INSERT statement), #f otherwise.

(side-effect-affected-rows eff)  exact-nonnegative-integer?
  eff : side-effect?
Returns the number of rows that were modified by the query that produced eff.

(side-effect-insert-id eff)  (or/c exact-positive-integer? #f)
  eff : side-effect?
Returns the primary key that was automatically generated by the INSERT query that produced eff or #f if no such key was generated.

(side-effect-warning-count eff)  exact-nonnegative-integer?
  eff : side-effect?
Returns the number of warnings generated by the query that produced eff.

(side-effect-message eff)  (or/c string? #f)
  eff : side-effect?
Returns a status message generated by the query that produced eff or #f if no message was generated.