/// <summary>Creates empty table with a single column for PK. List name must be formatted correctly before being passed here. Ie. no spaces, all lowercase.</summary> public static void CreateNewWikiList(string listName) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), listName); return; } //listname is checked in the UI for proper format. string command = "CREATE TABLE wikilist_" + POut.String(listName) + " (" + POut.String(listName) + "Num bigint NOT NULL auto_increment PRIMARY KEY ) DEFAULT CHARSET=utf8"; Db.NonQ(command); WikiListHeaderWidth headerWidth = new WikiListHeaderWidth(); headerWidth.ColName = listName + "Num"; headerWidth.ColWidth = 100; headerWidth.ListName = listName; WikiListHeaderWidths.InsertNew(headerWidth); }
///<summary>Column is automatically named "Column#" where # is the number of columns+1.</summary> public static void AddColumn(string listName) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), listName); return; } //Find Valid column name----------------------------------------------------------------------------------------- DataTable columnNames = Db.GetTable("DESCRIBE wikilist_" + POut.String(listName)); string newColumnName = "Column1"; //default in case table has no columns. Should never happen. for (int i = 0; i < columnNames.Rows.Count + 1; i++) //+1 to guarantee we can find a valid name. { newColumnName = "Column" + (1 + i); //ie. Column1, Column2, Column3... for (int j = 0; j < columnNames.Rows.Count; j++) { if (newColumnName == columnNames.Rows[j]["Field"].ToString()) { newColumnName = ""; break; } } if (newColumnName != "") { break; //found a valid name. } } if (newColumnName == "") { //should never happen. throw new ApplicationException("Could not create valid column name."); } //Add new column name-------------------------------------------------------------------------------------------- string command = "ALTER TABLE wikilist_" + POut.String(listName) + " ADD COLUMN " + POut.String(newColumnName) + " TEXT NOT NULL"; Db.NonQ(command); //Add column widths to wikiListHeaderWidth Table----------------------------------------------------------------- WikiListHeaderWidth headerWidth = new WikiListHeaderWidth(); headerWidth.ColName = newColumnName; headerWidth.ListName = listName; headerWidth.ColWidth = 100; WikiListHeaderWidths.InsertNew(headerWidth); }