Commit 59c1f121 authored by Jim Nelson's avatar Jim Nelson

Fix earliest UID assertion: Closes #7390

MIN() and MAX() in Sqlite returns an unanticipated NULL when a column
result set is empty.  Fix is to catch when that happens.
parent 0129af9c
......@@ -43,6 +43,18 @@ public class Geary.Db.Result : Geary.Db.Context {
return !finished;
}
/**
* column is zero-based.
*/
public bool is_null_at(int column) throws DatabaseError {
verify_at(column);
bool is_null = statement.stmt.column_type(column) == Sqlite.NULL;
log("is_null_at(%d) -> %s", column, is_null.to_string());
return is_null;
}
/**
* column is zero-based.
*/
......@@ -148,6 +160,14 @@ public class Geary.Db.Result : Geary.Db.Context {
throw new DatabaseError.LIMITS("column %d >= %d", column, count);
}
/**
* name is the name of the column in the result set. See Statement.get_column_index() for name
* matching rules.
*/
public bool is_null_for(string name) throws DatabaseError {
return is_null_at(convert_for(name));
}
/**
* name is the name of the column in the result set. See Statement.get_column_index() for name
* matching rules.
......
......@@ -699,7 +699,8 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics {
stmt.bind_rowid(0, folder_id);
Db.Result results = stmt.exec(cancellable);
if (!results.finished)
// MIN and MAX return NULL if the result set being examined is zero-length
if (!results.finished && !results.is_null_at(0))
id = new ImapDB.EmailIdentifier(results.rowid_at(1), new Imap.UID(results.int64_at(0)));
return Db.TransactionOutcome.DONE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment