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
=== modified file 'extensions/tabby.vala'
--- extensions/tabby.vala 2015-04-19 14:42:11 +0000
+++ extensions/tabby.vala 2015-06-25 04:55:41 +0000
@@ -557,20 +557,15 @@
557 var statement = database.prepare (sqlcmd,557 var statement = database.prepare (sqlcmd,
558 ":session_id", typeof (int64), this.id);558 ":session_id", typeof (int64), this.id);
559 statement.step ();559 statement.step ();
560 double sorting;560 double sorting = statement.get_double ("MAX(sorting)");
561 string? sorting_string = statement.get_double ("MAX(sorting)").to_string ();561 if (!sorting.is_nan ()) {
562 if (sorting_string != null) {562 return sorting;
563 /* we have to use a seperate if condition to avoid
564 a `possibly unassigned local variable` error */
565 if (double.try_parse (sorting_string, out sorting)) {
566 return sorting;
567 }
568 }563 }
569 } catch (Error error) {564 } catch (Error error) {
570 critical (_("Failed to select from database: %s"), error.message);565 critical (_("Failed to select from database: %s"), error.message);
571 }566 }
572567
573 return double.parse ("0");568 return 0.0;
574 }569 }
575570
576 internal Session (Midori.Database database) {571 internal Session (Midori.Database database) {
577572
=== modified file 'midori/midori-database.vala'
--- midori/midori-database.vala 2015-03-15 16:24:41 +0000
+++ midori/midori-database.vala 2015-06-25 04:55:41 +0000
@@ -121,6 +121,7 @@
121121
122 /*122 /*
123 * Get a string value by its named parameter, for example ":uri".123 * Get a string value by its named parameter, for example ":uri".
124 * Returns null if not found.
124 */125 */
125 public string? get_string (string name) throws DatabaseError {126 public string? get_string (string name) throws DatabaseError {
126 int index = column_index (name);127 int index = column_index (name);
@@ -132,6 +133,7 @@
132133
133 /*134 /*
134 * Get an integer value by its named parameter, for example ":day".135 * Get an integer value by its named parameter, for example ":day".
136 * Returns 0 if not found.
135 */137 */
136 public int64 get_int64 (string name) throws DatabaseError {138 public int64 get_int64 (string name) throws DatabaseError {
137 int index = column_index (name);139 int index = column_index (name);
@@ -144,12 +146,14 @@
144146
145 /*147 /*
146 * Get a double value by its named parameter, for example ":session_id".148 * Get a double value by its named parameter, for example ":session_id".
149 * Returns double.NAN if not found.
147 */150 */
148 public double get_double (string name) throws DatabaseError {151 public double get_double (string name) throws DatabaseError {
149 int index = column_index (name);152 int index = column_index (name);
150 if (stmt.column_type (index) != Sqlite.FLOAT)153 int type = stmt.column_type (index);
154 if (type != Sqlite.FLOAT && type != Sqlite.NULL)
151 throw new DatabaseError.TYPE ("Getting '%s' with wrong type in row: %s".printf (name, query));155 throw new DatabaseError.TYPE ("Getting '%s' with wrong type in row: %s".printf (name, query));
152 return stmt.column_double (index);156 return type == Sqlite.NULL ? double.NAN : stmt.column_double (index);
153 }157 }
154 }158 }
155159

Subscribers

People subscribed via source and target branches

to all changes: