TScript Basic Write Queries

Update table_1 set UInt = ObjectID

In this query it shows how TScript handles the basic - update table_1 set UInt = ID64. The main thing to note is the use of the "Copy" method, this allows you to access directly the memory buffer pointed to by the "fixed" pointer, the offset and length of the UInt field is coming from the cashed table scheme.

The second main difference between a read and write query is the use of the methods RewriteObject and CommitTransaction. Both of these methods must be called to update an object, the RewriteObject tells the ODBMS that all modifications on the object have been complete and CommitTransaction tells the ODBMS to write all database modification to disk.

  • TScript
#include "ODBPP.ts"

public main(variable parameters = null : Structure results) {
   ODBPP database;
   CODBPP::Object objectHandle;
   database.OpenDatabase(L"D:\\Database\\test.odc");
   database.BeginTransaction();
   database.OpenTable(1);
   if(database.ReadIndex(1,CODBPP::FIRST,0: objectHandle)){
      for(Reference fields = database.schemata[1].fields; true;){
         objectHandle.fixed.Copy(objectHandle.ID64,
                                  fields.UInt.offset,fields.UInt["length"]);
         database.RewriteObject(1);
         if(!database.ReadIndex(1,CODBPP::NEXT,0: objectHandle)){
            if(ERROR_MASK(error) != CODBPP::NOT_FOUND_INDEX_KEY) return error;
            break;
         }
      }
   }
   else if(ERROR_MASK(error) != CODBPP::NOT_FOUND_INDEX_KEY) return error;
   database.CommitTransaction();
}