gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] 01/02: modifications to batch1


From: gnunet
Subject: [taler-exchange] 01/02: modifications to batch1
Date: Fri, 06 Jan 2023 17:06:12 +0100

This is an automated email from the git hooks/post-receive script.

joseph-xu pushed a commit to branch master
in repository exchange.

commit 37f294b6add3ff4780b14ad54331e98c47b8453a
Author: Joseph <Joseph.xu@efrei.net>
AuthorDate: Fri Jan 6 11:05:05 2023 -0500

    modifications to batch1
---
 .../exchange_do_batch_reserves_in_insert.sql       | 50 +++++++++++++---------
 src/exchangedb/pg_batch2_reserves_in_insert.c      |  2 +
 2 files changed, 32 insertions(+), 20 deletions(-)

diff --git a/src/exchangedb/exchange_do_batch_reserves_in_insert.sql 
b/src/exchangedb/exchange_do_batch_reserves_in_insert.sql
index 4e0383f6..d1cc35d3 100644
--- a/src/exchangedb/exchange_do_batch_reserves_in_insert.sql
+++ b/src/exchangedb/exchange_do_batch_reserves_in_insert.sql
@@ -32,7 +32,10 @@ CREATE OR REPLACE FUNCTION 
exchange_do_batch_reserves_in_insert(
   OUT ruuid INT8)
 LANGUAGE plpgsql
 AS $$
-
+DECLARE
+  curs refcursor;
+DECLARE
+  i RECORD;
 BEGIN
 ruuid= 0;
 out_reserve_found = TRUE;
@@ -46,28 +49,35 @@ transaction_duplicate= TRUE;
     ,in_payto_uri)
   ON CONFLICT DO NOTHING;
 
-  INSERT INTO reserves
-    (reserve_pub
-    ,current_balance_val
-    ,current_balance_frac
-    ,expiration_date
-    ,gc_date)
-    VALUES
-    (in_reserve_pub
-    ,in_credit_val
-    ,in_credit_frac
-    ,in_expiration_date
-    ,in_gc_date)
-   ON CONFLICT DO NOTHING
-   RETURNING reserves.reserve_uuid INTO ruuid;
+  OPEN curs FOR
+  WITH reserve_changes AS (
+    INSERT INTO reserves
+      (reserve_pub
+      ,current_balance_val
+      ,current_balance_frac
+      ,expiration_date
+      ,gc_date)
+      VALUES
+      (in_reserve_pub
+      ,in_credit_val
+      ,in_credit_frac
+      ,in_expiration_date
+      ,in_gc_date)
+     ON CONFLICT DO NOTHING
+     RETURNING reserve_uuid, reserve_pub)
+   SELECT * FROM reserve_changes;
+  FETCH FROM curs INTO i;
   IF FOUND
   THEN
     -- We made a change, so the reserve did not previously exist.
-    out_reserve_found = FALSE;
-  ELSE
-    -- We made no change, which means the reserve existed.
-    out_reserve_found = TRUE;
+    IF in_reserve_pub = i.reserve_pub
+    THEN
+        out_reserve_found = FALSE;
+        ruuid = i.reserve_uuid;
+    END IF;
   END IF;
+  CLOSE curs;
+
   PERFORM pg_notify(in_notify, NULL);
   INSERT INTO reserves_in
     (reserve_pub
@@ -92,7 +102,7 @@ transaction_duplicate= TRUE;
     transaction_duplicate = FALSE;
   ELSE
     -- Unhappy...
---    RAISE EXCEPTION 'Reserve did not exist, but INSERT into reserves_in gave 
conflict';
+    RAISE EXCEPTION 'Reserve did not exist, but INSERT into reserves_in gave 
conflict';
     transaction_duplicate = TRUE;
 --    ROLLBACK;
   END IF;
diff --git a/src/exchangedb/pg_batch2_reserves_in_insert.c 
b/src/exchangedb/pg_batch2_reserves_in_insert.c
index a55c518c..e0208f09 100644
--- a/src/exchangedb/pg_batch2_reserves_in_insert.c
+++ b/src/exchangedb/pg_batch2_reserves_in_insert.c
@@ -763,6 +763,7 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
       t_duplicate |= transaction_duplicate[i+1];
       t_duplicate |= transaction_duplicate[i+2];
       t_duplicate |= transaction_duplicate[i+3];
+      //  fprintf(stdout, "reserve_uuid : %ld %ld %ld %ld\n", reserve_uuid[i], 
reserve_uuid[i+1], reserve_uuid[i+2], reserve_uuid[i+3]);
       i += 4;
       break;
     case 3:
@@ -792,6 +793,7 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
       results[i] = (t_duplicate)
       ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
       : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
+      //   fprintf(stdout, "reserve_uuid : %ld %ld\n", reserve_uuid[i], 
reserve_uuid[i+1]);
       i += 2;
       break;
     case 1:

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]