This file is indexed.

/usr/share/guile/database/postgres-resx.scm is in guile-pg 0.16-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
;;; postgres-resx.scm --- query-result transforms

;;    Guile-pg - A Guile interface to PostgreSQL
;;    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
;;
;;    This program is free software; you can redistribute it and/or modify
;;    it under the terms of the GNU General Public License as published by
;;    the Free Software Foundation; either version 2 of the License, or
;;    (at your option) any later version.
;;
;;    This program is distributed in the hope that it will be useful,
;;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;    GNU General Public License for more details.
;;
;;    You should have received a copy of the GNU General Public License
;;    along with this program; if not, write to the Free Software
;;    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

;;; Author: Thien-Thi Nguyen <ttn@gnu.org>

;;; Commentary:

;; This module provides various procedures to translate/transform tuple data
;; resulting from a query against a PostgreSQL database:
;;
;;  (for-each-tuple PROC RESULT) => bool
;;  (result-field->object-list RESULT FN OBJECTIFIER) => list
;;  (result->object-alist RESULT OBJECTIFIERS) => alist
;;  (result->object-alists RESULT OBJECTIFIERS) => list of alists

;;; Code:

(define-module (database postgres-resx)
  :use-module (database postgres)
  :use-module (database postgres-types)
  :use-module ((database postgres-col-defs)
               :renamer (symbol-prefix-proc 'def:))
  :export (for-each-tuple
           result-field->object-list
           result->object-alist
           result->object-alists))

;; Apply @var{proc} to each tuple in @var{result}.  Return #t to indicate
;; success, or #f if either the tuple count or the field count is zero.
;; The tuple is the list formed by mapping @code{pg-getvalue} over the fields.
;;
(define (for-each-tuple proc result)
  (let* ((nfields (pg-nfields result))
         (ntuples (pg-ntuples result))
         (field-range (iota nfields)))
    (and (< 0 nfields) (< 0 ntuples)
         (do ((tn 0 (1+ tn)))
             ((= tn ntuples) #t)        ; retval
           (apply proc (map (lambda (fn)
                              (pg-getvalue result tn fn))
                            field-range))))))

;; For @var{result} field number @var{fn}, map @var{objectifier}.
;; Return a list whose length is the number of tuples in @var{result}.
;;
(define (result-field->object-list result fn objectifier)
  (let loop ((tn (1- (pg-ntuples result))) (acc '()))
    (if (> 0 tn)
        acc                             ; retval
        (loop (1- tn)
              (cons (objectifier (pg-getvalue result tn fn))
                    acc)))))

;; Return an alist from extracting @var{result} using @var{objectifiers}.
;; Each key (a symbol) is a field name obtained by @code{pg-fname}, and the
;; associated value is a list of objects coverted by one of the objectifier
;; procedures from the list @var{objectifiers}.
;;
(define (result->object-alist result objectifiers)
  (let ((fn -1))
    (map (lambda (objectifier)
           (set! fn (1+ fn))
           (cons (string->symbol (pg-fname result fn))
                 (result-field->object-list result fn objectifier)))
         objectifiers)))

;; Process @var{result} using @var{objectifiers} like
;; @code{result->object-alist}, but return a list of alists instead,
;; each corresponding to a tuple in @var{result}.
;;
(define (result->object-alists result objectifiers)
  (let ((oa (result->object-alist result objectifiers)))
    (let ((names (map car oa)))
      (apply map (lambda slice
                   (map cons names slice))
             (map cdr oa)))))

;;; postgres-resx.scm ends here