public void BuildExpression_EmptyExpression() { MySQLBuilder builder = new MySQLBuilder(); StringBuilder sBuilder = new StringBuilder(); Assert.Throws(typeof(IncompleteQueryException), () => builder.BuildExpression(sBuilder)); }
public void Main() { Director director = new Director(); Console.WriteLine("Cadena de conexión del SQL Server"); SQLServerBuilder CadenaBuilder = new SQLServerBuilder(); director.CrearConexion(CadenaBuilder); SQLServer sQLServer = CadenaBuilder.GetResult(); sQLServer.Imprimir(); Console.WriteLine("\nCadena de conexión del MySQL "); MySQLBuilder CadenaMySQLBuilder = new MySQLBuilder(); director.CrearConexion(CadenaMySQLBuilder); MySQL mySQL = CadenaMySQLBuilder.GetResult(); mySQL.Imprimir(); Console.WriteLine("\n Cadena de conexión del Access"); AccessBuilder CadenaAccessBuilder = new AccessBuilder(); director.CrearConexion(CadenaAccessBuilder); Access Access = CadenaAccessBuilder.GetResult(); Access.Imprimir(); Console.ReadLine(); }
public void BuildExpression_ANSIJoin() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("id"); sqlBuilder.AddFromClause("foo"); sqlBuilder.AddJoinClause("LEFT JOIN", "bar", "bar.id = foo.id"); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT id FROM foo LEFT JOIN bar ON bar.id = foo.id;", stringBuilder.ToString()); }
public void BuildExpression_Limit() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("id"); sqlBuilder.AddFromClause("employees"); sqlBuilder.SkipResults(100); sqlBuilder.TakeResults(10); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT id FROM employees LIMIT 100, 10;", stringBuilder.ToString()); }
public void BuildExpression_Count() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("id"); sqlBuilder.AddSelectClause("name"); sqlBuilder.AddFromClause("employees"); sqlBuilder.AddCountClause(typeof(Employee)); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT COUNT(*) AS numrows FROM employees;", stringBuilder.ToString()); }
static void Main(string[] args) { var director = new Director(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********************************************"); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Elige la cadena que desea generar: "); Console.WriteLine("1 - Access"); Console.WriteLine("2 - MySQL"); Console.WriteLine("3 - SQL"); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("********************************************"); Console.ResetColor(); int iTipoCadena = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Crear Conexión:"); switch (iTipoCadena) { case 1: AccessBuilder accessBuilder = new AccessBuilder(); director.Builder = accessBuilder; director.AccessConection(); Console.WriteLine(accessBuilder.GetResult().ConnectionString()); break; case 2: MySQLBuilder mySQLBuilder = new MySQLBuilder(); director.Builder = mySQLBuilder; director.MySQLConection(); Console.WriteLine(mySQLBuilder.GetResult().ConnectionString()); break; case 3: SQLBuilder sqlBuilder = new SQLBuilder(); director.Builder = sqlBuilder; director.SQLConection(); Console.WriteLine(sqlBuilder.GetResult().ConnectionString()); break; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("\r\nPresione una tecla para salir."); Console.ReadKey(); }
public void BuildExpression_OrderBy() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("id"); sqlBuilder.AddFromClause("employees"); sqlBuilder.AddOrderByClause("name", SortDirection.Descending); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT id FROM employees ORDER BY name DESC;", stringBuilder.ToString()); }
public void Clone_SimpleTest() { SQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("name"); sqlBuilder.AddFromClause("employees"); sqlBuilder.AddWhereClause("id=42", ExpressionType.And); SQLBuilder clonedBuilder = (SQLBuilder) sqlBuilder.Clone(); sqlBuilder.AddCountClause(typeof(Employee)); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT COUNT(*) AS numrows FROM employees WHERE id=42 ;", stringBuilder.ToString()); stringBuilder = new StringBuilder(); clonedBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT name FROM employees WHERE id=42 ;", stringBuilder.ToString()); }
public void BuildExpression_TypeSelect() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectTypeClause("employees", typeof(Employee)); sqlBuilder.AddFromClause("employees"); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT employees.id AS employee_id, employees.name AS employee_name FROM employees;", stringBuilder.ToString()); }
public void BuildExpression_TrivialSelectTrivialWhere() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("1"); sqlBuilder.AddWhereClause("1 = 0", ExpressionType.Or); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT 1 WHERE 1 = 0 ;", stringBuilder.ToString()); }
public void BuildExpression_TrivialSelect() { MySQLBuilder builder = new MySQLBuilder(); builder.AddSelectClause("1"); StringBuilder sBuilder = new StringBuilder(); builder.BuildExpression(sBuilder); Assert.AreEqual("SELECT DISTINCT 1;", sBuilder.ToString()); }
public void BuildExpression_SelectFromWhere() { MySQLBuilder sqlBuilder = new MySQLBuilder(); sqlBuilder.AddSelectClause("name"); sqlBuilder.AddFromClause("employees"); sqlBuilder.AddWhereClause("id=42", ExpressionType.And); StringBuilder stringBuilder = new StringBuilder(); sqlBuilder.BuildExpression(stringBuilder); Assert.AreEqual("SELECT DISTINCT name FROM employees WHERE id=42 ;", stringBuilder.ToString()); }