Skip to content

Commit 09ec0ae

Browse files
practicalswiftcdecker
authored andcommitted
Return true or false from sqlite3_bind_* based on result from SQLite instead of always returning true
1 parent 1fca7ab commit 09ec0ae

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

wallet/db.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ bool sqlite3_bind_short_channel_id(sqlite3_stmt *stmt, int col,
710710
const struct short_channel_id *id)
711711
{
712712
char *ser = short_channel_id_to_str(id, id);
713-
sqlite3_bind_blob(stmt, col, ser, strlen(ser), SQLITE_TRANSIENT);
713+
int err = sqlite3_bind_blob(stmt, col, ser, strlen(ser), SQLITE_TRANSIENT);
714714
tal_free(ser);
715-
return true;
715+
return err == SQLITE_OK;
716716
}
717717

718718
bool sqlite3_column_short_channel_id(sqlite3_stmt *stmt, int col,
@@ -731,8 +731,8 @@ bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col,
731731

732732
/* Handle nulls early. */
733733
if (!id) {
734-
sqlite3_bind_null(stmt, col);
735-
return true;
734+
int err = sqlite3_bind_null(stmt, col);
735+
return err == SQLITE_OK;
736736
}
737737

738738
ser = tal_arr(NULL, u8, 0);
@@ -741,10 +741,10 @@ bool sqlite3_bind_short_channel_id_array(sqlite3_stmt *stmt, int col,
741741
for (i = 0; i < num; ++i)
742742
towire_short_channel_id(&ser, &id[i]);
743743

744-
sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
744+
int err = sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
745745

746746
tal_free(ser);
747-
return true;
747+
return err == SQLITE_OK;
748748
}
749749
struct short_channel_id *
750750
sqlite3_column_short_channel_id_array(const tal_t *ctx,
@@ -776,9 +776,9 @@ sqlite3_column_short_channel_id_array(const tal_t *ctx,
776776
bool sqlite3_bind_tx(sqlite3_stmt *stmt, int col, const struct bitcoin_tx *tx)
777777
{
778778
u8 *ser = linearize_tx(NULL, tx);
779-
sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
779+
int err = sqlite3_bind_blob(stmt, col, ser, tal_count(ser), SQLITE_TRANSIENT);
780780
tal_free(ser);
781-
return true;
781+
return err == SQLITE_OK;
782782
}
783783

784784
struct bitcoin_tx *sqlite3_column_tx(const tal_t *ctx, sqlite3_stmt *stmt,
@@ -795,8 +795,8 @@ bool sqlite3_bind_signature(sqlite3_stmt *stmt, int col,
795795
u8 buf[64];
796796
ok = secp256k1_ecdsa_signature_serialize_compact(secp256k1_ctx, buf,
797797
sig) == 1;
798-
sqlite3_bind_blob(stmt, col, buf, sizeof(buf), SQLITE_TRANSIENT);
799-
return ok;
798+
int err = sqlite3_bind_blob(stmt, col, buf, sizeof(buf), SQLITE_TRANSIENT);
799+
return ok && err == SQLITE_OK;
800800
}
801801

802802
bool sqlite3_column_signature(sqlite3_stmt *stmt, int col,
@@ -817,8 +817,8 @@ bool sqlite3_bind_pubkey(sqlite3_stmt *stmt, int col, const struct pubkey *pk)
817817
{
818818
u8 der[PUBKEY_DER_LEN];
819819
pubkey_to_der(der, pk);
820-
sqlite3_bind_blob(stmt, col, der, sizeof(der), SQLITE_TRANSIENT);
821-
return true;
820+
int err = sqlite3_bind_blob(stmt, col, der, sizeof(der), SQLITE_TRANSIENT);
821+
return err == SQLITE_OK;
822822
}
823823

824824
bool sqlite3_bind_pubkey_array(sqlite3_stmt *stmt, int col,
@@ -829,19 +829,19 @@ bool sqlite3_bind_pubkey_array(sqlite3_stmt *stmt, int col,
829829
u8 *ders;
830830

831831
if (!pks) {
832-
sqlite3_bind_null(stmt, col);
833-
return true;
832+
int err = sqlite3_bind_null(stmt, col);
833+
return err == SQLITE_OK;
834834
}
835835

836836
n = tal_count(pks);
837837
ders = tal_arr(NULL, u8, n * PUBKEY_DER_LEN);
838838

839839
for (i = 0; i < n; ++i)
840840
pubkey_to_der(&ders[i * PUBKEY_DER_LEN], &pks[i]);
841-
sqlite3_bind_blob(stmt, col, ders, tal_count(ders), SQLITE_TRANSIENT);
841+
int err = sqlite3_bind_blob(stmt, col, ders, tal_count(ders), SQLITE_TRANSIENT);
842842

843843
tal_free(ders);
844-
return true;
844+
return err == SQLITE_OK;
845845
}
846846
struct pubkey *sqlite3_column_pubkey_array(const tal_t *ctx,
847847
sqlite3_stmt *stmt, int col)
@@ -875,8 +875,8 @@ bool sqlite3_column_preimage(sqlite3_stmt *stmt, int col, struct preimage *dest
875875

876876
bool sqlite3_bind_preimage(sqlite3_stmt *stmt, int col, const struct preimage *p)
877877
{
878-
sqlite3_bind_blob(stmt, col, p, sizeof(struct preimage), SQLITE_TRANSIENT);
879-
return true;
878+
int err = sqlite3_bind_blob(stmt, col, p, sizeof(struct preimage), SQLITE_TRANSIENT);
879+
return err == SQLITE_OK;
880880
}
881881

882882
bool sqlite3_column_sha256(sqlite3_stmt *stmt, int col, struct sha256 *dest)
@@ -887,8 +887,8 @@ bool sqlite3_column_sha256(sqlite3_stmt *stmt, int col, struct sha256 *dest)
887887

888888
bool sqlite3_bind_sha256(sqlite3_stmt *stmt, int col, const struct sha256 *p)
889889
{
890-
sqlite3_bind_blob(stmt, col, p, sizeof(struct sha256), SQLITE_TRANSIENT);
891-
return true;
890+
int err = sqlite3_bind_blob(stmt, col, p, sizeof(struct sha256), SQLITE_TRANSIENT);
891+
return err == SQLITE_OK;
892892
}
893893

894894
bool sqlite3_column_sha256_double(sqlite3_stmt *stmt, int col, struct sha256_double *dest)
@@ -905,8 +905,8 @@ struct secret *sqlite3_column_secrets(const tal_t *ctx,
905905

906906
bool sqlite3_bind_sha256_double(sqlite3_stmt *stmt, int col, const struct sha256_double *p)
907907
{
908-
sqlite3_bind_blob(stmt, col, p, sizeof(struct sha256_double), SQLITE_TRANSIENT);
909-
return true;
908+
int err = sqlite3_bind_blob(stmt, col, p, sizeof(struct sha256_double), SQLITE_TRANSIENT);
909+
return err == SQLITE_OK;
910910
}
911911

912912
struct json_escaped *sqlite3_column_json_escaped(const tal_t *ctx,
@@ -920,6 +920,6 @@ struct json_escaped *sqlite3_column_json_escaped(const tal_t *ctx,
920920
bool sqlite3_bind_json_escaped(sqlite3_stmt *stmt, int col,
921921
const struct json_escaped *esc)
922922
{
923-
sqlite3_bind_text(stmt, col, esc->s, strlen(esc->s), SQLITE_TRANSIENT);
924-
return true;
923+
int err = sqlite3_bind_text(stmt, col, esc->s, strlen(esc->s), SQLITE_TRANSIENT);
924+
return err == SQLITE_OK;
925925
}

0 commit comments

Comments
 (0)