Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Word Strings get truncated on output #114

Closed
zardoz03 opened this issue Sep 23, 2023 · 2 comments
Closed

Multi-Word Strings get truncated on output #114

zardoz03 opened this issue Sep 23, 2023 · 2 comments

Comments

@zardoz03
Copy link

From executing an expression such as

(emacsql db 
 [:select [name sql]
  :from sqlite_schema 
  :where (like type '"table")])
;=>
((EXPENSE_TYPES CREATE)
 (TRANSACTIONS CREATE))

, the SQL column gets truncated to (table, create) on the output.
Whereas if i were to run

(sqlite-select (eieio-oref db 'handle)
               "select name, sql from sqlite_schema where type like \"table\"")
;=>
(("EXPENSE_TYPES"
   "CREATE TABLE EXPENSE_TYPES
      (id INT PRIMARY KEY, 
       expense TEXT)")
 ("TRANSACTIONS"
   "CREATE TABLE TRANSACTIONS (
          id INT PRIMARY KEY, 
          amount INT,
          debit INT CHECK (debit = 0 OR debit = 1),
          type INT,
          FOREIGN KEY (type) REFERENCES EXPENSE_TYPES (id),
          name TEXT   
     )"))

I get the full output of the table definition.

@tarsius
Copy link
Member

tarsius commented Sep 28, 2023

That is a consequence of the design decision commented on in this FAQ entry: https://github.com/magit/emacsql#why-are-all-values-stored-as-strings.

Since the metadata you are requesting here was not explicitly stored by EmacSQL itself, it wasn't printed, so when EmacSQL uses read on what it got from SQLite, then this happens: (read "CREATE TABLE EXPENSE_TYPES ...") => CREATE. EmacSQL cannot easily know that in that one case, it should not do that.

For the backend that uses built-in sqlite support, this happens in emacsql-send-message, for most other backends it happens in emacsql-parse.

I recommend, that for this one query, you fall back to a direct call to sqlite-select. Of course if you do not exclusively use the builtin backend, this will be more complicated.

@zardoz03
Copy link
Author

zardoz03 commented Oct 7, 2023

I knew it had to be a consequence of it mainly storing emacs pretty-printable values, but forgot about how READ truncates data. theres probably some way to wrap it as a "(list ...)" before passing it to READ but i fear that overcomplicates things further than trying to re-architect based on storing elisp values as a proper serialized object and supporting normal SQL data types.

@zardoz03 zardoz03 closed this as completed Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants