v13+ What table does a set belong to?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

v13+ What table does a set belong to?

4D Tech mailing list
Is there *any* way to determine what table a random set belongs to?

Thanks
Chip
---------------
Gas is for washing parts
Alcohol is for drinkin'
Nitromethane is for racing
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: v13+ What table does a set belong to?

4D Tech mailing list
Hi Chip,

You could try performing a set operation on a known table set with the unknown set.

If the two sets are from **different** tables, the set operation triggers an error. If both sets belong to the **same** table, no error occurs.

So iterate over each table performing the set operation until you encounter no error.

Something like this, which I tested before posting. It seems to work.:

C_LONGINT(error_i)
C_TEXT($known_empty_set)
C_TEXT($unknown_set_t)
C_BOOLEAN($done)
C_BOOLEAN($found)

$unknown_set_t:="unknown_set"
CREATE EMPTY SET([Storage];$unknown_set_t)

$known_empty_set:=Generate UUID
$table_i:=0
Repeat
       
        $table_i:=$table_i+1
       
        CREATE EMPTY SET(Table($table_i)->;$known_empty_set)
       
        ON ERR CALL("TRAP_ERROR")
        error_i:=0
        DIFFERENCE($unknown_set_t;$known_empty_set;$known_empty_set)
        ON ERR CALL("")
       
        If (error_i=0)
                $found:=True
        End if
        error_i:=0
       
        If ($table_i=Get last table number)
                $done:=True
        End if
       
        CLEAR SET($known_empty_set)
       
Until ($done | $found)

If ($found)
        ALERT("Set belongs to "+Table name($table_i)+".")
Else
        ALERT("Cannot determine table owning set.")
end if

- Jeremy French


> On Jun 2, 2017, at 5:22 PM, Chip Scheide via 4D_Tech <[hidden email]> wrote:
>
> Is there *any* way to determine what table a random set belongs to?

**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: v13+ What table does a set belong to?

4D Tech mailing list
Jeremy -
Thanks - and it looks like a possible solution,

The rest of this comment is more aimed at the forum post of Olivier (copied below) - but
This seems like a LOT of work, much more so that a single call to the server.
and it seems a lot of overhead for every set 'math' operation, for all sets involved.

something like (calling your routine 'Test_set'):
if (Test_set(Setname1))
  if (Test_set(Setname2))
    if (Test_set(Setname3))
// now all the sets are known valid
       union(Setname1;Setname2;Setname3)
    end if
  end if
end if

Olivier's forum post (on my feature request)
During a previous summit pre class, I explain and demonstrate how it's dangerous to have the same name for sets of different tables. That's an usual explanation of unnecessary exchanges between client and server. 
So it's a good practice to put the name of the table inside the name of the set. Thanks to this rules you prevent a lot of viscosity and "eliminate issues with (accidentally) trying to do set manipulations on sets from different tables". 

This feature request need a call to the server to read the parent table. I prefer avoid unnecessary exchanges and read a part of the set name. The read is local.


> Hi Chip,
>
> You could try performing a set operation on a known table set with
> the unknown set.
>
> If the two sets are from **different** tables, the set operation
> triggers an error. If both sets belong to the **same** table, no
> error occurs.
>
> So iterate over each table performing the set operation until you
> encounter no error.
>
> Something like this, which I tested before posting. It seems to work.:
>
> C_LONGINT(error_i)
> C_TEXT($known_empty_set)
> C_TEXT($unknown_set_t)
> C_BOOLEAN($done)
> C_BOOLEAN($found)
>
> $unknown_set_t:="unknown_set"
> CREATE EMPTY SET([Storage];$unknown_set_t)
>
> $known_empty_set:=Generate UUID
> $table_i:=0
> Repeat
>
> $table_i:=$table_i+1
>
> CREATE EMPTY SET(Table($table_i)->;$known_empty_set)
>
> ON ERR CALL("TRAP_ERROR")
> error_i:=0
> DIFFERENCE($unknown_set_t;$known_empty_set;$known_empty_set)
> ON ERR CALL("")
>
> If (error_i=0)
> $found:=True
> End if
> error_i:=0
>
> If ($table_i=Get last table number)
> $done:=True
> End if
>
> CLEAR SET($known_empty_set)
>
> Until ($done | $found)
>
> If ($found)
> ALERT("Set belongs to "+Table name($table_i)+".")
> Else
> ALERT("Cannot determine table owning set.")
> end if
>
> - Jeremy French
>
>
>> On Jun 2, 2017, at 5:22 PM, Chip Scheide via 4D_Tech
>> <[hidden email]> wrote:
>> Is there *any* way to determine what table a random set belongs to?
>
------------
Hell is other people
     Jean-Paul Sartre
**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Loading...