emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* orgtbl-to-sqlinsert
@ 2014-02-02 20:09 Thomas S. Dye
  2014-02-02 21:19 ` orgtbl-to-sqlinsert Thierry Banel
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2014-02-02 20:09 UTC (permalink / raw)
  To: Org-mode

Aloha all,

I'm expecting column names in the "foo( )" part of the INSERT statement.

I've done my best to understand
http://orgmode.org/worg/org-tutorials/multitarget-tables.org.html but
appear to have failed.

Can someone help?

*** 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 x '(:sqlname "foo" :fmt (1 "%s")))
#+end_src

#+results: test-bed
: BEGIN TRANSACTION;
: INSERT INTO foo(  ) VALUES ( 1 , 'Buckle' );
: INSERT INTO foo(  ) VALUES ( 2 , 'Shoe' );
: INSERT INTO foo(  ) VALUES ( 3 , 'Open' );
: INSERT INTO foo(  ) VALUES ( 4 , 'Door' );
: COMMIT;

All the best,
Tom
-- 
T.S. Dye & Colleagues, Archaeologists
735 Bishop St, Suite 315, Honolulu, HI 96813
Tel: 808-529-0866, Fax: 808-529-0884
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: orgtbl-to-sqlinsert
  2014-02-02 20:09 orgtbl-to-sqlinsert Thomas S. Dye
@ 2014-02-02 21:19 ` Thierry Banel
  2014-02-02 23:47   ` orgtbl-to-sqlinsert Thomas S. Dye
  0 siblings, 1 reply; 5+ messages in thread
From: Thierry Banel @ 2014-02-02 21:19 UTC (permalink / raw)
  To: emacs-orgmode

Le 02/02/2014 21:09, Thomas S. Dye a écrit :
> Aloha all,
>
> I'm expecting column names in the "foo( )" part of the INSERT statement.
>
> I've done my best to understand
> http://orgmode.org/worg/org-tutorials/multitarget-tables.org.html but
> appear to have failed.
>
> Can someone help?
>
> *** 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 x '(:sqlname "foo" :fmt (1 "%s")))
> #+end_src
>
> #+results: test-bed
> : BEGIN TRANSACTION;
> : INSERT INTO foo(  ) VALUES ( 1 , 'Buckle' );
> : INSERT INTO foo(  ) VALUES ( 2 , 'Shoe' );
> : INSERT INTO foo(  ) VALUES ( 3 , 'Open' );
> : INSERT INTO foo(  ) VALUES ( 4 , 'Door' );
> : COMMIT;
>
> All the best,
> Tom
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
--8<--------------------------->8--

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: orgtbl-to-sqlinsert
  2014-02-02 21:19 ` orgtbl-to-sqlinsert Thierry Banel
@ 2014-02-02 23:47   ` Thomas S. Dye
  2014-02-04 21:18     ` orgtbl-to-sqlinsert Thierry Banel
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas S. Dye @ 2014-02-02 23:47 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Aloha Thierry,

Thierry Banel <tbanelwebmin@free.fr> 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

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: orgtbl-to-sqlinsert
  2014-02-02 23:47   ` orgtbl-to-sqlinsert Thomas S. Dye
@ 2014-02-04 21:18     ` Thierry Banel
  2014-02-04 22:00       ` orgtbl-to-sqlinsert Thomas S. Dye
  0 siblings, 1 reply; 5+ messages in thread
From: Thierry Banel @ 2014-02-04 21:18 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2546 bytes --]

Le 03/02/2014 00:47, Thomas S. Dye a écrit :
> Aloha Thierry,
>
> Thierry Banel <tbanelwebmin@free.fr> 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---





[-- Attachment #2: Type: text/html, Size: 3413 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: orgtbl-to-sqlinsert
  2014-02-04 21:18     ` orgtbl-to-sqlinsert Thierry Banel
@ 2014-02-04 22:00       ` Thomas S. Dye
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas S. Dye @ 2014-02-04 22:00 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Aloha Thierry,

Thierry Banel <tbanelwebmin@free.fr> writes:

> 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;

Yes, of course, babel takes off the table header and optionally
reapplies it later. I should have thought of that!

Thanks for looking into this and finding the solution.

All the best,
Tom

-- 
Thomas S. Dye
http://www.tsdye.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-02-04 22:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-02 20:09 orgtbl-to-sqlinsert Thomas S. Dye
2014-02-02 21:19 ` orgtbl-to-sqlinsert Thierry Banel
2014-02-02 23:47   ` orgtbl-to-sqlinsert Thomas S. Dye
2014-02-04 21:18     ` orgtbl-to-sqlinsert Thierry Banel
2014-02-04 22:00       ` orgtbl-to-sqlinsert Thomas S. Dye

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).