home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 44
/
Amiga_Dream_44.iso
/
RiscPc
/
programmation
/
scm4e2.arc
/
!Scm
/
slib
/
dbutil
< prev
next >
Wrap
Text File
|
1994-12-18
|
2KB
|
67 lines
;;; "dbutil.scm" relational-database-utilities
; Copyright 1994 Aubrey Jaffer
;
;Permission to copy this software, to redistribute it, and to use it
;for any purpose is granted, subject to the following restrictions and
;understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warrantee or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
(require 'relational-database)
(define (dbutil:define-tables rdb spec-list)
(define new-tables '())
(define (define-table name prikeys slots data)
(define create-table (rdb 'create-table))
(define descname
(string->symbol (string-append "desc:" (symbol->string name))))
(let* ((tab (create-table descname))
(row:insert (tab 'row:insert))
(domains ((rdb 'open-table) '*domains-data* #f))
(dom:typ (domains 'get 4))
(j 0))
(define (check-domain dname)
(cond ((dom:typ dname))
((member dname new-tables)
(let* ((ftab ((rdb 'open-table)
(string->symbol
(string-append "desc:" (symbol->string dname)))
#f)))
((rdb 'add-domain)
(list dname dname #f
(dom:typ ((ftab 'get 'domain-name) 1)) #f))))))
(set! new-tables (cons name new-tables))
(for-each (lambda (des)
(set! j (+ 1 j))
(check-domain (cadr des))
(row:insert (list j #t (car des)
(if (null? (cddr des)) #f (caddr des))
(cadr des))))
prikeys)
(for-each (lambda (des)
(set! j (+ 1 j))
(check-domain (cadr des))
(row:insert (list j #f (car des)
(if (null? (cddr des)) #f (caddr des))
(cadr des))))
slots)
((tab 'close-table))
(set! tab (create-table name descname))
(set! row:insert (tab 'row:insert))
(for-each row:insert data)
((tab 'close-table))))
(for-each (lambda (spec) (apply define-table spec)) spec-list))
(define define-tables dbutil:define-tables)