Use the default fmt function, collect only the first header
line for field names, and don't call plist-get for the table
name on every line.

Signed-off-by: Jason Riedy <[EMAIL PROTECTED]>
---
 contrib/ChangeLog                |    7 +++++++
 contrib/lisp/orgtbl-sqlinsert.el |   13 +++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index 5db4bb3..85a7a27 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,3 +1,10 @@
+2008-05-04  Jason Riedy  <[EMAIL PROTECTED]>
+
+       * lisp/orgtbl-sqlinsert.el (orgtbl-to-sqlinsert): Use the
+       default fmt function, collect only the first header line for
+       field names, and don't call plist-get for the table name on
+       every line.
+
 2008-04-15  Jason Riedy  <[EMAIL PROTECTED]>
 
        * lisp/orgtbl-sqlinsert.el: New file.
diff --git a/contrib/lisp/orgtbl-sqlinsert.el b/contrib/lisp/orgtbl-sqlinsert.el
index 869f74f..648e44c 100644
--- a/contrib/lisp/orgtbl-sqlinsert.el
+++ b/contrib/lisp/orgtbl-sqlinsert.el
@@ -64,6 +64,8 @@ this function is called."
                               org-table-last-alignment ""))
         (nowebname (plist-get params :nowebname))
         (breakvals (plist-get params :breakvals))
+         (firstheader t)
+         (*orgtbl-default-fmt* 'orgtbl-sql-strip-and-quote)
         (params2
          (list
           :sqlname name
@@ -72,12 +74,10 @@ this function is called."
                                        "")
                                      "BEGIN TRANSACTION;"))
           :tend (lambda () (concat "COMMIT;" (if nowebname "\n@ " "")))
-          :fmt (lambda (str) (orgtbl-sql-strip-and-quote str))
-;         :hfmt (lambda (f) (push (concat "[" f "]") hdrlist) "")
-          :hfmt (lambda (f) (push f hdrlist) "")
-          :hlfmt (lambda (lst) nil)
+          :hfmt (lambda (f) (progn (if firstheader (push f hdrlist)) ""))
+          :hlfmt (lambda (lst) (setq firstheader nil))
           :lstart (lambda () (concat "INSERT INTO "
-                                     (plist-get params :sqlname) "( "
+                                     sqlname "( "
                                      (mapconcat 'identity (reverse hdrlist)
                                                 ", ")
                                      " )" (if breakvals "\n" " ")
@@ -86,7 +86,8 @@ this function is called."
           :sep " , "
           :hline nil
           :remove-nil-lines t))
-        (params (org-combine-plists params2 params)))
+        (params (org-combine-plists params2 params))
+         (sqlname (plist-get params :sqlname)))
     (orgtbl-to-generic table params)))
 
 (defun orgtbl-sql-quote (str)
-- 
1.5.5.rc1.121.g1594



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to