Chapter 2 The database layer
1. Change recversion
Ax4.0 uses Optimistic Concurrency Control and recversion is used to identify the recorded version. Static Void Recversionchange (ARGs _ ARGs)
{
Custtable custtableselected;
Custtable custtableselectedforupdate;
Custtable custtableupdated;
;
Ttsbegin;
Select custtableselected
Where custtableselected. accountnum = ' 4000 ' ;
Select forupdate custtableselectedforupdate
Where custtableselectedforupdate. accountnum = ' 4000 ' ;
Select forupdate custtableupdated
Where custtableupdated. accountnum = ' 4000 ' ;
// At this point, recversion in all three buffers are equal.
Custtableupdated. creditmax = Custtableupdated. creditmax;
Custtableupdated. Update ();
Print custtableupdated. recversion;
Print custtableselectedforupdate. recversion;
Print custtableselected. recversion;
// At this point, recversion is changed in the custtableupdated
// And custtableselectedforupdate buffers. custtableselected still
// Has its original value in recversion.
Ttscommit;
Pause;
}
2. Skip the forupdate, ttsbegin, and ttscommit checks.
Custtable;
;
Ttsbegin;
Select custtable where custtable. accountnum = ' 4000 ' ;
Custtable. creditmax = 1000 ;
Custtable. skipttscheck ( True );
Custtable. Update ();
Ttscommit;
This can be skipped, but why?
3. Use of temporary tables.
You can use settmp and data methods. Static Void Tmpcusttable (ARGs _ ARGs)
{
Custtable;
Custtable custtabletmp;
;
Custtabletmp. settmp ();
Ttsbegin;
While Select custtable
{
Custtabletmp. Data (custtable );
Custtabletmp. doinsert ();
}
Ttscommit;
}
Table has two methods: Data () and settmpdata (). Data () is a copy of the data, and settmpdata () is only used for Object Reference transfer.
4. Empty temporary tables
When a temporary table is assigned null, the memory is cleared and the temporary file is deleted.
Static Void Tmpledgertable (ARGs _ ARGs)
{
Tmpledgertable;
;
Tmpledgertable. companyid = ' Dat ' ;
Tmpledgertable. accountnum = ' 1000 ' ;
Tmpledgertable. accountname = ' Name ' ;
Tmpledgertable. insert (); // Insert into first dataset.
Tmpledgertable = Null ; // Allocated memory is freed
// And file is deleted.
Tmpledgertable. companyid = ' Dat ' ;
Tmpledgertable. accountnum = ' 1000 ' ;
Tmpledgertable. accountname = ' Name ' ;
Tmpledgertable. insert (); // Insert into new dataset.
// Check it
While Select * From tmpledgertable
{
Print tmpledgertable. accountname;
}
Pause;
}
5. The following sectionCodeAs mentioned above, settmpdata points to the same object.
Static Void Tmpledgertable (ARGs _ ARGs)
{
Tmpledgertable tmpledgertable1;
Tmpledgertable tmpledgertable2;
;
Tmpledgertable2.settmpdata (tmpledgertable1 );
Tmpledgertable1.companyid = ' Dat ' ;
Tmpledgertable1.accountnum = ' 1000 ' ;
Tmpledgertable1.accountname = ' Name ' ;
Tmpledgertable1.insert (); // Insert into shared dataset.
Tmpledgertable2.companyid = ' Dat ' ;
Tmpledgertable2.accountnum = ' 1000 ' ;
Tmpledgertable2.accountname = ' Name ' ;
Tmpledgertable2.insert (); // Insert will fail with dublicate value.
}
6. ttsabort is used to ignore record changes or inserts.
The rest of the code is about transactions and locks. It is similar to the database theory and will not be excerpted here.