public void GetFirstParameterPositionWithALabelShouldNotMatchTheLabelStatement()
        {
            var position = SqlUtility.GetFirstParameterPosition(@"delete_more:
     DELETE TOP(500) FROM LogMessages WHERE LogDate < @p0
IF @@ROWCOUNT > 0 GOTO delete_more");

            Assert.Equal(68, position);
        }
        public void GetFirstParameterPositionWithAnIdentifierInAQuotedString()
        {
            var position = SqlUtility.GetFirstParameterPosition(@"CREATE VIEW IF NOT EXISTS ListIDs_24h AS
SELECT
  EPC,
  substr( EPC, 15, 4 ) AS Type,
  substr( EPC, 19 ) AS ID,
  strftime( '%Y-%m-%d %H:%M:%S', Timestamp ) AS Timestamp
FROM LogEntries
WHERE Timestamp > datetime( 'now' ) - time( '24:00' )
ORDER BY Timestamp DESC");

            Assert.Equal(-1, position);
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the command text.
        /// </summary>
        /// <param name="commandText">The command text.</param>
        /// <returns>The actual command text.</returns>
        protected virtual string GetCommandText(string commandText)
        {
            if (commandText == null)
            {
                throw new ArgumentNullException("commandText");
            }

            if (this.IsStoredProcedureCall(commandText))
            {
                var invocationCommandLength = this.sqlCharacters.StoredProcedureInvocationCommand.Length;
                var firstParameterPosition  = SqlUtility.GetFirstParameterPosition(commandText);

                if (firstParameterPosition > invocationCommandLength)
                {
                    return(commandText.Substring(invocationCommandLength, firstParameterPosition - invocationCommandLength).Trim());
                }
                else
                {
                    return(commandText.Substring(invocationCommandLength, commandText.Length - invocationCommandLength).Trim());
                }
            }

            return(commandText);
        }
        public void GetFirstParameterPositionWithAQuotedStringAndParameters()
        {
            var position = SqlUtility.GetFirstParameterPosition("SELECT 1 FROM table WHERE column1 <> '' AND id = @p0 AND column2 <> ''");

            Assert.Equal(49, position);
        }
 public void GetFirstParameterPositionThrowsArgumentNullExceptionForNullCommandText()
 {
     Assert.Throws <ArgumentNullException>(() => SqlUtility.GetFirstParameterPosition(null));
 }
        public void GetFirstParameterPositionWithQuestionMarkParameters()
        {
            var position = SqlUtility.GetFirstParameterPosition("SELECT * FROM TABLE WHERE Column1 = ? AND Column2 = ?");

            Assert.Equal(36, position);
        }