Merge lp:~midori/midori/databaseAttach into lp:midori

Proposed by Cris Dywan
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6551
Merged at revision: 6551
Proposed branch: lp:~midori/midori/databaseAttach
Merge into: lp:midori
Diff against target: 69 lines (+21/-7)
3 files modified
midori/midori-bookmarksdatabase.vala (+1/-2)
midori/midori-database.vala (+19/-4)
midori/midori-historydatabase.vala (+1/-1)
To merge this branch: bzr merge lp:~midori/midori/databaseAttach
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+203848@code.launchpad.net

Commit message

Implement Midori.Database.attach method

To post a comment you must log in.
Revision history for this message
Paweł Forysiuk (tuxator) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-bookmarksdatabase.vala'
2--- midori/midori-bookmarksdatabase.vala 2013-10-11 22:36:30 +0000
3+++ midori/midori-bookmarksdatabase.vala 2014-01-29 21:56:50 +0000
4@@ -73,8 +73,7 @@
5
6 exec_script ("Create");
7
8- if (db.exec ("ATTACH DATABASE '%s' AS old_db;".printf (olddbfile)) != Sqlite.OK)
9- throw new DatabaseError.EXECUTE ("Failed to attach old database : %s (%s)".printf (olddbfile, db.errmsg ()));
10+ attach (olddbfile, "old_db");
11
12 bool failure = false;
13 try {
14
15=== modified file 'midori/midori-database.vala'
16--- midori/midori-database.vala 2014-01-27 22:46:08 +0000
17+++ midori/midori-database.vala 2014-01-29 21:56:50 +0000
18@@ -147,12 +147,16 @@
19 init ();
20 }
21
22- public virtual bool init (GLib.Cancellable? cancellable = null) throws DatabaseError {
23- string real_path = path;
24+ string resolve_path (string? path) {
25 if (path == null || path.has_prefix (":memory:"))
26- real_path = ":memory:";
27+ return ":memory:";
28 else if (!Path.is_absolute (path))
29- real_path = Midori.Paths.get_config_filename_for_writing (path);
30+ return Midori.Paths.get_config_filename_for_writing (path);
31+ return path;
32+ }
33+
34+ public virtual bool init (GLib.Cancellable? cancellable = null) throws DatabaseError {
35+ string real_path = resolve_path (path);
36 bool exists = Posix.access (real_path, Posix.F_OK) == 0;
37
38 if (Sqlite.Database.open_v2 (real_path, out _db) != Sqlite.OK)
39@@ -192,6 +196,17 @@
40 return true;
41 }
42
43+ /*
44+ * Since: 0.5.8
45+ */
46+ public bool attach (string path, string alias) throws DatabaseError {
47+ string real_path = resolve_path (path);
48+ bool exists = Posix.access (real_path, Posix.F_OK) == 0;
49+ if (!exists)
50+ throw new DatabaseError.OPEN ("Failed to attach database %s".printf (path));
51+ return exec ("ATTACH DATABASE '%s' AS '%s';".printf (real_path, alias));
52+ }
53+
54 public bool exec_script (string filename) throws DatabaseError {
55 string basename = Path.get_basename (path);
56 string[] parts = basename.split (".");
57
58=== modified file 'midori/midori-historydatabase.vala'
59--- midori/midori-historydatabase.vala 2013-12-16 22:38:24 +0000
60+++ midori/midori-historydatabase.vala 2014-01-29 21:56:50 +0000
61@@ -40,7 +40,7 @@
62 Object (path: "history.db");
63 init ();
64 Midori.BookmarksDatabase bookmarks_database = new Midori.BookmarksDatabase ();
65- exec ("ATTACH DATABASE '%s' AS bookmarks".printf (bookmarks_database.path));
66+ attach (bookmarks_database.path, "bookmarks");
67
68 try {
69 exec ("SELECT day FROM history LIMIT 1");

Subscribers

People subscribed via source and target branches

to all changes: