From mboxrd@z Thu Jan 1 00:00:00 1970 From: Charles Sebold Subject: Re: Re: Patch for ob-sql.el SQL output Date: Tue, 21 Dec 2010 10:57:00 -0600 Message-ID: References: <80hbe7gmwh.fsf@missioncriticalit.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Return-path: Received: from [140.186.70.92] (port=42336 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PV5WL-0004Q2-CT for emacs-orgmode@gnu.org; Tue, 21 Dec 2010 11:57:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PV5WJ-0003eZ-LI for emacs-orgmode@gnu.org; Tue, 21 Dec 2010 11:57:05 -0500 Received: from mail-fx0-f48.google.com ([209.85.161.48]:33248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PV5WJ-0003eJ-BW for emacs-orgmode@gnu.org; Tue, 21 Dec 2010 11:57:03 -0500 Received: by fxm2 with SMTP id 2so4132045fxm.35 for ; Tue, 21 Dec 2010 08:57:02 -0800 (PST) In-Reply-To: <80hbe7gmwh.fsf@missioncriticalit.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?ISO-8859-1?Q?S=E9bastien_Vauban?= Cc: emacs-orgmode I feel silly. I was just testing with one output column. Change the $ in the regexp to "[^-]" or just reapply patch as follows: diff --git a/lisp/ob-sql.el b/lisp/ob-sql.el index 5bb123d..32b7bf0 100644 --- a/lisp/ob-sql.el +++ b/lisp/ob-sql.el @@ -65,6 +65,7 @@ This function is called by `org-babel-execute-src-block'.= " (in-file (org-babel-temp-file "sql-in-")) (out-file (or (cdr (assoc :out-file params)) (org-babel-temp-file "sql-out-"))) + (header-delim "") (command (case (intern engine) ('msosql (format "osql %s -s \"\t\" -i %s -o %s" (or cmdline "") @@ -84,9 +85,19 @@ This function is called by `org-babel-execute-src-block'= ." (message command) (shell-command command) (with-temp-buffer + ; need to figure out what the delimiter is for the header row + (with-temp-buffer + (insert-file-contents out-file) + (goto-char (point-min)) + (when (re-search-forward "^\\(-+\\)[^-]" nil t) + (setq header-delim (match-string-no-properties 1)))) (org-table-import out-file '(16)) (org-babel-reassemble-table - (org-table-to-lisp) + (mapcar (lambda (x) + (if (string=3D (car x) header-delim) + 'hline + x)) + (org-table-to-lisp)) (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) 2010/12/21 S=E9bastien Vauban : > Hi Charles, > > Charles Sebold wrote: >> I use org-mode and babel under Windows with osql, and the line separatin= g >> the header from the rest of the rows in the output was bothering me. > > Excellent initiative! > >> I don't know that this is a really good fix, but maybe it's a start for = one? >> It looks for the first output line of all dashes and replaces it later w= ith >> the 'hline when the table is lisp-ified. > > It does not work correctly for me (with the osql engine). Look at the > situation before/after your patch: > > 1. Before > > =A0 #+srcname: top-10-dossiers-with-many-presta > =A0 #+begin_src sql > =A0 SET NOCOUNT ON > > =A0 SELECT TOP 10 prsAbcID, COUNT(*) AS '# Presta' > =A0 FROM presta > =A0 GROUP BY prsAbcID > =A0 ORDER BY COUNT(*) DESC > =A0 #+end_src > > =A0 #+results: top-10-dossiers-with-many-presta > =A0 | =A0 =A0 =A0 =A0 prsAbcID | =A0 =A0 =A0# Presta | > =A0 | ---------------- | ------------- | > =A0 | =A0 73020050900111 | =A0 =A0 =A0 =A0 =A0 =A022 | > =A0 | =A0 52020030200047 | =A0 =A0 =A0 =A0 =A0 =A021 | > =A0 | =A0 61020060400007 | =A0 =A0 =A0 =A0 =A0 =A021 | > =A0 | =A0 62020031200052 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 72020051100016 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 73020050800025 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 56020031100002 | =A0 =A0 =A0 =A0 =A0 =A019 | > =A0 | =A0 63020060900056 | =A0 =A0 =A0 =A0 =A0 =A019 | > =A0 | =A0 61020030900049 | =A0 =A0 =A0 =A0 =A0 =A018 | > =A0 | =A0 72020030700040 | =A0 =A0 =A0 =A0 =A0 =A018 | > =A0 | =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0| =A0 =A0 =A0 =A0 =A0 =A0 =A0 | > > =A0 Another annoying thing is the empty line at the end. With the COUNT O= N, > =A0 there is one empty line followed by the count. > > 2. After > > =A0 #+results: top-10-dossiers-with-many-presta > =A0 | =A0 =A0 =A0 =A0 prsAbcID | =A0 =A0 =A0# Presta | > =A0 | ---------------- | ------------- | > =A0 | =A0 73020050900111 | =A0 =A0 =A0 =A0 =A0 =A022 | > =A0 | =A0 52020030200047 | =A0 =A0 =A0 =A0 =A0 =A021 | > =A0 | =A0 61020060400007 | =A0 =A0 =A0 =A0 =A0 =A021 | > =A0 | =A0 62020031200052 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 72020051100016 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 73020050800025 | =A0 =A0 =A0 =A0 =A0 =A020 | > =A0 | =A0 56020031100002 | =A0 =A0 =A0 =A0 =A0 =A019 | > =A0 | =A0 63020060900056 | =A0 =A0 =A0 =A0 =A0 =A019 | > =A0 | =A0 61020030900049 | =A0 =A0 =A0 =A0 =A0 =A018 | > =A0 | =A0 72020030700040 | =A0 =A0 =A0 =A0 =A0 =A018 | > =A0 |------------------+---------------| > > =A0 The hline is not applied on the second line, but at the end of the ta= ble. > =A0 Perhaps the good condition is to work on the second line? > > Best regards, > =A0Seb > > -- > S=E9bastien Vauban > > > _______________________________________________ > Emacs-orgmode mailing list > Please use `Reply All' to send replies to the list. > Emacs-orgmode@gnu.org > http://lists.gnu.org/mailman/listinfo/emacs-orgmode > --=20 Charles Sebold Ego delendus sum