emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] orgtbl-to-sqlinsert


From: Thierry Banel
Subject: Re: [O] orgtbl-to-sqlinsert
Date: Tue, 04 Feb 2014 22:18:28 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0

Le 03/02/2014 00:47, Thomas S. Dye a écrit :
Aloha Thierry,

Thierry Banel <address@hidden> writes:

Hi Thomas.

I don't understand this behavior yet.
But here is a workaround:
try the   #+ORGTBL: SEND  feature:
1- Add a #+ORGTBL: SEND line
2- Add a BEGIN RECEIVE ORGTBL block
3- Type C-c C-c with cursor on the first pipe of the table

--8<--------------------------->8--
#+ORGTBL: SEND faraway orgtbl-to-sqlinsert :sqlname "foo" :fmt (1 "%s")
| one | two    |
|-----+--------|
|   1 | Buckle |
|   2 | Shoe   |
|   3 | Open   |
|   4 | Door   |

;; BEGIN RECEIVE ORGTBL faraway
BEGIN TRANSACTION;
INSERT INTO foo( one, two ) VALUES ( 1 , 'Buckle' );
INSERT INTO foo( one, two ) VALUES ( 2 , 'Shoe' );
INSERT INTO foo( one, two ) VALUES ( 3 , 'Open' );
INSERT INTO foo( one, two ) VALUES ( 4 , 'Door' );
COMMIT;
;; END RECEIVE ORGTBL faraway
Yes, this works.

Perhaps the table needs to be processed before it is passed to
orgtbl-to-sqlinsert? 

  Note that =orgtbl-to-sqlinsert= takes advantage of org-mode's applying
  the formatting to each cell /before/ checking for a line-formatting
  function.  The header line itself and sectioning line are suppressed
  with the settings

  : :hlfmt (lambda (lst) (setq firstheader nil))
  : :hline nil
  : :remove-nil-lines t

I don't fully understand what this means, but it appears to address the
table header.

All the best,
Tom


Hi again Thomas

Probably the issue is not in orgtbl-to-sqlinsert,
because orgtbl-to-sqlinsert does not receive the header of the table.
Here is another fix which just recovers the lost header and passes it to orgtbl-to-sqlinsert:

---8<----------------------->8---
*** Experiment with orgtbl-sqlinsert

#+name: test-table
| one | two    |
|-----+--------|
|   1 | Buckle |
|   2 | Shoe   |
|   3 | Open   |
|   4 | Door   |

#+name: test-bed
#+header: :var x=test-table
#+begin_src emacs-lisp
(require 'orgtbl-sqlinsert)
(orgtbl-to-sqlinsert
   (cons (cdadr (assoc :colname-names params)) (cons 'hline x))
  '(:sqlname "foo" :fmt (1 "%s")))
#+end_src

#+RESULTS: test-bed
: BEGIN TRANSACTION;
: INSERT INTO foo( one, two ) VALUES ( 1 , 'Buckle' );
: INSERT INTO foo( one, two ) VALUES ( 2 , 'Shoe' );
: INSERT INTO foo( one, two ) VALUES ( 3 , 'Open' );
: INSERT INTO foo( one, two ) VALUES ( 4 , 'Door' );
: COMMIT;
---8<----------------------->8---






reply via email to

[Prev in Thread] Current Thread [Next in Thread]