// table functions public static void CreateTable(DataStore dstore, string dbName, string tableName, TableDefinition tableDef) { // grab current line contents var dstoreEntries = dstore.DataLines.Select(x => x.Contents).ToList(); // verify db var existDBDef = ReadDB(dstore, dbName); // verify table does not exist var existTableDef = dstore.DataFormatter.ReadTableDefinition(dstoreEntries, dstore.DataStoreType, existDBDef, tableName); if (existTableDef != null) { throw new Exception( string.Format("Table \"{1}\" already exists in database \"{0}\"", dbName, tableName) ); } // build table def var newTableDef = new TableDefinition(tableName: tableName) { Fields = tableDef.Fields, Wires = tableDef.Wires, Description = tableDef.Description, FieldDelimiter = tableDef.FieldDelimiter, SupportsTags = tableDef.SupportsTags, IsHidden = tableDef.IsHidden, SupportsHistory = tableDef.SupportsHistory }; // build db entries var ecReq = dstore.DataFormatter.BuildTableEntry(dstoreEntries, dstore.DataStoreType, existDBDef, newTableDef); // submit dstore and entry change request for processing ProcessChangeRequest(dstore, ecReq); }
// tables public EntryChangeRequest BuildTableEntry(List <string> dstoreEntries, DataStoreType dstoreType, DatabaseDefinition dbDef, TableDefinition tableDef) { // build table title line var lineParts = new List <string>(); lineParts.Add(medataLineStart); if (mdataTablePrefix != string.Empty) { lineParts.Add(mdataTablePrefix); } lineParts.Add(buildMdataKeyValueString(mdataTable, tableDef.Name, tableDef.Description)); lineParts.Add(buildMdataString(mdataTableFieldSeparator, tableDef.FieldDelimiter)); lineParts.Add(buildMdataString(mdataTableInternal, tableDef.IsHidden)); lineParts.Add(buildMdataString(mdataTableTags, tableDef.SupportsTags)); lineParts.Add(buildMdataString(mdataTableHistory, tableDef.SupportsHistory)); lineParts.Add(buildMdataString(mdataTableEncapsulation, tableDef.EncapsulateValues)); lineParts.Add(buildMdataString(mdataTableHeaders, tableDef.SupportsHeaders)); // build table fields if (tableDef.Key != null) { lineParts.Add(buildMdataString(mdataTablePKField, tableDef.Key.Name, wrapInQuotes: false)); } else { lineParts.Add(buildMdataString(mdataTablePKField, mdataNotSet)); } foreach (Field field in tableDef.Fields) { string typeKeyName; switch (field.FieldType) { case FieldType.Boolean: typeKeyName = mdataFieldBool; break; case FieldType.Byte: typeKeyName = mdataFieldByte; break; case FieldType.Integer: typeKeyName = mdataFieldInteger; break; case FieldType.Text: typeKeyName = mdataFieldText; break; case FieldType.Date: typeKeyName = mdataFieldDate; break; case FieldType.Time: typeKeyName = mdataFieldTime; break; case FieldType.TimeStamp: typeKeyName = mdataFieldTimeStamp; break; case FieldType.TimeStampTZ: typeKeyName = mdataFieldTimeStampTZ; break; case FieldType.Decimal: typeKeyName = mdataFieldDecimal; break; case FieldType.UUID: typeKeyName = mdataFieldUUID; break; case FieldType.JSON: typeKeyName = mdataFieldJSON; break; case FieldType.XML: typeKeyName = mdataFieldXML; break; default: typeKeyName = mdataFieldText; break; } // TODO: implement nullable property lineParts.Add(buildMdataKeyValueString(typeKeyName, field.Name, field.Description)); } // build table wires foreach (Wire wire in tableDef.Wires) { lineParts.Add(buildMdataKeyValue(mdataTableFieldWire, wire.FromFieldName, wire.ToFieldName)); } var dbRange = extractDBRange(dstoreType.TypeName, dstoreEntries, dbDef); return(new EntryChangeRequest( EntryChangeType.Insert, dbRange.Last + 1, string.Join(mdataSeparator, lineParts) )); }
private EntryRange extractTableRange(string dstoreTypeName, List <string> dstoreEntries, DatabaseDefinition dbDef, TableDefinition tableDef) { var dbRange = extractDBRange(dstoreTypeName, dstoreEntries, dbDef); return(extractRange(dstoreEntries, mdataTable, tableDef.Name, keyvalue: true, relativeRange: dbRange)); }
public bool UpdateTable(string tableName, TableDefinition tableConfig) { // TODO: Connection.UpdateTable throw new NotImplementedException(); }