db: Use macro while creating prepared statements
This commit is contained in:
parent
f92af896f8
commit
a3e7b3af82
@ -272,7 +272,19 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
{
|
{
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_reserve",
|
#define PREPARE(name, sql, ...) \
|
||||||
|
do { \
|
||||||
|
result = PQprepare (db_conn, name, sql, __VA_ARGS__); \
|
||||||
|
if (PGRES_COMMAND_OK != PQresultStatus (result)) \
|
||||||
|
{ \
|
||||||
|
break_db_err (result); \
|
||||||
|
PQclear (result); result = NULL; \
|
||||||
|
return GNUNET_SYSERR; \
|
||||||
|
} \
|
||||||
|
PQclear (result); result = NULL; \
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
PREPARE ("get_reserve",
|
||||||
"SELECT "
|
"SELECT "
|
||||||
"current_balance_value"
|
"current_balance_value"
|
||||||
",current_balance_fraction"
|
",current_balance_fraction"
|
||||||
@ -282,15 +294,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"WHERE reserve_pub=$1 "
|
"WHERE reserve_pub=$1 "
|
||||||
"LIMIT 1; ",
|
"LIMIT 1; ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("update_reserve",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "update_reserve",
|
|
||||||
"UPDATE reserves "
|
"UPDATE reserves "
|
||||||
"SET"
|
"SET"
|
||||||
" current_balance_value=$2 "
|
" current_balance_value=$2 "
|
||||||
@ -298,44 +302,22 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
",expiration_date=$4 "
|
",expiration_date=$4 "
|
||||||
"WHERE reserve_pub=$1 ",
|
"WHERE reserve_pub=$1 ",
|
||||||
4, NULL);
|
4, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_collectable_blindcoins",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
result = PQprepare (db_conn, "insert_collectable_blindcoins",
|
|
||||||
"INSERT INTO collectable_blindcoins ( "
|
"INSERT INTO collectable_blindcoins ( "
|
||||||
" blind_ev, blind_ev_sig "
|
" blind_ev, blind_ev_sig "
|
||||||
",denom_pub, reserve_pub, reserve_sig) "
|
",denom_pub, reserve_pub, reserve_sig) "
|
||||||
"VALUES ($1, $2, $3, $4, $5)",
|
"VALUES ($1, $2, $3, $4, $5)",
|
||||||
6, NULL);
|
6, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_collectable_blindcoins",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_collectable_blindcoins",
|
|
||||||
"SELECT "
|
"SELECT "
|
||||||
"blind_ev_sig, denom_pub, reserve_sig, reserve_pub "
|
"blind_ev_sig, denom_pub, reserve_sig, reserve_pub "
|
||||||
"FROM collectable_blindcoins "
|
"FROM collectable_blindcoins "
|
||||||
"WHERE blind_ev = $1",
|
"WHERE blind_ev = $1",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
/* FIXME: does it make sense to store these computed values in the DB? */
|
/* FIXME: does it make sense to store these computed values in the DB? */
|
||||||
#if 0
|
#if 0
|
||||||
result = PQprepare (db_conn, "get_refresh_session",
|
PREPARE ("get_refresh_session",
|
||||||
"SELECT "
|
"SELECT "
|
||||||
" (SELECT count(*) FROM refresh_melt WHERE session_pub = $1)::INT2 as num_oldcoins "
|
" (SELECT count(*) FROM refresh_melt WHERE session_pub = $1)::INT2 as num_oldcoins "
|
||||||
",(SELECT count(*) FROM refresh_blind_session_keys "
|
",(SELECT count(*) FROM refresh_blind_session_keys "
|
||||||
@ -348,16 +330,9 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"FROM refresh_sessions "
|
"FROM refresh_sessions "
|
||||||
"WHERE session_pub = $1",
|
"WHERE session_pub = $1",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_known_coin",
|
PREPARE ("get_known_coin",
|
||||||
"SELECT "
|
"SELECT "
|
||||||
" coin_pub, denom_pub, denom_sig "
|
" coin_pub, denom_pub, denom_sig "
|
||||||
",expended_value, expended_fraction, expended_currency "
|
",expended_value, expended_fraction, expended_currency "
|
||||||
@ -365,15 +340,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"FROM known_coins "
|
"FROM known_coins "
|
||||||
"WHERE coin_pub = $1",
|
"WHERE coin_pub = $1",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("update_known_coin",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "update_known_coin",
|
|
||||||
"UPDATE known_coins "
|
"UPDATE known_coins "
|
||||||
"SET "
|
"SET "
|
||||||
" denom_pub = $2 "
|
" denom_pub = $2 "
|
||||||
@ -385,15 +352,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"WHERE "
|
"WHERE "
|
||||||
" coin_pub = $1 ",
|
" coin_pub = $1 ",
|
||||||
7, NULL);
|
7, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_known_coin",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_known_coin",
|
|
||||||
"INSERT INTO known_coins ("
|
"INSERT INTO known_coins ("
|
||||||
" coin_pub"
|
" coin_pub"
|
||||||
",denom_pub"
|
",denom_pub"
|
||||||
@ -405,45 +364,21 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
")"
|
")"
|
||||||
"VALUES ($1,$2,$3,$4,$5,$6,$7)",
|
"VALUES ($1,$2,$3,$4,$5,$6,$7)",
|
||||||
7, NULL);
|
7, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_refresh_commit_link",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_refresh_commit_link",
|
|
||||||
"SELECT "
|
"SELECT "
|
||||||
" transfer_pub "
|
" transfer_pub "
|
||||||
",link_secret_enc "
|
",link_secret_enc "
|
||||||
"FROM refresh_commit_link "
|
"FROM refresh_commit_link "
|
||||||
"WHERE session_pub = $1 AND cnc_index = $2 AND oldcoin_index = $3",
|
"WHERE session_pub = $1 AND cnc_index = $2 AND oldcoin_index = $3",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_refresh_commit_coin",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_refresh_commit_coin",
|
|
||||||
"SELECT "
|
"SELECT "
|
||||||
" link_vector_enc "
|
" link_vector_enc "
|
||||||
",coin_ev "
|
",coin_ev "
|
||||||
"FROM refresh_commit_coin "
|
"FROM refresh_commit_coin "
|
||||||
"WHERE session_pub = $1 AND cnc_index = $2 AND newcoin_index = $3",
|
"WHERE session_pub = $1 AND cnc_index = $2 AND newcoin_index = $3",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_order",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_order",
|
|
||||||
"INSERT INTO refresh_order ( "
|
"INSERT INTO refresh_order ( "
|
||||||
" newcoin_index "
|
" newcoin_index "
|
||||||
",session_pub "
|
",session_pub "
|
||||||
@ -451,15 +386,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
") "
|
") "
|
||||||
"VALUES ($1, $2, $3) ",
|
"VALUES ($1, $2, $3) ",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_melt",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_melt",
|
|
||||||
"INSERT INTO refresh_melt ( "
|
"INSERT INTO refresh_melt ( "
|
||||||
" session_pub "
|
" session_pub "
|
||||||
",oldcoin_index "
|
",oldcoin_index "
|
||||||
@ -468,69 +395,29 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
") "
|
") "
|
||||||
"VALUES ($1, $2, $3, $4) ",
|
"VALUES ($1, $2, $3, $4) ",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_refresh_order",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_refresh_order",
|
|
||||||
"SELECT denom_pub "
|
"SELECT denom_pub "
|
||||||
"FROM refresh_order "
|
"FROM refresh_order "
|
||||||
"WHERE session_pub = $1 AND newcoin_index = $2",
|
"WHERE session_pub = $1 AND newcoin_index = $2",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_refresh_collectable",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_refresh_collectable",
|
|
||||||
"SELECT ev_sig "
|
"SELECT ev_sig "
|
||||||
"FROM refresh_collectable "
|
"FROM refresh_collectable "
|
||||||
"WHERE session_pub = $1 AND newcoin_index = $2",
|
"WHERE session_pub = $1 AND newcoin_index = $2",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_refresh_melt",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_refresh_melt",
|
|
||||||
"SELECT coin_pub "
|
"SELECT coin_pub "
|
||||||
"FROM refresh_melt "
|
"FROM refresh_melt "
|
||||||
"WHERE session_pub = $1 AND oldcoin_index = $2",
|
"WHERE session_pub = $1 AND oldcoin_index = $2",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_session",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_session",
|
|
||||||
"INSERT INTO refresh_sessions ( "
|
"INSERT INTO refresh_sessions ( "
|
||||||
" session_pub "
|
" session_pub "
|
||||||
",noreveal_index "
|
",noreveal_index "
|
||||||
") "
|
") "
|
||||||
"VALUES ($1, $2) ",
|
"VALUES ($1, $2) ",
|
||||||
2, NULL);
|
2, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_commit_link",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_commit_link",
|
|
||||||
"INSERT INTO refresh_commit_link ( "
|
"INSERT INTO refresh_commit_link ( "
|
||||||
" session_pub "
|
" session_pub "
|
||||||
",transfer_pub "
|
",transfer_pub "
|
||||||
@ -540,15 +427,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
") "
|
") "
|
||||||
"VALUES ($1, $2, $3, $4, $5) ",
|
"VALUES ($1, $2, $3, $4, $5) ",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_commit_coin",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_commit_coin",
|
|
||||||
"INSERT INTO refresh_commit_coin ( "
|
"INSERT INTO refresh_commit_coin ( "
|
||||||
" session_pub "
|
" session_pub "
|
||||||
",coin_ev "
|
",coin_ev "
|
||||||
@ -558,15 +437,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
") "
|
") "
|
||||||
"VALUES ($1, $2, $3, $4, $5) ",
|
"VALUES ($1, $2, $3, $4, $5) ",
|
||||||
5, NULL);
|
5, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_refresh_collectable",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_refresh_collectable",
|
|
||||||
"INSERT INTO refresh_collectable ( "
|
"INSERT INTO refresh_collectable ( "
|
||||||
" session_pub "
|
" session_pub "
|
||||||
",newcoin_index "
|
",newcoin_index "
|
||||||
@ -574,28 +445,12 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
") "
|
") "
|
||||||
"VALUES ($1, $2, $3) ",
|
"VALUES ($1, $2, $3) ",
|
||||||
3, NULL);
|
3, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("set_reveal_ok",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "set_reveal_ok",
|
|
||||||
"UPDATE refresh_sessions "
|
"UPDATE refresh_sessions "
|
||||||
"SET reveal_ok = TRUE "
|
"SET reveal_ok = TRUE "
|
||||||
"WHERE session_pub = $1 ",
|
"WHERE session_pub = $1 ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_link",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_link",
|
|
||||||
"SELECT link_vector_enc, ro.denom_pub, ev_sig "
|
"SELECT link_vector_enc, ro.denom_pub, ev_sig "
|
||||||
"FROM refresh_melt rm "
|
"FROM refresh_melt rm "
|
||||||
" JOIN refresh_order ro USING (session_pub) "
|
" JOIN refresh_order ro USING (session_pub) "
|
||||||
@ -610,15 +465,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
" WHERE rcc2.newcoin_index = 0 AND rcc2.session_pub = rs.session_pub "
|
" WHERE rcc2.newcoin_index = 0 AND rcc2.session_pub = rs.session_pub "
|
||||||
" ) ",
|
" ) ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("get_transfer",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_transfer",
|
|
||||||
"SELECT transfer_pub, link_secret_enc "
|
"SELECT transfer_pub, link_secret_enc "
|
||||||
"FROM refresh_melt rm "
|
"FROM refresh_melt rm "
|
||||||
" JOIN refresh_commit_link rcl USING (session_pub) "
|
" JOIN refresh_commit_link rcl USING (session_pub) "
|
||||||
@ -630,15 +477,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
" WHERE newcoin_index = 0 AND rcc2.session_pub = rm.session_pub "
|
" WHERE newcoin_index = 0 AND rcc2.session_pub = rm.session_pub "
|
||||||
" ) ",
|
" ) ",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
if (PGRES_COMMAND_OK != PQresultStatus(result))
|
PREPARE ("insert_deposit",
|
||||||
{
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "insert_deposit",
|
|
||||||
"INSERT INTO deposits ("
|
"INSERT INTO deposits ("
|
||||||
"coin_pub,"
|
"coin_pub,"
|
||||||
"denom_pub,"
|
"denom_pub,"
|
||||||
@ -655,10 +494,7 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11"
|
"$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11"
|
||||||
")",
|
")",
|
||||||
11, NULL);
|
11, NULL);
|
||||||
EXITIF (PGRES_COMMAND_OK != PQresultStatus(result));
|
PREPARE ("get_deposit",
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
result = PQprepare (db_conn, "get_deposit",
|
|
||||||
"SELECT "
|
"SELECT "
|
||||||
"coin_pub,"
|
"coin_pub,"
|
||||||
"denom_pub,"
|
"denom_pub,"
|
||||||
@ -674,15 +510,8 @@ TALER_MINT_DB_prepare (PGconn *db_conn)
|
|||||||
"coin_pub = $1"
|
"coin_pub = $1"
|
||||||
")",
|
")",
|
||||||
1, NULL);
|
1, NULL);
|
||||||
EXITIF (PGRES_COMMAND_OK != PQresultStatus(result));
|
|
||||||
PQclear (result);
|
|
||||||
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
|
#undef PREPARE
|
||||||
EXITIF_exit:
|
|
||||||
break_db_err (result);
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_SYSERR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user