Merge lp:~gue5t/midori/tabby-double into lp:midori

Proposed by gue5t gue5t
Status: Merged
Approved by: Paweł Forysiuk
Approved revision: 6975
Merged at revision: 6981
Proposed branch: lp:~gue5t/midori/tabby-double
Merge into: lp:midori
Diff against target: 64 lines (+10/-11)
2 files modified
extensions/tabby.vala (+4/-9)
midori/midori-database.vala (+6/-2)
To merge this branch: bzr merge lp:~gue5t/midori/tabby-double
Reviewer Review Type Date Requested Status
Paweł Forysiuk Approve
Review via email: mp+262936@code.launchpad.net

Commit message

clean up handling of double-valued db column in Tabby

Description of the change

Right now, running in a new configuration directory causes Tabby to warn because Midori.Database.Statement.get_double expects the column to be of Sqlite.FLOAT type rather than either that or Sqlite.NULL (which differs from the behavior of other accessors in that namespace).

This changes get_double to return NAN if the column doesn't exist, which fixes the warning.
This commit also simplifies the logic in Tabby, which currently takes a roundabout path through stringification and parsing.

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 'extensions/tabby.vala'
2--- extensions/tabby.vala 2015-04-19 14:42:11 +0000
3+++ extensions/tabby.vala 2015-06-25 04:55:41 +0000
4@@ -557,20 +557,15 @@
5 var statement = database.prepare (sqlcmd,
6 ":session_id", typeof (int64), this.id);
7 statement.step ();
8- double sorting;
9- string? sorting_string = statement.get_double ("MAX(sorting)").to_string ();
10- if (sorting_string != null) {
11- /* we have to use a seperate if condition to avoid
12- a `possibly unassigned local variable` error */
13- if (double.try_parse (sorting_string, out sorting)) {
14- return sorting;
15- }
16+ double sorting = statement.get_double ("MAX(sorting)");
17+ if (!sorting.is_nan ()) {
18+ return sorting;
19 }
20 } catch (Error error) {
21 critical (_("Failed to select from database: %s"), error.message);
22 }
23
24- return double.parse ("0");
25+ return 0.0;
26 }
27
28 internal Session (Midori.Database database) {
29
30=== modified file 'midori/midori-database.vala'
31--- midori/midori-database.vala 2015-03-15 16:24:41 +0000
32+++ midori/midori-database.vala 2015-06-25 04:55:41 +0000
33@@ -121,6 +121,7 @@
34
35 /*
36 * Get a string value by its named parameter, for example ":uri".
37+ * Returns null if not found.
38 */
39 public string? get_string (string name) throws DatabaseError {
40 int index = column_index (name);
41@@ -132,6 +133,7 @@
42
43 /*
44 * Get an integer value by its named parameter, for example ":day".
45+ * Returns 0 if not found.
46 */
47 public int64 get_int64 (string name) throws DatabaseError {
48 int index = column_index (name);
49@@ -144,12 +146,14 @@
50
51 /*
52 * Get a double value by its named parameter, for example ":session_id".
53+ * Returns double.NAN if not found.
54 */
55 public double get_double (string name) throws DatabaseError {
56 int index = column_index (name);
57- if (stmt.column_type (index) != Sqlite.FLOAT)
58+ int type = stmt.column_type (index);
59+ if (type != Sqlite.FLOAT && type != Sqlite.NULL)
60 throw new DatabaseError.TYPE ("Getting '%s' with wrong type in row: %s".printf (name, query));
61- return stmt.column_double (index);
62+ return type == Sqlite.NULL ? double.NAN : stmt.column_double (index);
63 }
64 }
65

Subscribers

People subscribed via source and target branches

to all changes: