2012-01-10 10:40:34 -08:00
|
|
|
/* Copyright 2011-2012 Yorba Foundation
|
2011-06-10 19:17:35 -07:00
|
|
|
*
|
|
|
|
|
* This software is licensed under the GNU Lesser General Public License
|
|
|
|
|
* (version 2.1 or later). See the COPYING file in this distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-01-09 10:58:13 -08:00
|
|
|
public abstract class Geary.Sqlite.Row : Object {
|
2011-06-10 19:17:35 -07:00
|
|
|
public const int64 INVALID_ID = -1;
|
|
|
|
|
|
2011-07-29 20:10:43 -07:00
|
|
|
protected Table table;
|
2011-06-16 16:27:08 -07:00
|
|
|
|
|
|
|
|
public Row(Table table) {
|
|
|
|
|
this.table = table;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int fetch_int_for(SQLHeavy.QueryResult result, int col) throws SQLHeavy.Error {
|
2011-06-23 19:07:04 -07:00
|
|
|
return result.fetch_int(field_index(result, col));
|
2011-06-10 19:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-16 16:27:08 -07:00
|
|
|
public int64 fetch_int64_for(SQLHeavy.QueryResult result, int col) throws SQLHeavy.Error {
|
2011-06-23 19:07:04 -07:00
|
|
|
return result.fetch_int64(field_index(result, col));
|
2011-06-10 19:17:35 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-16 16:27:08 -07:00
|
|
|
public string fetch_string_for(SQLHeavy.QueryResult result, int col) throws SQLHeavy.Error {
|
2011-06-23 19:07:04 -07:00
|
|
|
return result.fetch_string(field_index(result, col));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int field_index(SQLHeavy.QueryResult result, int col) throws SQLHeavy.Error {
|
|
|
|
|
try {
|
|
|
|
|
return result.field_index(table.get_field_name(col));
|
|
|
|
|
} catch (SQLHeavy.Error err) {
|
|
|
|
|
debug("Bad column #%d in %s: %s", col, table.to_string(), err.message);
|
|
|
|
|
|
|
|
|
|
throw err;
|
|
|
|
|
}
|
2011-06-10 19:17:35 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|