private void HandleStatement(InsertStatement statement) { _catalogManager.CheckValidation(statement); // get table schema SchemaRecord schema = _catalogManager.GetTableSchemaRecord(statement.TableName); // adjust inlined type in insert statement if (schema.SQL.AttributeDeclarations.Count != statement.Values.Count) { throw new Exception("number of columns between \"create table\" and \"insert statement\' do not match"); } int i; for (i = 0; i < statement.Values.Count; i++) { statement.Values[i].CharLimit = schema.SQL.AttributeDeclarations[i].CharLimit; } // find out primary key from insert values AtomValue primaryKey = statement.Values[schema.SQL.AttributeDeclarations.FindIndex(x => x.AttributeName == schema.SQL.PrimaryKey)]; // insert into index trees List <SchemaRecord> indexSchemas = _catalogManager.GetIndicesSchemaRecord(statement.TableName); foreach (SchemaRecord indexSchema in indexSchemas) { // find indexed value from insert values AtomValue indexedValue = statement.Values[schema.SQL.AttributeDeclarations.FindIndex(x => x.AttributeName == indexSchema.SQL.AttributeName)]; // wrap up indexed value and primary key List <AtomValue> indexPrimaryKeyPair = new List <AtomValue>() { indexedValue, primaryKey }; // insert into index trees int newIndexRoot = _recordManager.InsertRecord(indexPrimaryKeyPair, indexedValue, indexSchema.RootPage); _catalogManager.TryUpdateSchemaRecord(indexSchema.Name, newIndexRoot); } // insert into table tree int newRoot = _recordManager.InsertRecord(statement.Values, primaryKey, schema.RootPage); _catalogManager.TryUpdateSchemaRecord(statement.TableName, newRoot); }