foundsetUpdater Refusing To Set Columns

Questions, tips and tricks and techniques for scripting in Servoy

foundsetUpdater Refusing To Set Columns

Postby joe26 » Wed Nov 18, 2020 1:30 am

Hi all,

Just trying to update the printing of inventory, but the foundsetUpdater is returning false.

Added databaseManager.saveData(Q); to see if there were were any unsaved records prior. Should not have been but still fails to update the records.

This has worked in the past. Am I running out of memory?

If the foundsetUpdater returns false, I now just set the columns for each record...

Code: Select all
   /** @type {QBSelect<db:/stsservoy/inventory>} */
   var q = databaseManager.createSelect('db:/stsservoy/inventory');
   q.where.add(q.columns.tenant_uuid.eq(globals.makeUUID(globals.session.tenant_uuid)));
   q.where.add(q.columns.inventory_uuid.isin(barcodePrintedArray));
   var Q = databaseManager.getFoundSet(q);
   if (Q.getSize() > 0){
      databaseManager.saveData(Q);
      var R = databaseManager.getFoundSetUpdater(Q);
      var printDate = new Date();
      R.setColumn('print_date',printDate);
      R.setColumn('lprint',1);
      if (!R.performUpdate()){
         var idx = 1;var rec = null;
         while (rec = Q.getRecord(idx++)){
            rec.print_date = printDate;
            rec.lprint = 1;
         }
         databaseManager.saveData(Q);
      }
   }


Get this error:
ERROR com.servoy.j2db.util.Debug - Error executing sql: update "TEMP_8_8E28242B-1806-44F5-ACF6-642786B79A76" "TEMP_06-44F5-ACF6-642786B79A76" set bc_printed=?, if_lprint=?
where "TEMP_06-44F5-ACF6-642786B79A76"."_sv_rowid" = ? with params: [1 ,type: java.lang.Integer, 1 ,type: java.lang.Integer, 5 ,type: java.lang.Integer] com.servoy.j2db.util.ServoyException:
Update/insert failed, unexpected nr of records affected: expected 1, actual 0
at com.servoy.j2db.server.dataprocessing.Zv.Za(Zv.java:1106) [j2db_server_2020.9.0.3602.jar:?]
at com.servoy.j2db.server.dataprocessing.Zv.performUpdates(Zv.java:559) [j2db_server_2020.9.0.3602.jar:?]
at jdk.internal.reflect.GeneratedMethodAccessor240.invoke(Unknown Source) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
at com.servoy.j2db.util.AbstractRemoteInvocationHandler.invokeMethod(AbstractRemoteInvocationHandler.java:77) [servoy_shared_2020.9.0.3602.jar:?]
at com.servoy.j2db.util.ThreadingRemoteInvocationHandler$1.run(ThreadingRemoteInvocationHandler.java:79) [servoy_shared_2020.9.0.3602.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:?]
at java.lang.Thread.run(Unknown Source) [?:?]
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm

Re: foundsetUpdater Refusing To Set Columns

Postby mboegem » Thu Nov 19, 2020 12:32 am

Hi joe26,

The issue is that either due to the length of your 'barcodePrintedArray' or just because creating the Foundset through the query, results in Servoy creating temp tables to display the results.
Because the foundsetupdater will touch all records and temp tables are reloaded in chunks, the updates will fail.

I've made some modification to your code, that might work. Pls give it a go.
If this still fails, it's definitely the length of your 'barcodePrintedArray' and you need to think of a different solution.

Code: Select all
var Q = datasources.db.stsservoy.inventory.getFoundSet();
      if(Q.find()) {
         Q.tenant_uuid = globals.makeUUID(globals.session.tenant_uuid);
         Q.inventory_uuid = barcodePrintedArray;
         
         if(Q.search()) {
            databaseManager.saveData(Q);
               var R = databaseManager.getFoundSetUpdater(Q);
               var printDate = new Date();
               R.setColumn('print_date',printDate);
               R.setColumn('lprint',1);
               if (!R.performUpdate()){
                  var idx = 1;var rec = null;
                  while (rec = Q.getRecord(idx++)){
                     rec.print_date = printDate;
                     rec.lprint = 1;
                  }
                  databaseManager.saveData(Q);
               }
         }
      }


Please be aware that the length of the barcodePrintedArray is definitely limited and limitations will depend on the type of database you're using.
A more solid solution would be to create records in a table to hold every key of the barcode you're printing.
Then the method above can find the records based on a relation between the inventory table and this 'print table'
Records in this 'print table' can/should be temporary and also be linked to the current user, so you can easily have more users executing a print job simultaneously.

Hope this helps
_____________________
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance SAN Developer

Image
User avatar
mboegem
 
Posts: 1573
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: foundsetUpdater Refusing To Set Columns

Postby joe26 » Thu Nov 19, 2020 6:32 pm

Thank You, Marc. I will try this.
joe26
 
Posts: 172
Joined: Wed Jun 19, 2013 10:30 pm


Return to Methods

Who is online

Users browsing this forum: No registered users and 3 guests