Saturday, July 7, 2018

Temporary Tables

A temporary table is defined in the AOT as a normal table, but with the
TableType property set to either InMemory or TempDB. Data is not persisted in
a temporary table, and only remains while the table is in scope. If TableType is
set to InMemory, the data is stored in memory or in a temporary file if memory is
full. TempDb means it is stored in a table in SQL, and can be joined to regular
tables at the database tier.
A typical example is a class which initializes a temporary table and inserts some
records, which should be shown in a form. The class has a variable _
tmpTablewhich holds the data and the form has a data source tmpTable_DS which should
show the same data. This is solved by using the method
tmptable_DS.setTmpData(_tmpTable). This disregards the individual file
allocated to
tmptable_DS. Now, both _tmpTable and tmptable_DS will access
the same pool of data, as if they were normal table variables. The allocated file
now shared between _
tmpTable and tmptable_DS is deleted once both variables
have gone out of scope.
Instead of making a dedicated definition of a temporary table in the AOT,
consider making a temporary instance of a database table (in other words, a nontemporary table which is part of the SQL database). Do this using the .
setTmp()method before accessing the variable. Be careful with this option, as you can
activate other methods which act as if it is real database data and cause
subsequent updates in other tables. See the following example, which copies all
customers from Australia to a temporary table.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
static void CopyPersistedTableToTemp(Args _args)
{
  CustTable custTable;
  CustTable tmpCustTable;

  tmpCustTable.setTmp();
  while select custTable
  where custTable.CountryRegionId == "AU"
  {
    tmpCustTable.data(custTable.data());
    tmpCustTable.doInsert();
  }
}

Best Regards,
Hossein Karimi

No comments:

Post a Comment

Configure the Firewall on the Enterprise Portal Server

After you install Enterprise Portal, enable Web Server (HTTP) in Windows Firewall. If you do not enable the web server in Windows Firewall...