internal static DBStatus CreateStruct(string name, int fields) { DBFile table = new DBFile(name); DBStatus status = new DBStatus(); status.Table = table; table.CreateStruct(fields); return(status); }
public static bool Open() { if (Table == null) { if (DB.Exists(Name)) { Table = DB.Open(Name); return(Table != null); } Table = DB.CreateStruct(Name, 2); Table.SetStructField(0, "id", DB.FieldTypeString, 20, 0); Table.SetStructField(1, "name", DB.FieldTypeString, 50, 0); return(Table.SaveStruct()); } return(false); }
internal static DBStatus Open(string name) { if (Tables.ContainsKey(name)) { DBFile tab = Tables[name]; return(tab.Open()); } if (!DBFile.Exists(name)) { ServerLog.Register("No se pudo abrir la table \"" + name + "\", debido a que no existe."); return(null); } DBFile table = new DBFile(name); DBStatus status = table.Open(); Tables.Add(name, table); return(status); }
internal DBStatus Open() { if (OpenCount > 0) { OpenCount++; DBStatus stat = new DBStatus(); stat.Values = new string[FieldCount]; stat.BlankRow(); return(stat); } try { DBStream = new FileStream(DataFileName(Name + DBFEXENSION), FileMode.Open); }catch (Exception e) { LogError(e); return(null); } Formatter = new BinaryFormatter(); Header = (DBHeader)Formatter.Deserialize(DBStream); if (!Header.IsValid()) { DBStream.Close(); ServerLog.Register("No se puedo abrir \"" + Name + "\" debido a que el encabezado es inválido."); return(null); } FieldCount = Header.Fields; Fields = new DBField[FieldCount]; for (int i = 0; i < FieldCount; i++) { DBField field = (DBField)Formatter.Deserialize(DBStream); field.Name = Encoding.ASCII.GetString(field.BName).Trim(); Fields[i] = field; } DBStatus status = new DBStatus(); status.Table = this; status.Values = new string[FieldCount]; status.BlankRow(); return(status); }