Closed jacobleft closed 12 months ago
I am having the same issue and I'm wondering (given that changes in BBT repeatedly broke Zothero) whether it might be an idea to switch from accessing Zotero via BetterBibtex to accessing the Zotero API. Then again, it would probably require a major rewrite of the workflow...
@jacobleft how do you check the current betterBibtex version? I updated Zotero and Zothero it is still working for me (I don't use either, so I might be missing something).
I am on Zotero 7-beta.
Click Tools
->Add-ons
, find Better BibTex, click ...
-> Manage
, then you see the version.
But I am curious. Why maintain this repo if you don't use it?
Yes, it seems it's due to the new Better BibTeX, as the beta itself did not change the database and works fine. I will try to fix it, but I suspect this will break Zothero for non-beta users. @tophee using the API will not help because I understand Zotero (inexplicably!?) does not support citekeys natively. As for my motivation: just trying to keep a great workflow alive! If you use BIbTeX there is a great alternative in the Gallery.
Yes that error message comes directly from trying to open the Better BibTeX sqlite database in the newer version. Hopefully the developer will fix soon
Does this mean that downgrading to an earlier version of BetterBibtex would solve the issue?
I seem to remember that I had to do exactly that a while ago to resolve a similar issue. Maybe we should just turn off automatic updates for BetterBibtex?
Zotero (inexplicably!?) does not support citekeys natively.
Oh, right, now I understand why everyone is going via BetterBibTeX.
But just to double check: isn't it sufficient that betterbibtex creates and manages the citekeys but once they are stored in the zotero database, they can be accessed without BetterBibteX? - Oh, or is there no api-support for that, perhaps?
In that case accessing the sqlite database locally would probably be the way to go.
yes, a previous version (I tried 6.7.71) works (but in Zotero 6, not 7 beta). Yes, Zothero uses the sqlite databases created by Zotero/Better BibTeX. In theory you can use them without Better BibTeX, assuming that you don't need to update your library.
@giovannicoppola You are the real hero. I can confirm ZotHero used to work on (old?) 7-beta with old betterbibtex. It just does not work with the latest of both.
Oh, that sqlite db is created by BBT! Learning so much today...
I'm so glad I found this thread. Now I know that it's not my fautl ;)
@tophee's idea should work as a temporary workaround, again provided that you don't need to update your library:
The database schema for auto-exports did change, and another change is slated for the citation key database.
Hi, all - just FYI, if you haven't updated to Zotero 7, it's possible to just downgrade to BBT (I used 6.7.71 via Zotero tools/addons/install add on from file). There's a "corrupt database" error message, but reloading Zotero data via zotconf seems to have resolved all issues with the workflow for now.
There should be no need to downgrade all the way back to .71, 6.7.125 introduced the schema change. Please don't encourage people to downgrade that far back. Zero support on such old versions.
Apps that read or write the database directly are going to have to change. The citationkey database (which zothero does read) is set to change too. I will see if I can prepare a PR for zothero.
Untested but this should work:
diff --git a/src/lib/zothero/betterbibtex.py b/src/lib/zothero/betterbibtex.py
index df9f23a..eee83ec 100644
--- a/src/lib/zothero/betterbibtex.py
+++ b/src/lib/zothero/betterbibtex.py
@@ -16,9 +16,6 @@ from .util import timed
log = logging.getLogger(__name__)
-SQL = "SELECT data FROM `better-bibtex` WHERE name = 'better-bibtex.citekey';"
-
-
class BetterBibTex(object):
"""Read citkeys from BetterBibTex database.
@@ -47,15 +44,14 @@ class BetterBibTex(object):
return
- conn = sqlite3.connect(dbpath)
+ conn = sqlite3.connect(':memory:')
+ conn.execute('ATTACH DATABASE ? AS betterbibtex', dbpath)
with timed('load Better Bibtex data'):
- row = conn.execute(SQL).fetchone()
- data = json.loads(row[0])['data']
self._refkeys = {
- str(ck['libraryID']) + '_' + ck['itemKey']: ck['citekey']
- for ck in data
+ str(ck['libraryID']) + '_' + ck['itemKey']: ck['citationKey']
+ for c in conn.execute('select * from betterbibtex.citationkey')
}
self.exists = True
Hi, all - just FYI, if you haven't updated to Zotero 7, it's possible to just downgrade to BBT (I used 6.7.71 via Zotero tools/addons/install add on from file). There's a "corrupt database" error message, but reloading Zotero data via zotconf seems to have resolved all issues with the workflow for now.
Which Zotero will undo within 48 hours by finding a newer BBT and installing that automatically. Please apply the patch to Zothero.
@retorquere thanks for the patch. But would you give me some guidance on how to apply the patch?
I am a noob/beginner, but I was wondering if I should simply replace the code in the betterbibtex.py by the one you put.
If so, would you tell me which one of code blocks should I use?
Sorry again if the answer is obvious!
No, those are targeted changes, you can't replace the whole file. The author of this program will have to get involved.
I am a noob/beginner, but I was wondering if I should simply replace the code in the betterbibtex.py by the one you put.
If so, would you tell me which one of code blocks should I use?
Every line that starts with -
should be removed, every line that starts with +
should be added. The other lines provide context on where to make these changes.
switch from accessing Zotero via BetterBibtex to accessing the Zotero API
The zotero API does not have these citation keys.
Untested but this should work:
diff --git a/src/lib/zothero/betterbibtex.py b/src/lib/zothero/betterbibtex.py index df9f23a..eee83ec 100644 --- a/src/lib/zothero/betterbibtex.py +++ b/src/lib/zothero/betterbibtex.py @@ -16,9 +16,6 @@ from .util import timed log = logging.getLogger(__name__) -SQL = "SELECT data FROM `better-bibtex` WHERE name = 'better-bibtex.citekey';" - - class BetterBibTex(object): """Read citkeys from BetterBibTex database. @@ -47,15 +44,14 @@ class BetterBibTex(object): return - conn = sqlite3.connect(dbpath) + conn = sqlite3.connect(':memory:') + conn.execute('ATTACH DATABASE ? AS betterbibtex', dbpath) with timed('load Better Bibtex data'): - row = conn.execute(SQL).fetchone() - data = json.loads(row[0])['data'] self._refkeys = { - str(ck['libraryID']) + '_' + ck['itemKey']: ck['citekey'] - for ck in data + str(ck['libraryID']) + '_' + ck['itemKey']: ck['citationKey'] + for c in conn.execute('select * from betterbibtex.citationkey') } self.exists = True
Thank you so much for the solution!
I have to do a bit adjustments to make it work:
conn.row_factory = sqlite3.Row
to access the data in row using str as indices. Iterating conn.execute('select ...') would return tuples otherwise.dbpath
with parentheses and a comma (like (dbpath, )
) to expand the argument correctly into the sql command.for ck in conn.execute('select * from betterbibtex.citationkey')
instead of for c in ...
. This might be a typo.The whole __init__
method now looks like this:
def __init__(self, datadir):
"""Load Better Bibtex database from Zotero data directory.
Args:
datadir (unicode, optional): Zotero's data directory.
Raises:
RuntimeError: Raised if Better Bibtex database doesn't exist.
"""
self._refkeys = {}
self.exists = False
#dbpath = os.path.join(datadir, 'better-bibtex.sqlite')
dbpath = datadir
if not os.path.exists(dbpath):
return
conn = sqlite3.connect(':memory:')
conn.row_factory = sqlite3.Row
conn.execute('ATTACH DATABASE ? AS betterbibtex', (dbpath, ))
with timed('load Better Bibtex data'):
# for ck in conn.execute('select * from betterbibtex.citationkey'):
# print(ck)
self._refkeys = {
str(ck['libraryID']) + '_' + ck['itemKey']: ck['citationKey']
for ck in conn.execute('select * from betterbibtex.citationkey')
}
self.exists = True
Now everything works like a charm.
Hope this can help you guys.
thanks @fty1777! If you want to send me a PR I will be happy to incorporate, or I can just make the edits.
thanks @fty1777! If you want to send me a PR I will be happy to incorporate, or I can just make the edits.
This might break the support for previous versions of Zotero/BetterBibtex and I am not familiar with how to deal with such multi-version supporting stuff. Or we may just drop the support for out-dated versions and apply the changes directly? The changes I did are trivial and it would be nice if you could make these edits. Thanks again to @giovannicoppola and you @retorquere for your fabulous work.
I can tell you how you recognize old or new schema. It's not really hard to support both.
That's great! I'm very happy if I can help!
You issue
SELECT COUNT(*) FROM betterbibtex.sqlite_master WHERE type='table' AND name = 'citationkey'
If that returns 1
, you have the new database (get the keys from betterbibtex.citationkey
), if it returns 0
you have the old database (get the keys from betterbibtex."better-bibtex"
).
You issue
SELECT COUNT(*) FROM betterbibtex.sqlite_master WHERE type='table' AND name = 'citationkey'
If that returns
1
, you have the new database (get the keys frombetterbibtex.citationkey
), if it returns0
you have the old database (get the keys frombetterbibtex."better-bibtex"
).
Thanks! I will give it a try.
thanks @fty1777 and @retorquere. I merged the pull request and released version 2.2 which should fix this.
I am experiencing this error from
zothero
.Reload Zotero Data
can not fix this. I suspect the cause is that it is incompatible with the last version ofbetterbibtex
, which is 6.7.128 as of today.