Module: select-viewer Synopsis: A simple sql query viewer Author: Keith Playford Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND // TODO: Create and define an object. define constant $dbms :: = make(); define class () constant slot name-data :: , required-init-keyword: name:; constant slot user-name-data :: , required-init-keyword: user-name:; constant slot password-data :: , required-init-keyword: password:; end class; // TODO: Implement open-database. Whatever you return is passed in to query-database // and close-database. define method open-database (name :: , user-name :: , password :: ) => (dbd :: ) make(, name: name, user-name: user-name, password: password); end method; // TODO: Implement query-interface. Use compute-column-headings on the result // sequence to generate the headings for you. define method query-database (dbd :: , query :: ) => (headings :: , rows :: ) with-dbms ($dbms) let db = make(, datasource-name: name-data(dbd)); let login = make(, user-name: user-name-data(dbd), password: password-data(dbd)); with-database (db, login) let results = map-as(, identity, execute(query)); let headings = compute-column-headings(results); values(headings, results) end; end; end method; define method compute-column-headings (results :: ) => (headings :: ) if (empty?(results)) #[] else let n-cols = size(first(results)); let headings = make(, size: n-cols); for (i from 0 below n-cols) headings[i] := format-to-string("Column %=", i + 1); end; headings end; end method; // TODO: Implement close-database. define method close-database (dbd) => () end method; // eof