private bool CheckExists(string commandText, out string newCommandText)
        {
            Match match = _ifStatementRegex.Match(commandText);

            newCommandText = commandText;
            if (!match.Success)
            {
                return(true);
            }

            string not             = match.Groups["not"].Value;
            string sqlCheckCommand = match.Groups["sqlCheckCommand"].Value;

            newCommandText = match.Groups["sqlCommand"].Value;

            bool hasRows;

            using (JetCommand command = (JetCommand)((ICloneable)this).Clone())
            {
                command.CommandText = sqlCheckCommand;
                using (var reader = command.ExecuteReader())
                {
                    hasRows = reader.HasRows;
                }
            }

            if (!string.IsNullOrWhiteSpace(not))
            {
                return(!hasRows);
            }
            else
            {
                return(hasRows);
            }
        }
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns>The created object</returns>
        object ICloneable.Clone()
        {
            JetCommand clone = new JetCommand();

            clone._Connection = this._Connection;

            clone._WrappedCommand = (DbCommand)((ICloneable)this._WrappedCommand).Clone();

            return(clone);
        }
Ejemplo n.º 3
0
        public DbCommand CreateCommand(string commandText, int?commandTimeout = null)
        {
            if (String.IsNullOrEmpty(commandText))
            {
                // SqlCommand will complain if the command text is empty
                commandText = Environment.NewLine;
            }

            var command = new JetCommand(commandText, this);

            if (commandTimeout.HasValue)
            {
                command.CommandTimeout = commandTimeout.Value;
            }

            return(command);
        }