Home Home

CreateTable

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

Parameters

schema A valid schema definition for the desired table.
tableID On 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 = _T"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 = _T"First";
    schema.fields[1].type = CODBPP::FLOAT64;
    schema.fields[1].name = _T"Second";
    schema.fields[2].type = CODBPP::ASTR;
    schema.fields[2].name = _T"Third";
    if(database.OpenDatabase(_T"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

    Copyright © 2003-2008, Ekky Software Pty. Ltd.