Example #1
0
        public SqlStatement GetSqlStatement(string sqlStr, params object[] os)
        {
            CommandType ct = SqlStatement.GetCommandType(sqlStr);

            if (ct == CommandType.StoredProcedure)
            {
                return(new SqlStatement(ct, sqlStr, os));
            }
            var dpc = new DataParameterCollection();
            int start = 0, n = 0;
            var sql = new StringBuilder();

            foreach (Match m in Reg.Matches(sqlStr))
            {
                if (m.Length == 1)
                {
                    string pn = Dialect.QuoteParameter("p" + n);
                    sql.Append(sqlStr.Substring(start, m.Index - start));
                    sql.Append(pn);
                    start = m.Index + 1;
                    var dp = new DataParameter(pn, os[n]);
                    dpc.Add(dp);
                    n++;
                }
            }
            if (start < sqlStr.Length)
            {
                sql.Append(sqlStr.Substring(start));
            }
            var ret = new SqlStatement(ct, sql.ToString(), dpc);

            return(ret);
        }
Example #2
0
 public SqlStatement(CommandType sqlCommandType, string sqlCommandText, params object[] os)
     : this(sqlCommandType, sqlCommandText)
 {
     Parameters.Add(os);
 }