Ejemplo n.º 1
0
        protected ADODB.Command GenerateCommand(CommandTypeEnum eCmdType, SqlFrag frag)
        {
            ADODB.Command SqlCmd   = new Command();
            string        strQuery = "";

            if (frag.SqlParams.Count < 2040)
            {
                ProcessParameters(SqlCmd, frag);

                // replace our tags
                strQuery = frag.m_strSql.Replace("{", "");
                strQuery = strQuery.Replace("}", "");
            }
            else
            {
                strQuery = frag.Flatten();
            }

            // ensure we have a valid connections
            Ensure();

            // set up the object
            SqlCmd.ActiveConnection = m_pConnection;
            SqlCmd.CommandText      = strQuery;
            SqlCmd.CommandType      = eCmdType;

            return(SqlCmd);
        }
Ejemplo n.º 2
0
        public static SqlFrag operator +(SqlFrag Frag1, string strToAdd)
        {
            SqlFrag Cloned = new SqlFrag(Frag1);

            Cloned.m_strSql += " ";
            Cloned.m_strSql += strToAdd;

            return(Cloned);
        }
Ejemplo n.º 3
0
        public int ExecuteSql(CommandTypeEnum eCmdType, SqlFrag frag)
        {
            ADODB.Command sqlCmd         = GenerateCommand(eCmdType, frag);
            object        obRecsAffected = 0;

            sqlCmd.Execute(out obRecsAffected);

            return((int)obRecsAffected);
        }
Ejemplo n.º 4
0
        public static SqlFrag operator +(SqlFrag Frag1, SqlFrag Frag2)
        {
            SqlFrag Cloned = new SqlFrag(Frag1);

            Cloned.m_strSql += " ";
            Cloned.m_strSql += Frag2.m_strSql;
            Cloned.m_Params.AddRange(Frag2.m_Params);

            return(Cloned);
        }
Ejemplo n.º 5
0
        public bool ReturnsRecords(SqlFrag frag)
        {
            ADORecordset rs      = CreateRecordset("IF EXISTS({SQL}) (SELECT CAST(1 AS BIT) AS Val) ELSE (SELECT CAST(0 AS BIT) AS Val)", frag);
            bool         bExists = false;

            if (!rs.EOF)
            {
                bExists = rs.GetValue <bool>("Val");
            }
            return(bExists);
        }
Ejemplo n.º 6
0
 public SqlDataReader GetDataReader(SqlFrag frag)
 {
     if (frag.SqlParams.Count < 2040)
     {
         return(GetParamDataReader("{SQL}", frag));
     }
     else
     {
         return(GetParamDataReader(frag.Flatten()));
     }
 }
Ejemplo n.º 7
0
 public DataSet GetDataSet(SqlFrag frag)
 {
     if (frag.SqlParams.Count < 2040)
     {
         return(GetParamDataSet("{SQL}", frag));
     }
     else
     {
         return(GetParamDataSet(frag.Flatten()));
     }
 }
Ejemplo n.º 8
0
 public int ExecuteSql(SqlFrag frag)
 {
     if (frag.SqlParams.Count < 2040)
     {
         return(ExecuteParamSql("{SQL}", frag));
     }
     else
     {
         return(ExecuteParamSql(frag.Flatten()));
     }
 }
Ejemplo n.º 9
0
        public Recordset CreateRecordset(SqlFrag frag, CommandTypeEnum eCmdType = CommandTypeEnum.adCmdText,
                                         CursorLocationEnum eCursorLoc          = CursorLocationEnum.adUseClient, CursorTypeEnum eCursorType = CursorTypeEnum.adOpenDynamic,
                                         LockTypeEnum eLockType = LockTypeEnum.adLockOptimistic, ExecuteOptionEnum eExecOptions              = ExecuteOptionEnum.adOptionUnspecified)
        {
            ADODB.Command SqlCmd   = GenerateCommand(eCmdType, frag);
            Recordset     rRecords = new Recordset();

            rRecords.CursorLocation = eCursorLoc;

            rRecords.Open(SqlCmd, Type.Missing, eCursorType, eLockType, (int)eExecOptions);
            return(rRecords);
        }
Ejemplo n.º 10
0
        private void ProcessParameters(Command SqlCmd, SqlFrag frag)
        {
            if (frag == null || frag.SqlParams.Count == 0)
            {
                return;
            }

            for (int i = 0; i < frag.SqlParams.Count; i++)
            {
                AppendParameter(frag.SqlParams[i], SqlCmd);
            }
        }
Ejemplo n.º 11
0
 public SqlFrag(SqlFrag FragToClone)
 {
     m_strSql = FragToClone.Sql;
     m_Params = new List <SqlParam>(FragToClone.SqlParams);
 }
Ejemplo n.º 12
0
        public void ProcessParamSql(string strSql, ref object[] parms)
        {
            // TODO: Use StringBuilder for better performance/less of a memory hit?
            int CurrIndexOpenCurly  = -1;
            int CurrIndexCloseCurly = -1;

            foreach (object oParam in parms)
            {
                CurrIndexOpenCurly = strSql.IndexOf('{', CurrIndexOpenCurly + 1);

                if (CurrIndexOpenCurly == -1)
                {
                    break;
                }

                CurrIndexCloseCurly = strSql.IndexOf('}', CurrIndexOpenCurly + 1);

                if (CurrIndexCloseCurly == -1)
                {
                    throw new Exception("An incomplete parameter tag exists in this query");
                }

                if (CurrIndexCloseCurly <= CurrIndexOpenCurly)
                {
                    throw new Exception("The index of the closing brace is less than the index of the opening brace.");
                }

                SqlParam sqlParam;
                sqlParam.Value    = oParam;
                sqlParam.DataType = GetParameterType(CurrIndexOpenCurly, CurrIndexCloseCurly, ref strSql);

                string strInsert = "{?}";
                switch (sqlParam.DataType)
                {
                case SqlParamType.Sql:
                {
                    SqlFrag frag = (SqlFrag)sqlParam.Value;
                    strInsert = frag.m_strSql;
                    m_Params.AddRange(frag.m_Params);
                }
                break;

                case SqlParamType.ConstantString:
                case SqlParamType.ConstantInt:
                    strInsert = FlattenParameter(sqlParam);
                    break;

                default:
                    strInsert = "{?}";
                    m_Params.Add(sqlParam);
                    break;
                }

                strSql = strSql.Remove(CurrIndexOpenCurly, CurrIndexCloseCurly - CurrIndexOpenCurly + 1);
                strSql = strSql.Insert(CurrIndexOpenCurly, strInsert);

                CurrIndexOpenCurly += strInsert.Length;
            }

            m_strSql = strSql;
        }