Changeset main,8


Ignore:
Timestamp:
11/13/2007 04:24:26 PM (19 years ago)
Author:
David Owen <dsowen@…>
branch-nick:
xbase
revision id:
dsowen@fugue88.ws-20071113162426-wigngk2zoejbcdu8
Message:

Can create connection-temporary and transaction-temporary tables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/xbase.lisp

    r7 r8  
    134134              (t (error "Bad type ~S." type))))))
    135135
     136(defvar *temporary-tables* nil)
     137
    136138(defun sql-create (name descs)
    137   (format nil "CREATE TABLE ~A~%   (~{~A~@{,~%    ~A~}~})"
     139  (format nil "CREATE ~:[~;TEMP ~]TABLE ~A~%   (~{~A~@{,~%    ~A~}~})~:[~;~%ON COMMIT DROP~]"
     140          *temporary-tables*
    138141          name
    139           (mapcar 'sql-column descs)))
     142          (mapcar 'sql-column descs)
     143          (eql *temporary-tables* 1)))
    140144
    141145(defgeneric sql-insert (obj))
     
    210214  (multiple-value-bind (db-name table-name) (split-name filename)
    211215    (let ((recs (import-dbf filename table-name)))
    212       (format t "BEGIN;~%~%~%~%~A;~%~%~%~%"
     216      (format t "~A;~4%"
    213217              (slot-value (gethash 'import-struct *dbfs*) 'sql-create))
    214218      (dolist (rec recs)
    215219        (unless (/= (slot-value rec '%deleted) 32)
    216           (format t "~A;~%~%" (sql-insert rec))))
    217       (format t "~%~%COMMIT;~%"))))
     220          (format t "~2&~A;~%" (sql-insert rec)))))))
    218221
    219222(defun main ()
    220   (when (/= (length *posix-argv*) 2)
    221     (format *error-output* "Usage: xbase dbf-file~%")
     223  (unless (member (length *posix-argv*) '(2 3))
     224    (format *error-output* "Usage: xbase [-t | -tt] dbf-file~%")
    222225    (quit))
    223   (do-dbf (second *posix-argv*))
     226  (let* ((*temporary-tables* (position (second *posix-argv*) '("-t" "-tt") :test 'string=))
     227         (file (if *temporary-tables*
     228                   (third *posix-argv*)
     229                   (second *posix-argv*))))
     230    (do-dbf file))
    224231  (quit))
Note: See TracChangeset for help on using the changeset viewer.