sqlitebrowser icon indicating copy to clipboard operation
sqlitebrowser copied to clipboard

JSON1 Extension still unavailable under Ubuntu / Linux Mint

Open MartinHaeusler opened this issue 5 years ago • 36 comments

I'm trying to execute a query using JSON1 in SQLite Browser under Linux Mint, however the extension seems to be missing in this binary.

Details for the issue

What did you do?

I just tried the nightly release on Linux Mint 20 with the following commands:

  • sudo add-apt-repository -y ppa:linuxgndu/sqlitebrowser-testing
  • sudo apt-get update
  • sudo apt-get install sqlitebrowser

This gives me the following version in the "About" dialog: DB Browser for SQLite Version 3.12.99 (Oct 10 2020)

What did you expect to see?

For example, the basic query:

SELECT json_extract(json('{"greeting": "hello"}'), '$.greeting')

... should work.

What did you see instead?

The example query above produces the following error:

Execution finished with errors.
Result: no such function: json
At line 1:
SELECT json_extract(json('{"greeting": "hello"}'), '$.greeting')

Useful extra information

The info below often helps, please fill it out if you're able to. :)

What operating system are you using?

  • [ ] Windows: ( version: ___ )
  • [x] Linux: (Mint 20 )
  • [ ] macOS: ( version: ___ )
  • [ ] Other: ___

MartinHaeusler avatar Oct 13 '20 14:10 MartinHaeusler

The extension isn't compiled statically into the application - you'd have to load it via 'Tools' and 'Load extension'. It would also need creating, as its not currently available in our packages. I've had a quick look around, but many sources just say, "compile it yourself" which isn't helpful...

chrisjlocke avatar Oct 13 '20 14:10 chrisjlocke

I just compile JSON1 extension for you. You can load the below file from the 'Preferences' and use it. At least it works fine on my Ubuntu 20.04.1 PC and DB4S's latest nightly build.

DOWNLOAD LINK REMOVED

  • MD5SUM: 6a5166245d1b2609d6b61996bdd9ae39
  • SHA256: dab4a626be23514f75485ce77d5959f53e2dfa966011f156985d40941996a820

lucydodo avatar Oct 13 '20 14:10 lucydodo

It's odd that the extension isn't enabled by default on linux. I know for a fact that in the windows version, the JSON1 extension is enabled by default because my co-workers use it.

MartinHaeusler avatar Oct 13 '20 14:10 MartinHaeusler

@lucydodo I just tried it, sorry but my SQLite crashes immediately (without any error message, the window just closes) when I try to add that extension file...

MartinHaeusler avatar Oct 13 '20 14:10 MartinHaeusler

The extension isn't compiled statically into the application - you'd have to load it via 'Tools' and 'Load extension'. It would also need creating, as its not currently available in our packages. I've had a quick look around, but many sources just say, "compile it yourself" which isn't helpful...

@chrisjlocke We include the JSON1 extension (built in) to our Windows and macOS builds:

https://github.com/sqlitebrowser/sqlitebrowser/blob/1c0cf443b55e3a06e0c948db7ba6ece50eec278e/installer/windows/nightly_build_scripts/win64build.bat#L70

We probably just need to add the same options to the Linux build process. @deepsidhu1313 would you be ok to try adding them? It's probably just a matter of using the same compile options for the build. Something like:

<compiler> sqlite3.c -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_STAT4 -DSQLITE_SOUNDEX -DSQLITE_ENABLE_JSON1 -DSQLITE_ENABLE_GEOPOLY -DSQLITE_ENABLE_RTREE -DSQLITE_MAX_ATTACHED=125

The "<compiler>" thing there being (eg) gcc or whatever is currently being used. Hopefully that works. :smile:

justinclift avatar Oct 13 '20 14:10 justinclift

If there's a way to enable JSON1 by default on linux, please enable it. It would make my daily work that much easier.

MartinHaeusler avatar Oct 13 '20 15:10 MartinHaeusler

No worries. @deepsidhu1313 is the creator of our Linux packages, so lets see if the extension can be added to them. :smile:

justinclift avatar Oct 13 '20 15:10 justinclift

@justinclift Can you tell me what extensions are currently built-in to DB4S? It would be nice to add information about this to the wiki. :smile:

lucydodo avatar Oct 15 '20 12:10 lucydodo

Quick question, to enable json1 support do we need set flag while building DB4S or sqlite ?

deepsidhu1313 avatar Oct 15 '20 13:10 deepsidhu1313

Theoretically, when building SQLite. Specifically, "Add the -DSQLITE_ENABLE_JSON1 compile-time option to enable the json1 extension that is built into the amalgamation. The json1 source code is included with the SQLite amalgamation, though it is disabled by default."

chrisjlocke avatar Oct 15 '20 13:10 chrisjlocke

Oops. Yeah, that's why I was pointing to the compile line above. Forgot I should probably explain it a bit better.

Each of those options in the compile line above are explained here:

    https://www.sqlite.org/compile.html

So:

  • -DSQLITE_ENABLE_FTS5 enables the FTS5 extension
  • -DSQLITE_ENABLE_FTS3 enables the FTS3 extension
  • etc...

Thanks @chrisjlocke. :smile:

justinclift avatar Oct 15 '20 15:10 justinclift

I have to check if default sqlite packages are built with these flags, otherwise we have to compile our own

deepsidhu1313 avatar Oct 15 '20 15:10 deepsidhu1313

Hey folks, I've just acquired SQLite Browser 3.12.0 from https://launchpad.net/~linuxgndu/+archive/ubuntu/sqlitebrowser using Ubuntu 20.10 and it still doesn't include the JSON1 extension... This is unfortunately still an issue.

MartinHaeusler avatar Feb 10 '21 11:02 MartinHaeusler

Ahhh well. I suppose the only foolproof method that's likely to be timely is compiling the code yourself.

Is that something you're ok with?

You'd likely need to compile SQLite itself (eg with the JSON extension), then compile SQLite Browser using that SQLite.

We have instructions for Ubuntu for compiling the SQLite Browser piece, if that's helpful?

    https://github.com/sqlitebrowser/sqlitebrowser/blob/master/BUILDING.md#ubuntu--debian-linux


There's some further info about compiling with a custom SQLite, for Ubuntu, that's likely relevant:

    https://github.com/sqlitebrowser/sqlitebrowser/wiki/Compiling-DB4S-on-Ubuntu-To-Use-A-Pre-Installed-Version-of-SQLite

justinclift avatar Feb 10 '21 12:02 justinclift

I'm not really all that comfortable with compiling native binaries to be honest. Those things tend to go wrong in all sorts of ways (wrong library versions etc.). My short-term solution currently is to use another SQL UI tool (their SQLite binary apparently had the extension by default), but I'd still prefer the SQLite browser.

MartinHaeusler avatar Feb 10 '21 13:02 MartinHaeusler

No worries at all. :smile:

@deepsidhu1313 Hopefully you have some time to look at this at some point. Another approach might be to ask the Ubuntu SQLite packaging people if they'd be ok to include most/all of the optional SQLite extensions that are in the SQLite tarball. They'd just need to add the -Dxxxxx options (like in our Windows build). :smile:

justinclift avatar Feb 10 '21 14:02 justinclift

Sure, i can build some binaries on testing ppa over weekend. Can someone please provide me details how to test this issue, so that I don’t miss anything ? I was pretty much sure it was solved. But may be i missed something.

Thanks

deepsidhu1313 avatar Feb 10 '21 19:02 deepsidhu1313

How to test:

  • open any sqlite db in the browser
  • open the sql editor
  • run the following query: select json('{}')

If you don't get an error running the query, the extension works.

MartinHaeusler avatar Feb 10 '21 22:02 MartinHaeusler

@MartinHaeusler apologies for taking some time to investigate the issue. I ran the query you mentioned and got the following results

image image

Something broke the package 3.12.0. Did we change anything special in 3.12 ?

deepsidhu1313 avatar Mar 01 '21 05:03 deepsidhu1313

@deepsidhu1313 That screenshot seems to be for the older 3.11.2 release, and it seems to be ok. eg it does include the JSON1 extension.

So, in theory (!) the same approach for building that should work for building the 3.12.1 release with the JSON1 extension.

justinclift avatar Mar 01 '21 12:03 justinclift

I have this flag enabled for both sqlitebrowser and sqlcipher package.

https://github.com/deepsidhu1313/sqlitebrowser-deb-packaging/blob/master/debian/rules

https://github.com/deepsidhu1313/sqlcipher_deb_packaging/blob/master/debian/rules

Am I missing any flag or do I need to compile SQLite with this option? Is there a way in our make step to know if sqlite or sqlcipher which is being used to build sqlitebrowser supports JSON?

deepsidhu1313 avatar Mar 02 '21 04:03 deepsidhu1313

or did something happened with ubuntu's SQLite package?

image

deepsidhu1313 avatar Mar 02 '21 04:03 deepsidhu1313

Ahhh, interesting. That's a flag used when compiling SQLite and SQLCipher, and doesn't do anything for the DB4S package build.

DB4S just needs to be built with SQLite or SQLCipher that had the extension enabled for its build.

It seems like whichever SQLite or SQLCipher library is being used when testing, it's not one with that flag enabled.

Maybe the DB4S install is just picking up the wrong library when it's being run?

justinclift avatar Mar 02 '21 05:03 justinclift

should we look into standardizing sqlite and sqlcipher version and build flags to be used across all platforms? it seems like windows builds are using different flags than Linux one.

deepsidhu1313 avatar Mar 04 '21 14:03 deepsidhu1313

Yeah, the Linux one should probably use the same flags as the Windows one. :smile:

justinclift avatar Mar 04 '21 22:03 justinclift

I have created new ppa for sqlite3 and added some extra cc flags to align with windows builds. May i request someone to peer review the cc flags?! I have kept cc flags that are being used by original debian packaging.

https://github.com/deepsidhu1313/sqlite_deb_packaging/commit/f3899094852002b2a579df2cabc80dec93c00702

New ppa link for sqlite_daily packages. once we build sqlite with json support, i will try to build sqlcipher with json support and then DB4S.

deepsidhu1313 avatar Mar 08 '21 01:03 deepsidhu1313

@deepsidhu1313 Looking over the list, it seems to include all the same pieces we have in the Windows and macOS builds. :smile:

There is one aspect I'm not sure of though. Some of the -D options have a =1 on the end. I'm guessing you're trying to give them a value, like in key/value lookups? eg:

  • -DSQLITE_ENABLE_JSON1=1
  • -DSQLITE_ENABLE_RTREE=1
  • -DSQLITE_SOUNDEX=1

There are some SQLite defines that can take values, but those three don't seem to:

  • JSON1 → https://www.sqlite.com/compile.html#enable_json1
  • R*Tree → https://www.sqlite.com/compile.html#enable_rtree
  • Soundex → https://www.sqlite.com/compile.html#soundex

Not sure if it'll really hurt anything though. :smile:

justinclift avatar Mar 09 '21 04:03 justinclift

so finally able to figure out why sqlite3 version i was using, was not recognizing json* functions :confused: . My machine was picking up sqlite3 from android packaging tool. This thing was driving me nuts from last few weeks :angry:. so finally was able to fix and test json support in sqlite and sqlcipher :smile: . Will spend some time testing sqlitebrowser nightly packages .

deepsidhu1313 avatar Mar 13 '21 23:03 deepsidhu1313

@deepsidhu1313 Good stuff. :smile:

Sounds like that was a royal pain in the arse to figure out too. :frowning_face:

justinclift avatar Mar 14 '21 02:03 justinclift

Finally issue is resolved in latest build on nightly repo. Please verify with 3.12.1-3~3036* build. I would love someone to confirm the package is working for all before i push it to stable repo.

deepsidhu1313 avatar Mar 14 '21 03:03 deepsidhu1313