After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 329488 - Sqlite 2 versus 3 runtime and upgrade issues
Sqlite 2 versus 3 runtime and upgrade issues
Status: RESOLVED FIXED
Product: f-spot
Classification: Other
Component: General
CVS
Other Linux
: Normal major
: ---
Assigned To: F-spot maintainers
F-spot maintainers
: 333494 333550 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2006-02-01 17:02 UTC by Christopher Aillon
Modified: 2006-12-02 00:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch to detect sqlite version (1.18 KB, patch)
2006-03-06 19:29 UTC, Larry Ewing
committed Details | Review

Description Christopher Aillon 2006-02-01 17:02:37 UTC
Its possible to build f-spot against either sqlite 2.x or >= 3.3 but we need to make sure that connections are made against the DB version compiled with (to protect against cases where both are installed).  switching at runtime based on which dbs are present on the system is bad.
Comment 1 Gabriel Burt 2006-02-14 06:31:15 UTC
This issue is more complex than this, since we also need to support users who started using f-spot when they ran sqlite2 and now only have sqlite3 installed.  The only way to convert the databases is to have both installed and dump from 2 into 3.

So instead of always using the sqlite db installed, if 3 is detected, it should be used and any existing version 2 db's converted as sqlite2 will probably be removed of the user's machine sometime in the future.

As it is right now, F-Spot will simply not handle any of these cases well at all.
Comment 2 Larry Ewing 2006-02-17 22:02:47 UTC
I think the solution to the upgrade problem is going to have involve distributions shipping a static binary sqlite2dump program that is required for upgrading or something similar
Comment 3 Christopher Aillon 2006-02-18 09:51:23 UTC
Yeah, the upgrade thing is a separate issue.  Not all distros shipped sqlite version 2 anyway (we did for a brief period in rawhide, but it never made a final release).  I'm mostly concerned with building against sqlite 3, having sqlite 3 as a dependency, and the user installing sqlite 2.  We should never use sqlite 2 in that situation (explicitly use sqlite version 3).
Comment 4 Christopher Aillon 2006-02-18 09:53:59 UTC
In Db.cs,  sqlite_connection.ConnectionString should be updated to have version info.  E.g.: 

sqlite_connection.ConnectionString = "URI=file:" + path + ",version=3";

(hack we're using in Fedora)
Comment 5 Larry Ewing 2006-02-25 07:51:25 UTC
is there any way to tell from the file what version it is?  we don't want to make an error the other way and force loading version 3 if the db is version 2 either.
Comment 6 Christopher Aillon 2006-02-26 08:22:13 UTC
running file seems to have version info (i don't have an sqlite2 db around to verify that with).

% file ~/.gnome2/f-spot/photos.db
/home/caillon/.gnome2/f-spot/photos.db: SQLite database (Version 3)

So I imagine there is some way, but it should be insignificant if we use the right version, and dependencies prevent the required sqlite version from being removed.
Comment 7 Gabriel Burt 2006-03-06 05:21:01 UTC
*** Bug 333494 has been marked as a duplicate of this bug. ***
Comment 8 Gabriel Burt 2006-03-06 05:22:18 UTC
*** Bug 333550 has been marked as a duplicate of this bug. ***
Comment 9 Larry Ewing 2006-03-06 18:11:29 UTC
ok a quick peek at shared-mime-info shows



 <mime-type type="application/x-sqlite2">
    <_comment>SQLite2 database</_comment>
    <magic>
      <match type="string" value="** This file contains an SQLite" offset="0"/>
    </magic>
  </mime-type>
  <mime-type type="application/x-sqlite3">
    <_comment>SQLite3 database</_comment>
    <magic>
      <match type="string" value="SQLite format 3" offset="0"/>
    </magic>
  </mime-type>

which means it should be pretty simple to detect the type ourselves
Comment 10 Larry Ewing 2006-03-06 19:12:15 UTC
does version=2 work to force a version 2 connection?
Comment 11 Gabriel Burt 2006-03-06 19:18:07 UTC
Version=3,URI=... is what Aaron uses for banshee (though it's probably not case sensitive).
Comment 12 Christopher Aillon 2006-03-06 19:20:46 UTC
Yes, beagle uses SQLITE_MAJ_VER.  See http://cvs.gnome.org/viewcvs/beagle/Util/ExternalStringsHack.cs.in?rev=1.8&view=markup
Comment 13 Larry Ewing 2006-03-06 19:29:47 UTC
Created attachment 60784 [details] [review]
patch to detect sqlite version

this patch should hopefully make the connection string match the version of the file.  Does this solve the downgrade problem?
Comment 14 Larry Ewing 2006-03-06 19:35:14 UTC
I think the only problem that remains with this patch if if someone installs sqlite2 before running f-spot for the first time they'll end up with an sqlite2 db (if I understand the mono binding issue) but I think we can probably live with that.
Comment 15 Christopher Aillon 2006-03-06 19:35:38 UTC
The main issue I have with this approach is that you are assuming that because there is an sqlite 2 file around, the user still has sqlite 2 around.  That is not necessarily the case.  It should default to whatever the package is built to use.

Additionally, I don't believe it solves the issue where:

sqlite 2 and 3 are installed.  The package was built to use sqlite 3.  In this case, it will erroneously default to sqlite version 2.
Comment 16 Larry Ewing 2006-03-06 19:36:11 UTC
I think the only problem that remains with this patch if (ignoreing how gross it is) is that if someone installs sqlite2 before running f-spot for the first time they'll end up with an sqlite2 db (if I understand the mono binding issue) but I think we can probably live with that.
Comment 17 Christopher Aillon 2006-03-06 19:37:39 UTC
(In reply to comment #14)
> I think the only problem that remains with this patch if if someone installs
> sqlite2 before running f-spot for the first time they'll end up with an sqlite2
> db (if I understand the mono binding issue) but I think we can probably live
> with that.

That will make life hard for distributors who need to figure out package dependencies.
Comment 18 Ryan Hayle 2006-03-06 19:40:53 UTC
Why can't you just _require_ sqlite3, and force any users with sqlite2 photos.db files lying around to convert them?  The conversion process is simple and worked flawlessly for me.
Comment 19 Larry Ewing 2006-03-06 19:43:44 UTC
If it defaults to whatever the package is built with then people upgrading will be completely out of luck.  Unless you have a plan that solves that I'm not sure what you suggest is any better.
Comment 20 Larry Ewing 2006-03-06 19:46:03 UTC
Ryan because converting them requires you to have both sqlite2 and sqlite3 installed, there is no way to convert versions with just sqlite3 installed is there?
Comment 21 Larry Ewing 2006-03-06 19:48:44 UTC
Other distributors have already shipped f-spot with version two, which means requiring version3 would break every existing f-spot install on those distributions.
Comment 22 Christopher Aillon 2006-03-06 19:50:42 UTC
(In reply to comment #19)
> If it defaults to whatever the package is built with then people upgrading will
> be completely out of luck.

That's IMO more of a problem for packagers to solve.  The problem is that sqlite 2's threading model is broken to hell to begin with, and never should have been enabled in 2.x, so people using sqlite 2 are already losing.  We've had a few reports of broken behavior with stuff that went away when the new threading stuff went in.  We should make them convert.  I agree with Ryan that sqlite 3 is a much better proposition.
Comment 23 Ryan Hayle 2006-03-06 19:53:17 UTC
If someone has an sqlite2 db, then they already have sqlite2 installed, so the next version of f-spot that requires sqlite3 would install it, then they'd have both installed and the upgrade would be simple.  You could put a big fat warning in the release notes.  I don't know any way around this and it's undoubtedly going to cause problems for users who don't read the release notes after an upgrade, however it seems like it has to be done -some- time, so better sooner rather than later. :)
Comment 24 Christopher Aillon 2006-03-06 19:54:29 UTC
I'll also note that that beagle also does it based on what the package was compiled with.
Comment 25 Larry Ewing 2006-03-06 20:09:01 UTC
callion: beagle's index doesn't hold anything that can't be regenerated by reindexing the files, so throwing away the db on upgrade isn't a problem.  Banshee  has a little bit of extra info but not much.  F-Spot has tags and descriptions that can't in some cases (and weren't in all cases until recently) written to the file so discarding is a lot less than ideal.  Also f-spot is careful about the threading so that is a nonissue in this case.

I don't see how working if you have both versions installed makes things harder for the distribution.  If sqlite2 isn't installed you're in no worse shape.

ryan: unfortunately that isn't how it works.
Comment 26 Christopher Aillon 2006-03-06 20:41:09 UTC
At some point they are going to have to upgrade, anyway.  I can't imagine sqlite2 being supported for years on into the future (maybe I'm wrong).  Why not sooner rather than later?  It becomes a bigger problem in the future the longer sqlite2 is allowed to linger.
Comment 27 Larry Ewing 2006-03-07 13:27:53 UTC
yeah they'll definitely have to upgrade it is just the going from supported to completely broken with in a single release with a poor upgrade path that I'm trying to avoid.  On the other hand the latest mono changes seem to have broken things again so I may just go ahead and force things.
Comment 28 Bjørn Haagensen 2006-03-07 21:44:24 UTC
In my setup it is not enough to convert/force creation of photos.db as sqlite3. I renamed libsqlite.so.0.8.6 and started f-spot. The resulting photos.db is v3.

bh@lifebook34:~/.gnome2/f-spot$ file photos.db
photos.db: SQLite database (Version 3)

Everything works like a charm until I rerename libsqlite to its original name. Launching f-spot then results in:

An unhandled exception was thrown: file is encrypted or is not a database

in <0x000ab> Mono.Data.SqliteClient.SqliteConnection:Open ()
in <0x0009d> Db:Init (System.String path, Boolean create_if_missing)
in <0x0008d> FSpot.Core:.ctor ()
in <0x0037a> FSpot.Driver:Main (System.String[] args)
.NET Version: 1.1.4322.2032

Same thing happends if I convert. I originally filed in Bug 333494 which is fixed if I stay purely with sqlite3. Is there any way of forcing sqlite3? 


Comment 29 Andrew Mitchell 2006-03-09 00:14:22 UTC
I'm going to work on a patch this weekend which will dump & reload the database to convert from sqlite 2 to 3, if it detects that photos.db is sqlite 2. This will require that both libraries be installed, but it's a reasonable assumption that if the user has an sqlite 2 db, they will still have the library available to use.
Comment 30 Christopher Aillon 2006-03-09 03:58:16 UTC
Why is that a reasonable assumption?  Distributors tend to upgrade libraries.  We shipped sqlite (version 3) and an sqlite2 package for mono.  I did the packaging work to make sure that our mono packages were updated to use sqlite 3.  When the conversion was done, we removed sqlite2 from Core.  Users can re-install sqlite2 if they absolutely need for other apps, but it was broken anyway, which is why we wanted to get rid of it.  :)

This all happened in a day, and I imagine there's room for other distros to do similar things.
Comment 31 Andrew Mitchell 2006-03-09 04:05:47 UTC
Then in removing the sqlite2 libraries, you only give users the option of wiping their (sqlite2) photos.db & starting again. Could you give a better suggestion then of how this migration could work?
Comment 32 Ryan Hayle 2006-03-09 07:11:54 UTC
I don't know of any distributions that actually *removes* packages automatically for the user without asking them, but even if they exist I think it should be up to the packager to warn & instruct users of the appropriate course of action if they want to convert their old data upon upgrading.  As long as f-spot provides the functionality to convert to sqlite3, there's nothing more it can do.
Comment 33 Christopher Aillon 2006-03-09 14:31:22 UTC
Sure you do.  Any rpm based distro removes packages.  That's what rpm -U does.  Additionally, any time there is a conflicts: or obsoletes: line in an rpm, dependency resolvers figure that out and remove the appropriate packages.  That has to work, else the packagers and you, the packager user, are screwed.
Comment 34 Ryan Hayle 2006-03-09 14:53:17 UTC
Okay I guess you caught me, I didn't know rpm did that automatically when upgrading (non-conflicting) packages.  I'll add that to my list of reasons for hating rpm-based distros so much. :-P  Of course if f-spot is marked as conflciting with sqlite2 it should -ask- to remove sqlite2, but that's not the case here.

If you're that paranoid about upsetting users who will have to upgrade you could just depend on both sqlite versions for a year or so, but it really seems like hand-holding when they can just read a note on how to upgrade in a README file like every other package I've ever installed.
Comment 35 Gabriel Burt 2006-03-10 06:11:11 UTC
F-Spot is written to be usable by most anybody.  It's an end-user application, not a developer's application.

If F-Spot detects a version 2 database and can't open it because sqlite2 is no longer installed, it should ideally pop up a dialog explaning to the user exactly how to upgrade it (by installing sqlite2 and re-runing f-spot).  Or we could have a website that would run their db through a CGI program and convert it for them. :)  Hmm, I actually like that idea a lot.

We need to have F-Spot convert databases from 2 to 3 now if it can.  I know I have both installed at the moment, but I probably won't for long.

I think we also shouldn't allow any new sqlite2 databases to be created, period.  Sqlite3 should be required.

#28: yes, we can force version=3.
Comment 36 Andrew Mitchell 2006-03-10 06:53:27 UTC
Which is why I think I'll just do a simple forced-conversion patch to dump & reload if it sees an sqlite 2 DB - I think that it should save a copy as photos.db.2 or similar in case it doesn't quite work properly. 
Comment 37 Bengt Thuree 2006-05-17 15:22:23 UTC
Has this issue been resolved? Quite some time since last entry here, and I think SQLite3 is coming close and closer or?
Comment 38 Larry Ewing 2006-12-02 00:22:38 UTC
yeah I consider this resolved now, upgrades are manual, f-spot with automatically work with existing 2 or 3 and tries version3 by default.