/// <summary>Creates empty table with a column for PK and optionally the columns in listHeaders. List name must be formatted correctly before /// being passed here, i.e. no spaces, all lowercase. If listHeaders is not null or empty, they will be inserted into the db. /// If dropTableIfExists==true, the table with name wikilist_listName will be dropped if it exists and any wikilistheaderwidth rows for the table /// will be deleted before creating the new table and inserting any new wikilistheaderwidth rows.</summary> public static void CreateNewWikiList(string listName, List <WikiListHeaderWidth> listHeaders = null, bool dropTableIfExists = false) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), listName, listHeaders, dropTableIfExists); return; } List <string> listColDefs = new List <string>(); if (listHeaders.IsNullOrEmpty()) { listHeaders = new List <WikiListHeaderWidth>() { new WikiListHeaderWidth { ListName = listName, ColName = listName + "Num", ColWidth = 100 } }; } listColDefs.Add($"{POut.String(listHeaders[0].ColName)} bigint NOT NULL auto_increment PRIMARY KEY"); //listHeaders guaranteed to not be null or empty listColDefs.AddRange(listHeaders.Skip(1).Select(x => $"{POut.String(x.ColName)} TEXT NOT NULL")); //first in listHeaders added as PK already string command = ""; if (dropTableIfExists) { command += $"DROP TABLE IF EXISTS wikilist_{POut.String(listName)}; "; WikiListHeaderWidths.DeleteForList(listName); } command += $@"CREATE TABLE wikilist_{POut.String(listName)} ( {string.Join(@", ",listColDefs)} ) DEFAULT CHARSET=utf8" ; Db.NonQ(command); WikiListHeaderWidths.InsertMany(listHeaders); }
public static void DeleteList(string listName) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), listName); return; } string command = "DROP TABLE wikilist_" + POut.String(listName); Db.NonQ(command); WikiListHeaderWidths.DeleteForList(listName); }