mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-24 01:24:26 +01:00
db: Maybe a bit too pedantic?
Checking on whether we access a null field is ok, but should we crash right away? Probably not. This reduces the access to a warning on sqlite3 and let's it continue. We can look for occurences and fix them as they come up and then re-arm the asserts once we addressed all cases.
This commit is contained in:
committed by
neil saitug
parent
712595f0d2
commit
1ecad0cc53
25
wallet/db.c
25
wallet/db.c
@@ -562,7 +562,10 @@ bool db_step(struct db_stmt *stmt)
|
||||
|
||||
u64 db_column_u64(struct db_stmt *stmt, int col)
|
||||
{
|
||||
assert(!db_column_is_null(stmt, col));
|
||||
if (db_column_is_null(stmt, col)) {
|
||||
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
|
||||
return 0;
|
||||
}
|
||||
return stmt->db->config->column_u64_fn(stmt, col);
|
||||
}
|
||||
|
||||
@@ -576,13 +579,19 @@ int db_column_int_or_default(struct db_stmt *stmt, int col, int def)
|
||||
|
||||
int db_column_int(struct db_stmt *stmt, int col)
|
||||
{
|
||||
assert(!db_column_is_null(stmt, col));
|
||||
if (db_column_is_null(stmt, col)) {
|
||||
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
|
||||
return 0;
|
||||
}
|
||||
return stmt->db->config->column_int_fn(stmt, col);
|
||||
}
|
||||
|
||||
size_t db_column_bytes(struct db_stmt *stmt, int col)
|
||||
{
|
||||
assert(!db_column_is_null(stmt, col));
|
||||
if (db_column_is_null(stmt, col)) {
|
||||
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
|
||||
return 0;
|
||||
}
|
||||
return stmt->db->config->column_bytes_fn(stmt, col);
|
||||
}
|
||||
|
||||
@@ -593,13 +602,19 @@ int db_column_is_null(struct db_stmt *stmt, int col)
|
||||
|
||||
const void *db_column_blob(struct db_stmt *stmt, int col)
|
||||
{
|
||||
assert(!db_column_is_null(stmt, col));
|
||||
if (db_column_is_null(stmt, col)) {
|
||||
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
|
||||
return NULL;
|
||||
}
|
||||
return stmt->db->config->column_blob_fn(stmt, col);
|
||||
}
|
||||
|
||||
const unsigned char *db_column_text(struct db_stmt *stmt, int col)
|
||||
{
|
||||
assert(!db_column_is_null(stmt, col));
|
||||
if (db_column_is_null(stmt, col)) {
|
||||
log_broken(stmt->db->log, "Accessing a null column %d in query %s", col, stmt->query->query);
|
||||
return NULL;
|
||||
}
|
||||
return stmt->db->config->column_text_fn(stmt, col);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user