Adding a new type to an SQLite DB

83 views
Skip to first unread message

weather list

unread,
Apr 16, 2021, 5:54:19 PM4/16/21
to weewx...@googlegroups.com
From the WeeWx docs:

Adding a new type to an existing database

Here's how you would add the observation type electricity (from the example Adding a second data source) to an existing database by using wee_database:

wee_database --add-column=electricity

But if I want to specify **which** .sdb file can I do:

wee_database --add-column=mynewcolumn --config=another.sdb (which already exists).

WeeWx 4.4.1
Python 3.7
Raspian Desktop Buster

vince

unread,
Apr 16, 2021, 5:58:00 PM4/16/21
to weewx-user
(untested but...) see if the --binding option gets you what you're looking for, if you're asking how to add column(s) to a secondary database other than the default one.

weather list

unread,
Apr 19, 2021, 2:38:54 PM4/19/21
to weewx...@googlegroups.com
I am asking just that but I can’t see how —binding might work

When I installed the Envoy drive, it still uses wx_binding when in creates envoy.sdb

So I tried:

In /home/weewx:

sudo bin/wee_database --add-column=energy_total --config=archive/envoy.sdb

And it throws an error:

wee_database: error: no such option: --add-column

--
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/961ff186-7efa-4306-9e21-4fa6c505e9e2n%40googlegroups.com.

vince

unread,
Apr 19, 2021, 3:57:32 PM4/19/21
to weewx-user
Your weewx is too old.  You need to update to 4.5.0 or later according to the release notes at https://github.com/weewx/weewx/releases

Graham Eddy

unread,
Apr 19, 2021, 8:12:53 PM4/19/21
to weewx...@googlegroups.com
and —config takes a weewx.conf (not a weewx.sdb) as its arg

Tom Keffer

unread,
Apr 19, 2021, 8:13:31 PM4/19/21
to weewx-user
Vince is right that you need V4.5.

But, your command is also wrong. Review the docs for wee_database

The --config option selects a configuration file, such as weewx.conf, not a database. 

The --binding option selects the binding. By default, it uses the binding wx_binding.

So, if you want to use a second database, such as envoy.sdb, it must first be listed as a binding. For example,

[DataBindings]
   
    [[envoy_binding]]
        # The database must match one of the sections in [Databases].
        # This is likely to be the only option you would want to change.
        database = envoy_sqlite
        # The name of the table within the database
        table_name = archive
        # The manager handles aggregation of data for historical summaries
        manager = weewx.wxmanager.WXDaySummaryManager
        # The schema defines the structure of the database.
        # It is *only* used when the database is created.
        schema = schemas.wview_extended.schema

[Databases]
   
    # A SQLite database is simply a single file
    [[envoy_sqlite]]
        database_name = envoy.sdb
        database_type = SQLite
    
This sets up a new binding envoy_binding, which uses envoy.sdb. Now you can add a new column to the new binding:

wee_database --add-column=mynewcolumn --binding=envoy_binding



weather list

unread,
Apr 19, 2021, 8:21:11 PM4/19/21
to weewx...@googlegroups.com
Thanks. Upgrade to 4.5.1 went fine, but this command throws an error which puzzles me:

/home/weewx $ sudo bin/wee_database --add-column=energy_total --type=REAL --config=archive/envoy.sdb
Traceback (most recent call last):
  File "bin/wee_database", line 1138, in <module>
    main()
  File "bin/wee_database", line 186, in main
    config_path, config_dict = weecfg.read_config(options.config_path, args)
  File "/home/weewx/bin/weecfg/__init__.py", line 180, in read_config
    default_encoding='utf-8')
  File "/usr/lib/python3/dist-packages/configobj.py", line 1229, in __init__
    self._load(infile, configspec)
  File "/usr/lib/python3/dist-packages/configobj.py", line 1287, in _load
    content = self._handle_bom(content)
  File "/usr/lib/python3/dist-packages/configobj.py", line 1437, in _handle_bom
    r eturn self._decode(infile, self.encoding)
  File "/usr/lib/python3/dist-packages/configobj.py", line 1517, in _decode
    infile[i] = line.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 31: invalid start byte

Raspian Desktop Buster updated/upgraded
Intel NUC
WeeWx 4.5.1

weather list

unread,
Apr 19, 2021, 8:23:04 PM4/19/21
to weewx...@googlegroups.com
Ah good, makes sense indeed. Please ignore my last message with the error message.

Reply all
Reply to author
Forward
0 new messages