public void ShouldInsertBeginAndEndTransactionStatementsForEachDelta()
    	{
			const string deltaScriptContent = @"foo bar";
			using (StreamWriter stream = script.GetFile().CreateText())
				stream.Write(deltaScriptContent);

    		StringWriter writer = new StringWriter();
    		MsSqlDbmsSyntax syntax = new MsSqlDbmsSyntax();
    		ChangeScriptExecuter executer = new ChangeScriptExecuter(writer, syntax, true);
			executer.ApplyChangeDoScript(script);

    		string deltaFragment = writer.ToString();

			Console.Write(deltaFragment);

			string expectedBegin = syntax.GenerateBeginTransaction();
			int startOfBegin = deltaFragment.IndexOf(deltaScriptContent) - expectedBegin.Length - Environment.NewLine.Length;
    		string resultBegin = deltaFragment.Substring(startOfBegin, expectedBegin.Length);

			Assert.AreEqual(expectedBegin, resultBegin);

			string expectedCommit = syntax.GenerateCommitTransaction();
			int startOfCommit = deltaFragment.IndexOf(deltaScriptContent) + deltaScriptContent.Length + Environment.NewLine.Length;
			string resultCommit = deltaFragment.Substring(startOfCommit, expectedCommit.Length);

			Assert.AreEqual(expectedCommit, resultCommit);
		}
 public virtual IDbmsSyntax CreateDbmsSyntax()
 {
     IDbmsSyntax dmDbmsSyntax;
     
     switch (dbms)
     {
         case SupportedDbms.ORACLE:
             dmDbmsSyntax = new OracleDbmsSyntax();
             break;
         case SupportedDbms.MSSQL:
             dmDbmsSyntax = new MsSqlDbmsSyntax();
             break;
         case SupportedDbms.MYSQL:
             dmDbmsSyntax = new MySqlDbmsSyntax();
             break;
         case SupportedDbms.FIREBIRD:
             dmDbmsSyntax = new FirebirdDbmsSyntax();
             break;
         case SupportedDbms.POSTGRE:
             dmDbmsSyntax = new PostgreDbmsSyntax();
             break;
         case SupportedDbms.SYBASE:
             dmDbmsSyntax = new SybaseDbmsSyntax();
             break;
         default:
             throw new DbmsNotSupportedException("Supported dbms: ora, mssql, mysql, firebird, postgre, sybase");
     }
     dmDbmsSyntax.SetDefaultDatabaseName(connectionString);
     return dmDbmsSyntax;
 }
Example #3
0
        /// <summary>
        /// Ensures the table does not exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        protected override void EnsureTableDoesNotExist(string tableName)
        {
            var syntax    = new MsSqlDbmsSyntax();
            var tableInfo = syntax.GetTableInfo(tableName);

            ExecuteSql(string.Format(
                           CultureInfo.InvariantCulture,
                           @"IF (EXISTS (SELECT * 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_NAME = '{0}'))
BEGIN
    DROP Table {0}
END", tableInfo.TableName));
        }
    	public void ShouldNotInsertBeginOrEndTransactionStatementIfPropertyIsNotSet()
    	{
			const string deltaScriptContent = @"foo bar";
			using (StreamWriter stream = script.GetFile().CreateText())
				stream.Write(deltaScriptContent);

			StringWriter writer = new StringWriter();
			MsSqlDbmsSyntax syntax = new MsSqlDbmsSyntax();
			ChangeScriptExecuter executer = new ChangeScriptExecuter(writer, syntax, false);
			executer.ApplyChangeDoScript(script);

			string deltaFragment = writer.ToString();

			Console.Write(deltaFragment);

    		int beingIndex = deltaFragment.IndexOf(syntax.GenerateBeginTransaction());
			Assert.AreEqual(-1, beingIndex);

    		int endIndex = deltaFragment.IndexOf(syntax.GenerateCommitTransaction());
			Assert.AreEqual(-1, endIndex);
		}
Example #5
0
        public virtual IDbmsSyntax CreateDbmsSyntax()
        {
            IDbmsSyntax dmDbmsSyntax;

            switch (dbms)
            {
            case SupportedDbms.ORACLE:
                dmDbmsSyntax = new OracleDbmsSyntax();
                break;

            case SupportedDbms.MSSQL:
                dmDbmsSyntax = new MsSqlDbmsSyntax();
                break;

            case SupportedDbms.MYSQL:
                dmDbmsSyntax = new MySqlDbmsSyntax();
                break;

            case SupportedDbms.FIREBIRD:
                dmDbmsSyntax = new FirebirdDbmsSyntax();
                break;

            case SupportedDbms.POSTGRE:
                dmDbmsSyntax = new PostgreDbmsSyntax();
                break;

            case SupportedDbms.SYBASE:
                dmDbmsSyntax = new SybaseDbmsSyntax();
                break;

            default:
                throw new DbmsNotSupportedException("Supported dbms: ora, mssql, mysql, firebird, postgre, sybase");
            }
            dmDbmsSyntax.SetDefaultDatabaseName(connectionString);
            return(dmDbmsSyntax);
        }
        /// <summary>
        /// Ensures the table does not exist.
        /// </summary>
        /// <param name="tableName">Name of the table.</param>
        protected override void EnsureTableDoesNotExist(string tableName)
        {
            var syntax = new MsSqlDbmsSyntax();
            var tableInfo = syntax.GetTableInfo(tableName);
            this.ExecuteSql(string.Format(
                CultureInfo.InvariantCulture,
@"IF (EXISTS (SELECT * 
    FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_SCHEMA = '{0}' 
    AND  TABLE_NAME = '{1}'))
BEGIN
    DROP Table {0}.{1}
END", 
                tableInfo.Schema, tableInfo.TableName));
        }