Exemplo n.º 1
0
		public void Replace()
		{
			SqlString sql =
				new SqlString(
					new object[] {"select ", "from table ", "where a = ", Parameter.Placeholder, " and c = ", Parameter.Placeholder});
			SqlString replacedSql = sql.Replace("table", "replacedTable");
			Assert.AreEqual(sql.ToString().Replace("table", "replacedTable"), replacedSql.ToString());

			replacedSql = sql.Replace("not found", "not in here");
			Assert.AreEqual(sql.ToString().Replace("not found", "not in here"), replacedSql.ToString(), "replace no found string");

			replacedSql = sql.Replace("le", "LE");
			Assert.AreEqual(sql.ToString().Replace("le", "LE"), replacedSql.ToString(), "multi-match replace");
		}
        private int GetAfterSelectInsertPoint(SqlString sql)
        {
            const string criteriaComment = "/* criteria query */ ";

            if (sql.StartsWithCaseInsensitive(criteriaComment))
                return GetAfterSelectInsertPoint(criteriaComment.Length, sql.Replace(criteriaComment, String.Empty));
            else
                return GetAfterSelectInsertPoint(0, sql);
        }
Exemplo n.º 3
0
 /// <summary>
 /// MS Access and SQL Server support limit. This implementation has been made according the MS Access syntax
 /// </summary>
 /// <param name="querySqlString">The original query</param>
 /// <param name="offset">Specifies the number of rows to skip, before starting to return rows from the query expression.</param>
 /// <param name="limit">Is used to limit the number of results returned in a SQL statement</param>
 /// <returns>Processed query</returns>
 public override SqlString GetLimitString(SqlString querySqlString, int offset, int limit)
 {
     return querySqlString.Replace("select", string.Format("select top {0}", limit));
 }
		public void Replace() 
		{
			SqlString sql = new SqlString( new object[] {"select ", "from table ", "where a = ", new Parameter( "p1" ), " and c = ", new Parameter( "p2" ) } );
			
			SqlString replacedSql = sql.Replace( "table", "replacedTable" );
			Assert.AreEqual( "select from replacedTable where a = ", replacedSql.SqlParts[0], "replaced single instance" );

			replacedSql = sql.Replace( "not found", "not in here" );
			Assert.AreEqual( sql.ToString(), replacedSql.ToString(), "replace no found string" );

			replacedSql = sql.Replace( "le", "LE" );
			Assert.AreEqual( "seLEct from tabLE where a = ", replacedSql.SqlParts[0], "multi-match replace" );
			Assert.IsTrue( replacedSql.SqlParts[1] is Parameter, "multi-match replace - Param 1" );
			Assert.AreEqual(" and c = ", replacedSql.SqlParts[2], "multi-match replace" );
			Assert.IsTrue( replacedSql.SqlParts[3] is Parameter, "multi-match replace - Param 2" );
			
		}