Пример #1
0
        public static void AddMap(string filePath)
        {
            StreamReader sr  = new StreamReader(filePath);
            string       xml = sr.ReadToEnd();

            sr.Close();
            var doc        = XDocument.Parse(xml);
            var root       = doc.Element("Root");
            var sqlMapList = root.Elements().ToList();

            foreach (var sm in sqlMapList)
            {
                var item = new SqlMapCommand();
                item.ReturnType = sm.Attribute("Type").Value;
                item.Name       = sm.Attribute("Name").Value;
                item.Memo       = sm.Attribute("Memo").Value;
                item.SQL        = sm.Value;
                item.SQLType    = root.Attribute("Type").Value;
                SetParameters(item);
                try
                {
                    sqlMaps.Add(item.Name, item);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 得到SQL-Map命令对象
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public SqlMapCommand GetCommandInfo(string name)
        {
            SqlMapCommand commandInfo = null;

            if (sqlMaps.TryGetValue(name, out commandInfo))
            {
                commandInfo.DataProvider = this.Provider;
                return(commandInfo);
            }
            else
            {
                throw new NotSupportedException("没有对应的SQL命令函数!");
            }
        }
Пример #3
0
        private static void SetParameters(SqlMapCommand command)
        {
            Regex regex = new Regex(@"#(\w+):(\w+)[,]?(out|input)?#");
            var   ms    = regex.Matches(command.SQL);

            foreach (Match m in ms)
            {
                if (m.Success)   // parameter of word
                {
                    SqlMapParameter p = new SqlMapParameter();
                    p.Name      = m.Groups[1].Value;
                    p.Type      = Type.GetType("System." + m.Groups[2].Value);
                    p.Direction = m.Groups[3].Value == "out"? ParameterDirection.Output
                                             : ParameterDirection.Input;

                    command.Parameters.Add(p);
                }
            }
        }