Creating a new table under transaction controlYou can add an extra level of data integrity when creating a new table by placing the code to create a table inside a transaction. If the transaction is aborted, the table entry in the database dictionary file is removed, and the table data and index files are deleted from disk. When a table is created inside a transaction, and until the transaction is committed or aborted, the newly created table must be opened with CTOPEN_EXCLUSIVE mode, otherwise the table open operation will fail. After the transaction is committed the table can be opened in non-exclusive mode. The code fragment below creates a new table under transaction control. Again no error checking code is included in the example: /* allocate a new table handle */ hTable = ctdbAllocTable(hDatabase);
ctdbBegin(hTable);
ctdbAddField(hTable, “Field1”, CT_INTEGER, 4);
ctdbAddField(hTable, “Field1”, CT_CHAR, 30);
ctdbCreateTable(hTable, “MyTable”, CTCREATE_NORMAL);
ctdbCommit(hTable); |
|||