Home Home

SetTableSchema

SetTableSchema changes the schema of a table.
unsigned int SetTableSchema (
	unsigned int tableID,
	const CODBPP::Schema *schema = NULL,
	const unsigned int *fieldMapping = NULL
);

Parameters

tableID The table ID defining the table's handle.
schema Pointer to a valid schema.
fieldMapping An array of int values allowing this method to map field from there old schema to the new - eg. fieldMapping[0] = 2, will move the value in the first field of the old table into the third field of the new table. Sub fields are appended to the end so that <fields><sub fields 1><sub fields 2> and so no.

Return Values

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

Remarks

  • If fieldMapping parameter is missing, than SetTableSchema will map the first fixed field to the first fixed field, the second fixed field to the second and so on, plus the first variable field to the first variable field and so on.
  • SetTableSchema is not part of the transaction.
  • When schema equals NULL SetTableSchema attempts a rebuild and/or upgrade for the table file to its current standard and this will also open the table.
  • Example Use

    int length;
    CODBPP database;
    CODBPP::Schema *schema;
    if(database.OpenDatabase(_T"YourDatabase") == NO_ERROR
    && (error = database.BeginTransaction(CODBPP::EXCLUSIVE)) == NO_ERROR
    && (error = database.OpenTable(1)) == NO_ERROR
    && (error = database.GetTableSchema(1,NULL,&length)) == NO_ERROR){
       schema = (CODBPP::Schema*) new BYTE[length];
       if((error = database.GetTableSchema(1,schema)) == NO_ERROR){
          //removes the last index if there is one
          if(schema.indexCount > 0){
             schema.indexCount--;
             error = database.SetTableSchema(1,schema);
          }
       }
       delete [] (LPBYTE)schema;
    }
    if(error && database.GetErrorMessage(&message) == NO_ERROR)
       MessageBox(message);
    database.EndTransaction();
    

    Also See

    GetTableSchema

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