From d7b4252b65cbd75c88720672778da7ac794476cd Mon Sep 17 00:00:00 2001 From: Jacob <92279567+Oia20@users.noreply.github.com> Date: Thu, 25 Apr 2024 20:59:01 -0500 Subject: [PATCH] Added alter table --- CropSQL/Pages/Components/Terminal.razor | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/CropSQL/Pages/Components/Terminal.razor b/CropSQL/Pages/Components/Terminal.razor index ad6e191..af06373 100644 --- a/CropSQL/Pages/Components/Terminal.razor +++ b/CropSQL/Pages/Components/Terminal.razor @@ -108,14 +108,17 @@ "Let's start by creating your farm with 'CREATE DATABASE' followed by the name of our farm, lets name ours 'sqland', followed by a semi-colon don't forget the semi-colon, this is how sql knows where your command ends.", "We need to tell SQL which Database we are using, do this by saying 'USE' followed by our farm name.", "You need a table to store the crops in your field. Create a table with 'CREATE TABLE' followed by the table name, we will name ours 'crops' then open a parentheses '('inside of your table you can specify columns, and what datatype goes into them. This will make more sense later in the game, but for now, lets create a column named Crop with a data type of varchar(20) which is a word with a max of 20 characters. Then an Amount column which takes and int, and a Word column which also takes an int.", - "Oops, it looks like we forgot to add a column for how much our Crops are worth! Not to worry, SQL gives us a command for that. 'ALTER TABLE tableName' followed by ADD columnName datatype" + "Oops, it looks like we forgot to add a column for how much our Crops are worth! Not to worry, SQL gives us a command for that. 'ALTER TABLE tableName' followed by ADD columnName datatype", + "Hello" ]); private List codeSample = new List { new string[] { "CREATE DATABASE sqland;" }, new string[] { "USE sqland;" }, new string[] { "CREATE TABLE crops (", "crop varchar(20),", "amount int", ");"}, + new string[] { "ALTER TABLE crops", "ADD worth int;" }, new string[] { "ALTER TABLE crops", "ADD worth int;" } + }; private void ExecuteCommand() { @@ -124,6 +127,8 @@ currentCommand.ForEach(Console.WriteLine); currentCommand = currentCommand.SelectMany(command => command.Split(" ")).ToList(); currentCommand.ForEach(Console.WriteLine); + currentCommand.RemoveAll(string.IsNullOrEmpty); + switch (termNum) { case 1: @@ -164,6 +169,24 @@ } break; case 4: + if (currentCommand.Count > 5 && + currentCommand[0].ToUpper() == "ALTER" && + currentCommand[1].ToUpper() == "TABLE" && + currentCommand[2].ToUpper() == "CROPS" && + currentCommand[3].ToUpper() == "ADD" && + currentCommand[4].ToUpper() == "WORTH" && + currentCommand[5].ToUpper().Contains("INT") + ) + { + terminalOutput.Add("CropSQL> Anotha one! Column Added To Table!"); + termNum++; + } + else + { + terminalOutput.Add("CropSQL> Incorrect Command"); + } + break; + case 5: break; }