Issue: peewee OperationalError: no such function: json_set
Author: Quo00
State: closed
Created: 2018-07-13 09:40:01

Hello,

Peewee version is 3.5.2.

I'm trying to update a JSON value in-place and am following the documentation. I'm using an SqliteDatabase in memory.

I'm following the documentation very closesly:

```
>>> from playhouse.sqlite_ext import *
>>> db = SqliteExtDatabase(':memory:')
>>> class KV(Model):
...     key = TextField()
...     value = JSONField()
...     class Meta:
...         database = db
...

>>> KV.create_table()
```

`>>> KV.update(value=KV.value.update({'k2': 'v2'})).execute()`

However, I'm being returned with the following error:

```
Traceback (most recent call last):
  File "C:\Python36\lib\site-packages\peewee.py", line 2625, in execute_sql
    cursor.execute(sql, params or ())
sqlite3.OperationalError: no such function: json_set

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\system_checker_database_test.py", line 58, in <module>
    main()
  File ".\system_checker_database_test.py", line 42, in main
    KV.update(value=KV.value.update({'hi': 'hey'})).execute()
  File "C:\Python36\lib\site-packages\peewee.py", line 1560, in inner
    return method(self, database, *args, **kwargs)
  File "C:\Python36\lib\site-packages\peewee.py", line 1631, in execute
    return self._execute(database)
  File "C:\Python36\lib\site-packages\peewee.py", line 2049, in _execute
    cursor = database.execute(self)
  File "C:\Python36\lib\site-packages\peewee.py", line 2638, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "C:\Python36\lib\site-packages\peewee.py", line 2632, in execute_sql
    self.commit()
  File "C:\Python36\lib\site-packages\peewee.py", line 2424, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "C:\Python36\lib\site-packages\peewee.py", line 177, in reraise
    raise value.with_traceback(tb)
  File "C:\Python36\lib\site-packages\peewee.py", line 2625, in execute_sql
    cursor.execute(sql, params or ())
peewee.OperationalError: no such function: json_set
```

Any thoughts to this issue?

You need SQLite compiled with the `json1` extension. Apparently the SQLite you're using does not have it.

* https://sqlite.org/json1.html
* https://www.sqlite.org/compile.html#_options_to_enable_features_normally_turned_off

Hello @coleifer , I've tried to compile my own sqlite3.dll but it's still not working.

I'm following these instructions: https://www.sqlite.org/howtocompile.html#building_a_windows_dll

I download the sql-amalgamation-XXXX.zip and execute the following in MSVC: `cl sqlite3.c -DSQLITE_ENABLE_JSON1 -link -dll -out:sqlite3.dll`. I drop the compiled dll into C:\Python36\DLLs. Is this the location where I'm meant to be copying it to? 

After I run my peewee script, I'm now returned with a new error:

```
Traceback (most recent call last):
  File "system_checker_database_test.py", line 56, in <module>
    System.create_table()
  File "C:\Python36\lib\site-packages\peewee.py", line 5529, in create_table
    cls._schema.create_all(safe, **options)
  File "C:\Python36\lib\site-packages\peewee.py", line 4790, in create_all
    self.create_table(safe, **table_options)
  File "C:\Python36\lib\site-packages\peewee.py", line 4686, in create_table
    self.database.execute(self._create_table(safe=safe, **options))
  File "C:\Python36\lib\site-packages\peewee.py", line 2589, in execute
    return self.execute_sql(sql, params, commit=commit)
  File "C:\Python36\lib\site-packages\peewee.py", line 2574, in execute_sql
    cursor = self.cursor(commit)
  File "C:\Python36\lib\site-packages\peewee.py", line 2560, in cursor
    self.connect()
  File "C:\Python36\lib\site-packages\peewee.py", line 2523, in connect
    self._state.set_connection(self._connect())
  File "C:\Python36\lib\site-packages\peewee.py", line 2790, in _connect
    raise ImproperlyConfigured('SQLite driver not installed!')
peewee.ImproperlyConfigured: SQLite driver not installed!
```
I'm not doing something right, so I'm hoping someone here will know. Has anyone else compiled their own sqlite3.dll and executed JSON1 extensions using Peewee?

If you need any more information, please let me know.

EDIT:

I have tried import sqlite3 into a Python shell, but I was returned with the following traceback:

```
>>> import sqlite3
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python36\lib\sqlite3\__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "C:\Python36\lib\sqlite3\dbapi2.py", line 27, in <module>
    from _sqlite3 import *
ImportError: DLL load failed: %1 is not a valid Win32 application.
```

I compiled my sqlite3.dll in both 64-bit and 32-bit versions of MSVC, so I'm not really sure what I'm doing wrong.

The reason peewee is saying "SQLite driver not installed!" is because it cannot import the Python `sqlite3` module. You apparently did something wrong when building the SQLite library, since the standard lib `sqlite3` module links against the system sqlite.

@coleifer I fixed the issue by downloading the 32-bit version of Python. Now I need to figure out how to make a 64-bit  sqlite3.dll.