示例#1
0
        public void TestSqlJoiner()
        {
            string expected = "field1=20 AND field2=30 AND field3=50";
            List <SqlFieldValuePair> fieldvaluepairs = new List <SqlFieldValuePair>()
            {
                new SqlFieldValuePair(
                    new KeyValuePair <string, object>("field1", 20),
                    SqlCompareOperator.Equal),
                new SqlFieldValuePair(
                    new KeyValuePair <string, object>("field2", 30),
                    SqlCompareOperator.Equal),
                new SqlFieldValuePair(
                    new KeyValuePair <string, object>("field3", 50),
                    SqlCompareOperator.Equal),
            };
            string result = SqlConditionJoiner.Join(fieldvaluepairs, SqlConditions.AND);

            Assert.AreEqual(expected, result);
            expected = "field1=20 AND field2=30 OR field3=50";
            List <SqlConditions> list = new List <SqlConditions>()
            {
                SqlConditions.AND,
                SqlConditions.OR,
            };

            result = SqlConditionJoiner.Join(fieldvaluepairs, list);
            Assert.AreEqual(expected, result);
        }
 public static string CreateUpdateCommand(string tableName, IEnumerable <SqlFieldValuePair> set, IEnumerable <SqlFieldValuePair> conditionsPairs, IEnumerable <SqlConditions> conditions)
 {
     return($"UPDATE {tableName} SET {string.Join(",", set)} WHERE {SqlConditionJoiner.Join(conditionsPairs.ToList(), conditions.ToList())}");
 }
 public static string CreateSelectCommand(string tableName, IEnumerable <string> fields, IEnumerable <SqlFieldValuePair> pairs, IEnumerable <SqlConditions> conditions)
 {
     return($"SELECT {string.Join(",", fields)} FROM {tableName} WHERE {SqlConditionJoiner.Join(pairs.ToList(), conditions.ToList())}");
 }