Exemple #1
0
        public void TestTableAddLine()
        {
            string[]    numeCol1    = { "col11", "col12", "col13" };
            ColumnNames columnName1 = new ColumnNames(numeCol1);

            TableLine customTableLine = new TableLine(null).SetContent(new string[] { "t1", "t2", "t3" });
            Table     customTable     = new Table("customTable", columnName1);

            Assert.AreEqual(customTable.AddLine(customTableLine).ToString(), "customTable:\ncol11 col12 col13\n   t1    t2    t3");
        }
Exemple #2
0
        public void TestAddLines()
        {
            string[]    numeCol1    = { "col11", "col12", "col13" };
            ColumnNames columnName1 = new ColumnNames(numeCol1);

            Table testTable = new Table("testTable", columnName1);

            string[]    numeCol2    = { "col11", "col12" };
            ColumnNames columnName2 = new ColumnNames(numeCol2);
            TableLine   tableLine   = new TableLine(columnName2);

            Assert.AreEqual(testTable.AddLine(tableLine).ToString(), "testTable:\ncol11 col12 col13\n                 ");
        }
Exemple #3
0
        public void addLineTest2()
        {
            string[]    cols     = { "col1", "col2", "col3" };
            ColumnNames colNames = new ColumnNames(cols);

            Assert.AreEqual(colNames.ToString(), "col1 col2 col3");
            Assert.AreNotEqual(colNames.ToString(), "col1 col2 col33");
            Table testTable1 = new Table("testTable", colNames);

            string[]  tableLine = new string[] { "col1Content", "col2Content", "col3Content" };
            TableLine tl        = new TableLine(colNames);

            tl = tl.SetContent(tableLine);
            TableLine tl2 = tl.Select(colNames);

            testTable1.AddLine(tl2);
            String expected = "testTable:\n       col1        col2        col3\ncol1Content col2Content col3Content";
            String actual   = testTable1.ToString();

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public static string INSERT_Command(string param)
        {
            Trace.Assert(param != null, "param == null");
            if (param == "-h")
            {
                return("Insert into <table name> (<fields list>) values (<values list>)   |-> Insert int table on current db");
            }
            check(currentDb != noDb, "Not allowed");
            string insert = $"INTO _(?<table>{term})_\\(_(?<fields>{multi(lValue)})_\\)_VALUES_\\(_(?<values>{multi(rValue)})_\\)".Replace("_", "\\s*");

            Match matches = new Regex(insert, RegexOptions.IgnoreCase).Match(param);

            check(matches.Value.Length == param.Length, "Syntax error");
            string
                tableName = matches.Groups["table"].Value,
                fields    = matches.Groups["fields"].Value,
                values    = matches.Groups["values"].Value;

            List <string> fieldsList = new List <string>();

            foreach (Match m in new Regex($"{lValue}").Matches(fields))
            {
                fieldsList.Add(m.Value.Trim(compSep));
            }

            List <string> valuesList = new List <string>();

            foreach (Match m in new Regex($"{rValue}").Matches(values))
            {
                valuesList.Add(m.Value.Trim(strSep));
            }

            Contract.Requires(valuesList != null);
            Contract.Requires(fieldsList != null);
            TableLine ctl = new TableLine(new ColumnNames(fieldsList.ToArray())).SetContent(valuesList.ToArray());

            currentDb[tableName].AddLine(ctl);
            Contract.Ensures(currentDb[tableName].Contains(ctl));
            return("Ok");
        }