SQLITE More than binding for one database

49 views
Skip to first unread message

Karen K

unread,
Sep 2, 2021, 7:16:54 AM9/2/21
to weewx-user
Is it possible to have multiple sections in [DataBindings], that refer to the same database (and thus database file), but different table_names?

Like that:
[DataBindings]
    ...
    [[binding1]]
        data_base = xxx_sqlite
        table_name = table1
        ...
    [[binding2]]
        data_base = xxx_sqlite
        table_name = table2
        ...
[Databases]
    ...
    [[xxx_sqlite]]
        database_name = xxx.sdb
        database_type = SQLite

Tom Keffer

unread,
Sep 2, 2021, 8:39:27 AM9/2/21
to weewx-user
I've never tried it, but I don't see why it can't be done. 

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/a99f2ac9-7ea4-4754-aaa0-335c14455c4cn%40googlegroups.com.

Karen K

unread,
Sep 5, 2021, 12:54:32 PM9/5/21
to weewx-user
I now read through the code, and I am not sure. As I understood the code, each binding opens its own database connection. They do not only open a new cursor. So those database connections can compete, and I do not know what happens when they access the database file simultaneously. And as I cannot test it in a definite way, I will create different files.

Tom Keffer

unread,
Sep 5, 2021, 5:42:38 PM9/5/21
to weewx-user
I guess it all depends on your usage pattern. If you use WeeWX the normal way: writes are done by the main thread, while the reporting threads do only reads, it should not be a problem. Right now, many RESTful threads often read the same database file, indeed, the same database table, simultaneously without problem. 

OTOH, if you try to write from something other than the main thread, then you might get contention. Both the main thread and your thread could be seeking EXCLUSIVE locks, leading to writer starvation. 

-tk

Reply all
Reply to author
Forward
0 new messages