Example #1
0
        protected IList <SqlClause> ParseChilds()
        {
            /*
             * 一个动态子句的形式为:{? .. #ParamName# ..} 或者 {? .. $ParamName$ ..}.  或者 {? .. {? .. } {?..} }
             *
             * 1.必须出现一个而且只能是一个参数子句,可以是命名参数或者值替换参数
             * 2.如果出现动态语句,那么不能出现参数语句
             */

            IList <SqlClause> clauses = SqlParser.ParseToClauses(Content);

            //如果找到动态语句,那么必须全部文本或动态语句
            DynamicClause clause = clauses.FirstOrDefault(c => c is DynamicClause) as DynamicClause;

            if (null != clause)
            {
                if (clauses.Any(c => c is ParameterClause))
                {
                    throw new FoxOneException("嵌套的动态语句{?..}和命名参数(#..#或$..$)不能同时出现在一个动态语句中 : " + RawText);
                }

                _foundNestedDynamicClause = true;
            }
            else if (!FindSingleParameterClause(clauses))
            {
                throw new FoxOneException("动态语句{?..}中必须包含命名参数或者嵌套的动态语句 : " + RawText);
            }

            return(clauses);
        }
Example #2
0
        public override bool ToCommand(IDaoProvider provider, SqlCommandBuilder builder, ISqlParameters parameters)
        {
            IDictionary <string, object> outParams = new Dictionary <string, object>();

            string sql = _executor.Execute(_action, parameters, outParams);

            if (!string.IsNullOrEmpty(sql))
            {
                parameters = outParams.Count == 0 ? parameters : new ArrayParameters(outParams, parameters);

                IList <SqlClause> clauses = SqlParser.ParseToClauses(sql);

                foreach (SqlClause clause in clauses)
                {
                    clause.ToCommand(provider, builder, parameters);
                }
            }

            return(true);
        }
Example #3
0
        private static Dictionary <string, ISqlStatement> LoadSqlsFromXml(string file, XElement root)
        {
            Dictionary <string, ISqlStatement> sqls = new Dictionary <string, ISqlStatement>();

            //支持配置文件编写如Users.Oracle.config来表示SQL只适用于某个数据库类型
            string subfix          = "";
            string daoProviderName = ExtractDaoProviderName(file);

            if (!string.IsNullOrEmpty(daoProviderName) &&
                null != DaoFactory.GetDaoProvider(daoProviderName))
            {
                subfix = "$" + daoProviderName.ToLower();
            }

            foreach (XElement element in root.Elements())
            {
                XAttribute attribute = element.Attribute("key");

                if (null == attribute || string.IsNullOrEmpty(attribute.Value))
                {
                    throw new InvalidOperationException(string.Format("'key' attribute must has a value of command in '{0}'", file));
                }

                string key = attribute.Value + subfix;

                // default sql don't support @ or : native db named param
                XAttribute    ignoreDbNamedParam = element.Attribute("ignoreDbNamedParam");
                ISqlStatement statement          = SqlParser.Parse(element.Value, null != ignoreDbNamedParam && ignoreDbNamedParam.Value.Equals("true", StringComparison.OrdinalIgnoreCase));

                XAttribute connection = element.Attribute("connection");
                if (null != connection)
                {
                    statement.Connection = connection.Value;
                }

                sqls[key] = statement;
            }

            return(sqls);
        }