From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thierry Banel Subject: Re: orgtbl-to-sqlinsert Date: Tue, 04 Feb 2014 22:18:28 +0100 Message-ID: <52F15924.1080104@free.fr> References: <52EEB660.5070308@free.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------000108070909050903080308" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAnOA-0006QL-J6 for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:18:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WAnO9-00062E-7v for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:18:38 -0500 Received: from smtp3-g21.free.fr ([2a01:e0c:1:1599::12]:59388) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WAnO8-00061U-Ds for emacs-orgmode@gnu.org; Tue, 04 Feb 2014 16:18:37 -0500 Received: from [IPv6:2a01:e35:2e21:def0:8dcc:48a7:98b3:f206] (unknown [IPv6:2a01:e35:2e21:def0:8dcc:48a7:98b3:f206]) by smtp3-g21.free.fr (Postfix) with ESMTP id 0D082A624C for ; Tue, 4 Feb 2014 22:18:29 +0100 (CET) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a multi-part message in MIME format. --------------000108070909050903080308 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Le 03/02/2014 00:47, Thomas S. Dye a =E9crit : > Aloha Thierry, > > Thierry Banel 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?=20 > > Note that =3Dorgtbl-to-sqlinsert=3D takes advantage of org-mode's app= lying > 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=3Dtest-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--- --------------000108070909050903080308 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
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---





--------------000108070909050903080308--