CreateTable

CreateTable creates a new table within the database.
unsigned int CreateTable (
   const CODBPP::Schema *schema,
   unsigned int *tableID = NULL
);

Parameters

schemaa valid schema definition for the desired table.
tableIDon successful creation of a table where the schema.tableID was set to zero, the next allocated ID is written to this return value.

Return Values

If the method succeeds, the return value is zero else see error codes for more details.

Remarks

  • Database must be in exculsive mode before this method is called.
  • CreateTable is atomic and will be undone if method fails.
  • CreateTable checks to see if the given schema is valid, if it is capable of being repaired, it will do it.
  • CreateTable is not part of the transaction so there is no need to call CommitTransaction.
Example Use
CODBPP database;
CODBPP::Schema schema;
CODBPP::Field fields[3];
memset(&schema,0,sizeof(CODBPP::Schema));
schema.tableName = TEXT("Table Name");
schema.fieldCount = 3;
schema.fields = &fields;
memset(schema.fields,0,schema.fieldCount * sizeof(CODBPP::Field));
schema.fields[0].type = CODBPP::UINT32;
schema.fields[0].name = TEXT("First");
schema.fields[1].type = CODBPP::FLOAT64;
schema.fields[1].name = TEXT("Second");
schema.fields[2].type = CODBPP::ASTR;
schema.fields[2].name = TEXT("Third");
if(database.OpenDatabase(TEXT("YourDatabase")) == NO_ERROR){
   if((error = database.BeginTransaction(CODBPP::EXCLUSIVE)) == NO_ERROR){
      if((error = database.CreateTable(&schema)) == NO_ERROR){
         ...
      }
   }
   if(error && database.GetErrorMessage(&message) == NO_ERROR)
      MessageBox(message);
   database.EndTransaction();
}

Also See

AddTable, CloseTable, OpenTable, RemoveTable
Comments (0)Listen All
Characters left: 2500
 
Ekky Software Homepage Ekky Software Homepage ObjectDatabase++ TScript Ekky Software Homepage Ekky Software Homepage ObjectDatabase++ TScript