emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: sqlite output truncated?
@ 2021-05-03 22:22 learn orchids
  2021-05-03 23:32 ` Nick Savage
  2021-05-04 20:42 ` [PATCH] Fix truncated output in ob-sqlite.el (Was: Bug: sqlite output truncated?) Nick Savage
  0 siblings, 2 replies; 4+ messages in thread
From: learn orchids @ 2021-05-03 22:22 UTC (permalink / raw)
  To: emacs-orgmode

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

I am using Org mode version 9.4.5 (9.4.5-73-g4c7696-elpaplus and I
have the following code snippet. Values in the 'sql' column of the
second row is truncated. Am I missing something?

#+begin_src sqlite :db /tmp/rip.db  :colnames yes
  drop table if exists testtable;
  create table testtable(id int, sql varchar);
  insert into testtable values (1, "Select id from foo");
  insert into testtable values (2, 'Select "id" from foo');
  select* from testtable;
#+end_src

#+RESULTS: testsql
| id | sql                |
|----+--------------------|
|  1 | Select id from foo |
|  2 | id                 |

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

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

* Re: Bug: sqlite output truncated?
  2021-05-03 22:22 Bug: sqlite output truncated? learn orchids
@ 2021-05-03 23:32 ` Nick Savage
  2021-05-04 20:42 ` [PATCH] Fix truncated output in ob-sqlite.el (Was: Bug: sqlite output truncated?) Nick Savage
  1 sibling, 0 replies; 4+ messages in thread
From: Nick Savage @ 2021-05-03 23:32 UTC (permalink / raw)
  To: emacs-orgmode

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

I can replicate this, it looks like a bug to me.

Looks to me that there's something wrong with the way it is handling 
single quoted strings, since the output is only what is within the 
double quoted strings. I will take a stab at fixing this.

On 5/3/21 6:22 PM, learn orchids wrote:
> I am using Org mode version 9.4.5 (9.4.5-73-g4c7696-elpaplus and I have the following code snippet. Values in the 'sql' column of the second row is truncated. Am I missing something?
>
> #+begin_src sqlite :db /tmp/rip.db  :colnames yes
>    drop table if exists testtable;
>    create table testtable(id int, sql varchar);
>    insert into testtable values (1, "Select id from foo");
>    insert into testtable values (2, 'Select "id" from foo');
>    select* from testtable;
> #+end_src
>
> #+RESULTS: testsql
> | id | sql                |
> |----+--------------------|
> |  1 | Select id from foo |
> |  2 | id                 |

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

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

* [PATCH] Fix truncated output in ob-sqlite.el (Was: Bug: sqlite output truncated?)
  2021-05-03 22:22 Bug: sqlite output truncated? learn orchids
  2021-05-03 23:32 ` Nick Savage
@ 2021-05-04 20:42 ` Nick Savage
  2021-05-04 20:44   ` [PATCH] Fix truncated output in ob-sqlite.el Bastien
  1 sibling, 1 reply; 4+ messages in thread
From: Nick Savage @ 2021-05-04 20:42 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 1206 bytes --]

I've attached a patch to address this.

The issue is that ob-sqlite.el uses org-babel-string-read, which 
purposefully removes double-quotes. I think this is unintended 
behaviour, and it only seems to be used with ob-sqlite.el. I added a 
minor function to bypass the part of org-babel-string-read that was 
stripping out the double-quotes and use the rest of the function.

I tried ob-sql with the mysql engine and didn't experience the same bug, 
so I'm pretty confident that this is an isolated issue.


On 5/3/21 6:22 PM, learn orchids wrote:
> I am using Org mode version 9.4.5 (9.4.5-73-g4c7696-elpaplus and I have the following code snippet. Values in the 'sql' column of the second row is truncated. Am I missing something?
>
> #+begin_src sqlite :db /tmp/rip.db  :colnames yes
>    drop table if exists testtable;
>    create table testtable(id int, sql varchar);
>    insert into testtable values (1, "Select id from foo");
>    insert into testtable values (2, 'Select "id" from foo');
>    select* from testtable;
> #+end_src
>
> #+RESULTS: testsql
> | id | sql                |
> |----+--------------------|
> |  1 | Select id from foo |
> |  2 | id                 |

[-- Attachment #1.2: Type: text/html, Size: 2070 bytes --]

[-- Attachment #2: 0001-lisp-ob-sqlite.el-Prevent-output-from-being-incorrec.patch --]
[-- Type: text/x-patch, Size: 1576 bytes --]

From 3dd868bcd798e6763ec67ba0d2661834e09bb6e9 Mon Sep 17 00:00:00 2001
From: Nicholas Savage <nick@nicksavage.ca>
Date: Tue, 4 May 2021 11:02:20 -0400
Subject: [PATCH] lisp/ob-sqlite.el: Prevent output from being incorrectly
 parsed if it contains double-quotes.

* lisp/ob-sqlite.el (org-babel-sqlite--read-cell): New function.
lisp/ob-sqlite.el (org-babel-sqlite-table-or-scalar): Use
`org-babel-sqlite--read-cell' instead of `org-babel-string-read' to
prevent data from being ignored if it contains double-quotes.

Reported-by: learnorchids@gmail.com
Link: https://orgmode.org/list/CAK5xwica4i8h09ObzCVPx2pe-T6B0_ju_MXiduRiY7GH+PkE_A@mail.gmail.com/
---
 lisp/ob-sqlite.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-sqlite.el b/lisp/ob-sqlite.el
index c0c6f3c97..d227ba69d 100644
--- a/lisp/ob-sqlite.el
+++ b/lisp/ob-sqlite.el
@@ -125,7 +125,7 @@ This function is called by `org-babel-execute-src-block'."
     (mapcar (lambda (row)
 	      (if (eq 'hline row)
 		  'hline
-		(mapcar #'org-babel-string-read row)))
+		(mapcar #'org-babel-sqlite--read-cell row)))
 	    result)))
 
 (defun org-babel-sqlite-offset-colnames (table headers-p)
@@ -139,6 +139,10 @@ This function is called by `org-babel-execute-src-block'."
 Prepare SESSION according to the header arguments specified in PARAMS."
   (error "SQLite sessions not yet implemented"))
 
+(defun org-babel-sqlite--read-cell (cell)
+  "Process CELL to remove unnecessary characters."
+  (org-babel-read cell t))
+
 (provide 'ob-sqlite)
 
 ;;; ob-sqlite.el ends here
-- 
2.20.1


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

* Re: [PATCH] Fix truncated output in ob-sqlite.el
  2021-05-04 20:42 ` [PATCH] Fix truncated output in ob-sqlite.el (Was: Bug: sqlite output truncated?) Nick Savage
@ 2021-05-04 20:44   ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2021-05-04 20:44 UTC (permalink / raw)
  To: Nick Savage; +Cc: emacs-orgmode

Hi Nick,

Nick Savage <nick@nicksavage.ca> writes:

> I've attached a patch to address this.

Applied in maint, thanks a lot!

-- 
 Bastien


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

end of thread, other threads:[~2021-05-04 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-03 22:22 Bug: sqlite output truncated? learn orchids
2021-05-03 23:32 ` Nick Savage
2021-05-04 20:42 ` [PATCH] Fix truncated output in ob-sqlite.el (Was: Bug: sqlite output truncated?) Nick Savage
2021-05-04 20:44   ` [PATCH] Fix truncated output in ob-sqlite.el Bastien

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).