From a91e6f64520e6564545fc1c5c6c7664165cd3ffd Mon Sep 17 00:00:00 2001 From: Ryan Culpepper Date: Fri, 26 Aug 2011 04:32:22 -0600 Subject: [PATCH] db: "recordset" -> "rows-result", "rows" --- collects/db/private/generic/functions.rkt | 54 +++++++++---------- collects/db/private/generic/interfaces.rkt | 8 +-- collects/db/private/generic/main.rkt | 2 +- collects/db/private/generic/prepared.rkt | 8 +-- collects/db/private/mysql/connection.rkt | 10 ++-- collects/db/private/odbc/connection.rkt | 6 +-- collects/db/private/postgresql/connection.rkt | 6 +-- collects/db/private/sqlite3/connection.rkt | 2 +- collects/db/scribblings/introduction.scrbl | 12 ++--- collects/db/scribblings/query.scrbl | 40 +++++++------- collects/tests/db/db/query.rkt | 4 +- 11 files changed, 76 insertions(+), 76 deletions(-) diff --git a/collects/db/private/generic/functions.rkt b/collects/db/private/generic/functions.rkt index 03a4ba50ba..50514edbef 100644 --- a/collects/db/private/generic/functions.rkt +++ b/collects/db/private/generic/functions.rkt @@ -84,19 +84,19 @@ (define (query1 c fsym stmt) (send c query fsym stmt)) -;; query/recordset : connection symbol Statement nat/#f -> void -(define (query/recordset c fsym sql want-columns) +;; query/rows : connection symbol Statement nat/#f -> void +(define (query/rows c fsym sql want-columns) (let [(result (query1 c fsym sql))] - (unless (recordset? result) - (uerror fsym "query did not return recordset: ~e" sql)) - (let ([got-columns (length (recordset-headers result))]) + (unless (rows-result? result) + (uerror fsym "query did not return rows: ~e" sql)) + (let ([got-columns (length (rows-result-headers result))]) (when (and want-columns (not (= got-columns want-columns))) (uerror fsym "query returned ~a ~a (expected ~a): ~e" got-columns (if (= got-columns 1) "column" "columns") want-columns sql))) result)) -(define (recordset->row fsym rs sql maybe-row? one-column?) - (define rows (recordset-rows rs)) +(define (rows-result->row fsym rs sql maybe-row? one-column?) + (define rows (rows-result-rows rs)) (cond [(null? rows) (cond [maybe-row? #f] [else (uerror fsym "query returned zero rows (expected 1): ~e" sql)])] @@ -136,46 +136,46 @@ ;; query-rows : connection Statement arg ... -> (listof (vectorof 'a)) (define (query-rows c sql . args) - (let ([sql (compose-statement 'query-rows c sql args 'recordset)]) - (recordset-rows (query/recordset c 'query-rows sql #f)))) + (let ([sql (compose-statement 'query-rows c sql args 'rows)]) + (rows-result-rows (query/rows c 'query-rows sql #f)))) ;; query-list : connection Statement arg ... -> (listof 'a) -;; Expects to get back a recordset with one field per row. +;; Expects to get back a rows-result with one field per row. (define (query-list c sql . args) (let ([sql (compose-statement 'query-list c sql args 1)]) (map (lambda (v) (vector-ref v 0)) - (recordset-rows (query/recordset c 'query-list sql 1))))) + (rows-result-rows (query/rows c 'query-list sql 1))))) ;; query-row : connection Statement arg ... -> (vector-of 'a) -;; Expects to get back a recordset of zero or one rows. +;; Expects to get back a rows-result of zero or one rows. (define (query-row c sql . args) - (let ([sql (compose-statement 'query-row c sql args 'recordset)]) - (recordset->row 'query-row - (query/recordset c 'query-row sql #f) + (let ([sql (compose-statement 'query-row c sql args 'rows)]) + (rows-result->row 'query-row + (query/rows c 'query-row sql #f) sql #f #f))) ;; query-maybe-row : connection Statement arg ... -> (vector-of 'a) or #f -;; Expects to get back a recordset of zero or one rows. +;; Expects to get back a rows-result of zero or one rows. (define (query-maybe-row c sql . args) - (let ([sql (compose-statement 'query-maybe-row c sql args 'recordset)]) - (recordset->row 'query-maybe-row - (query/recordset c 'query-maybe-row sql #f) + (let ([sql (compose-statement 'query-maybe-row c sql args 'rows)]) + (rows-result->row 'query-maybe-row + (query/rows c 'query-maybe-row sql #f) sql #t #f))) ;; query-value : connection string arg ... -> value | raises error -;; Expects to get back a recordset of exactly one row, exactly one column. +;; Expects to get back a rows-result of exactly one row, exactly one column. (define (query-value c sql . args) (let ([sql (compose-statement 'query-value c sql args 1)]) - (recordset->row 'query-value - (query/recordset c 'query-value sql 1) + (rows-result->row 'query-value + (query/rows c 'query-value sql 1) sql #f #t))) ;; query-maybe-value : connection Statement arg ... -> value/#f -;; Expects to get back a recordset of zero or one rows, exactly one column. +;; Expects to get back a rows-result of zero or one rows, exactly one column. (define (query-maybe-value c sql . args) (let ([sql (compose-statement 'query-maybe-value c sql args 1)]) - (recordset->row 'query-maybe-value - (query/recordset c 'query-maybe-value sql 1) + (rows-result->row 'query-maybe-value + (query/rows c 'query-maybe-value sql 1) sql #t #t))) ;; query-exec : connection Statement arg ... -> void @@ -224,9 +224,9 @@ (apply raise-type-error 'in-query "connection" 0 c stmt args)) (unless (statement? stmt) (apply raise-type-error 'in-query "statement" 1 c stmt args)) - (let* ([check (or vars 'recordset)] + (let* ([check (or vars 'rows)] [stmt (compose-statement 'in-query c stmt args check)]) - (recordset-rows (query/recordset c 'in-query stmt vars)))) + (rows-result-rows (query/rows c 'in-query stmt vars)))) ;; ======================================== diff --git a/collects/db/private/generic/interfaces.rkt b/collects/db/private/generic/interfaces.rkt index 249be38965..0fb17ebc46 100644 --- a/collects/db/private/generic/interfaces.rkt +++ b/collects/db/private/generic/interfaces.rkt @@ -5,7 +5,7 @@ prepared-statement<%> (struct-out simple-result) - (struct-out recordset) + (struct-out rows-result) (struct-out statement-binding) @@ -122,10 +122,10 @@ ;; An query-result is one of: ;; - (simple-result alist) -;; - (recordset Header data) -;; for user-visible recordsets: headers present, data is (listof vector) +;; - (rows-result Header data) +;; for user-visible rows-results: headers present, data is (listof vector) (struct simple-result (info) #:transparent) -(struct recordset (headers rows) #:transparent) +(struct rows-result (headers rows) #:transparent) ;; A Header is (listof FieldInfo) ;; A FieldInfo is an alist, contents dbsys-dependent diff --git a/collects/db/private/generic/main.rkt b/collects/db/private/generic/main.rkt index 82d6d1fe4f..2c93420e15 100644 --- a/collects/db/private/generic/main.rkt +++ b/collects/db/private/generic/main.rkt @@ -3,7 +3,7 @@ "sql-data.rkt" "functions.rkt") (provide (struct-out simple-result) - (struct-out recordset) + (struct-out rows-result) statement-binding? (except-out (all-from-out "sql-data.rkt") make-sql-bits/bytes diff --git a/collects/db/private/generic/prepared.rkt b/collects/db/private/generic/prepared.rkt index 4e48095d9a..e5b6506051 100644 --- a/collects/db/private/generic/prepared.rkt +++ b/collects/db/private/generic/prepared.rkt @@ -39,17 +39,17 @@ (define/public (get-result-types) (send dbsystem describe-typeids result-typeids)) - ;; checktype is either #f, 'recordset, or exact-positive-integer + ;; checktype is either #f, 'rows, or exact-positive-integer (define/public (check-results fsym checktype obj) - (cond [(eq? checktype 'recordset) + (cond [(eq? checktype 'rows) (unless (positive? (get-result-count)) (when close-on-exec? (finalize)) - (error fsym "expected statement producing recordset, got ~e" obj))] + (error fsym "expected statement producing rows, got ~e" obj))] [(exact-positive-integer? checktype) (unless (= (get-result-count) checktype) (when close-on-exec? (finalize)) (error fsym - "expected statement producing recordset with ~a ~a, got ~e" + "expected statement producing rows with ~a ~a, got ~e" checktype (if (= checktype 1) "column" "columns") obj))] diff --git a/collects/db/private/mysql/connection.rkt b/collects/db/private/mysql/connection.rkt index b3e84b4b41..a1fa843c93 100644 --- a/collects/db/private/mysql/connection.rkt +++ b/collects/db/private/mysql/connection.rkt @@ -293,7 +293,7 @@ [(struct result-set-header-packet (fields extra)) (let* ([field-dvecs (query1:get-fields fsym binary?)] [rows (query1:get-rows fsym field-dvecs binary? wbox)]) - (vector 'recordset field-dvecs rows))]))) + (vector 'rows field-dvecs rows))]))) (define/private (query1:get-fields fsym binary?) (let ([r (recv fsym 'field)]) @@ -317,8 +317,8 @@ (define/private (query1:process-result fsym result) (match result - [(vector 'recordset field-dvecs rows) - (recordset (map field-dvec->field-info field-dvecs) rows)] + [(vector 'rows field-dvecs rows) + (rows-result (map field-dvec->field-info field-dvecs) rows)] [(vector 'command command-info) (simple-result command-info)])) @@ -377,7 +377,7 @@ [i (in-naturals)]) (and (equal? (field-dvec->name dvec) name) i))) (match result - [(vector 'recordset field-dvecs rows) + [(vector 'rows field-dvecs rows) (let ([code-index (find-index "Code" field-dvecs)] [message-index (find-index "Message" field-dvecs)]) (for ([row (in-list rows)]) @@ -506,7 +506,7 @@ According to that page, the following statements may be prepared: CALL, CREATE TABLE, DELETE, DO, INSERT, REPLACE, SELECT, SET, UPDATE, and most SHOW statements -On the other hand, we want to force all recordset-returning statements +On the other hand, we want to force all rows-returning statements through the prepared-statement path to use the binary data protocol. That would seem to be the following: diff --git a/collects/db/private/odbc/connection.rkt b/collects/db/private/odbc/connection.rkt index d5dc04c391..4b2a1af94d 100644 --- a/collects/db/private/odbc/connection.rkt +++ b/collects/db/private/odbc/connection.rkt @@ -54,7 +54,7 @@ (check-valid-tx-status fsym) (query1 fsym stmt)))]) (statement:after-exec stmt*) - (cond [(pair? dvecs) (recordset (map field-dvec->field-info dvecs) rows)] + (cond [(pair? dvecs) (rows-result (map field-dvec->field-info dvecs) rows)] [else (simple-result '())]))) (define/private (query1 fsym stmt) @@ -534,8 +534,8 @@ (handle-status fsym (SQLFreeHandle SQL_HANDLE_STMT stmt) stmt) (values result-dvecs rows))))) ;; Layout is: #(catalog schema table table-type remark) - (recordset (map field-dvec->field-info dvecs) - rows)) + (rows-result (map field-dvec->field-info dvecs) + rows)) |# ;; Handler diff --git a/collects/db/private/postgresql/connection.rkt b/collects/db/private/postgresql/connection.rkt index 4a43eaca45..9f036fff11 100644 --- a/collects/db/private/postgresql/connection.rkt +++ b/collects/db/private/postgresql/connection.rkt @@ -283,7 +283,7 @@ [(struct RowDescription (field-dvecs)) (let* ([rows (query1:data-loop fsym)]) (query1:expect-close-complete fsym) - (vector 'recordset field-dvecs rows))] + (vector 'rows field-dvecs rows))] [(struct NoData ()) (let* ([command (query1:expect-completion fsym)]) (query1:expect-close-complete fsym) @@ -318,7 +318,7 @@ (define/private (query1:process-result fsym result) (match result - [(vector 'recordset field-dvecs rows) + [(vector 'rows field-dvecs rows) (let* ([type-reader-v (list->vector (query1:get-type-readers fsym field-dvecs))] [convert-row! @@ -329,7 +329,7 @@ row type-reader-v))]) (for-each convert-row! rows) - (recordset (map field-dvec->field-info field-dvecs) rows))] + (rows-result (map field-dvec->field-info field-dvecs) rows))] [(vector 'command command) (simple-result command)])) diff --git a/collects/db/private/sqlite3/connection.rkt b/collects/db/private/sqlite3/connection.rkt index ca1969a6ca..d2a72db847 100644 --- a/collects/db/private/sqlite3/connection.rkt +++ b/collects/db/private/sqlite3/connection.rkt @@ -42,7 +42,7 @@ (check-valid-tx-status fsym) (query1 fsym stmt)))]) (statement:after-exec stmt) - (cond [(pair? info) (recordset info rows)] + (cond [(pair? info) (rows-result info rows)] [else (simple-result '())]))) (define/private (query1 fsym stmt) diff --git a/collects/db/scribblings/introduction.scrbl b/collects/db/scribblings/introduction.scrbl index 01a656acdc..7240899c1b 100644 --- a/collects/db/scribblings/introduction.scrbl +++ b/collects/db/scribblings/introduction.scrbl @@ -64,14 +64,14 @@ system to system and is subject to change.) [(query pgc "insert into the_numbers values (3, 'a crowd')") (simple-result '((command insert 0 1)))] [(query pgc "select n, d from the_numbers where n % 2 = 0") - (recordset + (rows-result (list '((name . "n") (typeid . 23)) '((name . "d") (typeid . 1043))) '(#(0 "nothing") #(2 "company")))] ] -When the query is known to return a recordset and when the field +When the query is known to return rows and when the field descriptions are not needed, it is more convenient to use the @racket[query-rows] function. @@ -80,16 +80,16 @@ descriptions are not needed, it is more convenient to use the '(#(0 "nothing") #(2 "company"))] ] -Use @racket[query-row] for queries that are known to return a -recordset of exactly one row. +Use @racket[query-row] for queries that are known to return exactly +one row. @my-interaction[ [(query-row pgc "select * from the_numbers where n = 0") (vector 0 "nothing")] ] -Similarly, use @racket[query-list] for queries that produce a -recordset of exactly one column. +Similarly, use @racket[query-list] for queries that produce rows of +exactly one column. @my-interaction[ [(query-list pgc "select d from the_numbers order by n") diff --git a/collects/db/scribblings/query.scrbl b/collects/db/scribblings/query.scrbl index a202e7f5ad..588d22f547 100644 --- a/collects/db/scribblings/query.scrbl +++ b/collects/db/scribblings/query.scrbl @@ -89,8 +89,8 @@ All query functions require both a connection and a The simple query API consists of a set of functions specialized to various types of queries. For example, @racket[query-value] is -specialized to queries that return a recordset of exactly one column -and exactly one row. +specialized to queries that return exactly one row of exactly one +column. If a statement takes parameters, the parameter values are given as additional arguments immediately after the SQL statement. Only a @@ -121,8 +121,8 @@ The types of parameters and returned fields are described in [arg any/c] ...) (listof vector?)]{ - Executes a SQL query, which must produce a recordset, and returns the - list of rows (as vectors) from the query. + Executes a SQL query, which must produce rows, and returns the list + of rows (as vectors) from the query. @examples/results[ [(query-rows pgc "select * from the_numbers where n = $1" 2) @@ -137,7 +137,7 @@ The types of parameters and returned fields are described in [arg any/c] ...) list?]{ - Executes a SQL query, which must produce a recordset of exactly one + Executes a SQL query, which must produce rows of exactly one column, and returns the list of values from the query. @examples/results[ @@ -153,8 +153,8 @@ The types of parameters and returned fields are described in [arg any/c] ...) vector?]{ - Executes a SQL query, which must produce a recordset of exactly one - row, and returns its (single) row result as a vector. + Executes a SQL query, which must produce exactly one row, and + returns its (single) row result as a vector. @examples/results[ [(query-row myc "select * from the_numbers where n = ?" 2) @@ -185,8 +185,8 @@ The types of parameters and returned fields are described in [arg any/c] ...) any/c]{ - Executes a SQL query, which must produce a recordset of exactly one - column and exactly one row, and returns its single value result. + Executes a SQL query, which must produce exactly one row of exactly + one column, and returns its single value result. @examples/results[ [(query-value pgc "select timestamp 'epoch'") @@ -217,9 +217,9 @@ The types of parameters and returned fields are described in [arg any/c] ...) sequence?]{ - Executes a SQL query, which must produce a recordset, and returns a + Executes a SQL query, which must produce rows, and returns a sequence. Each step in the sequence produces as many values as the - recordset has columns. + rows have columns. @examples/results[ [(for/list ([n (in-query pgc "select n from the_numbers where n < 2")]) @@ -249,7 +249,7 @@ based on the number of variables in the clause's left-hand side: @section{General Query Support} A general query result is either a @racket[simple-result] or a -@racket[recordset]. +@racket[rows-result]. @defstruct*[simple-result ([info any/c])]{ @@ -262,7 +262,7 @@ rely on its contents; it varies based on database system and may change in future versions of this library (even new minor versions). } -@defstruct*[recordset +@defstruct*[rows-result ([headers (listof any/c)] [rows (listof vector?)])]{ @@ -279,11 +279,11 @@ future version of this library (even new minor versions). @defproc[(query [connection connection?] [stmt statement?] [arg any/c] ...) - (or/c simple-result? recordset?)]{ + (or/c simple-result? rows-result?)]{ Executes a query, returning a structure that describes the results. Unlike the more specialized query functions, @racket[query] - supports both recordset-returning and effect-only queries. + supports both rows-returning and effect-only queries. } @@ -347,11 +347,11 @@ closed. @defproc[(prepared-statement-result-types [pst prepared-statement?]) (listof (list/c boolean? (or/c symbol? #f) any/c))]{ - If @racket[pst] is a recordset-producing statement (eg, - @tt{SELECT}), returns a list of type descriptions as described - above, identifying the SQL types (or pseudotypes) of the result - columns. If @racket[pst] does not produce a recordset, the function - returns the empty list. + If @racket[pst] is a rows-returning statement (eg, @tt{SELECT}), + returns a list of type descriptions as described above, identifying + the SQL types (or pseudotypes) of the result columns. If + @racket[pst] is not a rows-returning statement, the function returns + the empty list. } @defproc[(bind-prepared-statement diff --git a/collects/tests/db/db/query.rkt b/collects/tests/db/db/query.rkt index 3b5527b75e..5b267f2912 100644 --- a/collects/tests/db/db/query.rkt +++ b/collects/tests/db/db/query.rkt @@ -139,10 +139,10 @@ (test-case "query - select" (with-connection c (let [(q (query c "select N from the_numbers"))] - (check-pred recordset? q) + (check-pred rows-result? q) (check set-equal? (map vector (map car test-data)) - (recordset-rows q))))) + (rows-result-rows q))))) (test-case "query - update" (unless (ANYFLAGS 'isora 'isdb2) (with-connection c