Permalink
Browse files

Started Updating Tests and Processors to correctly escape generated SQL

  • Loading branch information...
abusby committed Feb 17, 2011
1 parent 32548c8 commit 7c3899536f6f8071cee0c9df9097ab48161eea0e
View
BIN +105 KB lib/Moq.Contrib.dll
Binary file not shown.
View
BIN +230 KB (190%) lib/Moq.dll
Binary file not shown.
View
BIN +56 KB (170%) lib/nunit.framework.dll
Binary file not shown.
View
BIN +0 Bytes (100%) lib/nunit.should.dll
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -4,18 +4,22 @@
namespace FluentMigrator.Runner.Generators
{
class SqliteColumn : ColumnBase
{
{
protected override bool CanSeperatePrimaryKeyAndIdentity { get { return false; } }
public SqliteColumn() : base(new SqliteTypeMap(), new ConstantFormatter())
{
}
protected override string FormatName(ColumnDefinition column)
{
return string.Format("[{0}]",column.Name);
}
protected override string FormatIdentity(ColumnDefinition column)
{
//SQLite only supports the concept of Identity in combination with a single primary key
//see: http://www.sqlite.org/syntaxdiagrams.html#column-constraint syntax details
return string.Empty;
//SQLite only supports the concept of Identity in combination with a single primary key
//see: http://www.sqlite.org/syntaxdiagrams.html#column-constraint syntax details
return string.Empty;
}
protected override string FormatPrimaryKey(ColumnDefinition column)
@@ -217,7 +217,7 @@ public override string Generate(CreateIndexExpression expression)
if (expression.Index.IsUnique)
result.Append(" UNIQUE");
result.Append(" INDEX IF NOT EXISTS {0} ON {1} (");
result.Append(" INDEX IF NOT EXISTS [{0}[ ON [{1}] (");
bool first = true;
foreach (IndexColumnDefinition column in expression.Index.Columns)
@@ -236,7 +236,7 @@ public override string Generate(CreateIndexExpression expression)
public override string Generate(DeleteIndexExpression expression)
{
return String.Format("DROP INDEX IF EXISTS {0}", expression.Index.Name);
return String.Format("DROP INDEX IF EXISTS [{0}]", expression.Index.Name);
}
}
}
@@ -47,7 +47,7 @@ public override bool TableExists(string tableName)
public override bool ColumnExists(string tableName, string columnName)
{
return Read("PRAGMA table_info({0})",tableName).Tables[0].Select(string.Format("Name='{0}'",columnName.Replace("'","''"))).Length>0;
return Read("PRAGMA table_info([{0}])",tableName).Tables[0].Select(string.Format("Name='{0}'",columnName.Replace("'","''"))).Length>0;
}
public override bool ConstraintExists(string tableName, string constraintName)
@@ -87,7 +87,7 @@ public override bool Exists(string template, params object[] args)
public override DataSet ReadTableData(string tableName)
{
return Read("select * from {0}", tableName);
return Read("select * from [{0}]", tableName);
}
public override void Process(PerformDBOperationExpression expression)
@@ -140,7 +140,7 @@ private void ExecuteBatchNonQuery(string sql, SQLiteConnection conn)
{
sql += "\nGO"; // make sure last batch is executed.
string sqlBatch = string.Empty;
using (var command = new SQLiteCommand(sql, Connection))
{
try
@@ -99,15 +99,15 @@
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Moq, Version=2.6.1014.1, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<Reference Include="Moq, Version=3.1.416.3, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Moq.dll</HintPath>
</Reference>
<Reference Include="MySql.Data, Version=1.0.10.1, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=2.4.6.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<Reference Include="nunit.framework, Version=2.5.9.10320, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\nunit.framework.dll</HintPath>
</Reference>
@@ -39,6 +39,7 @@ public class SqliteProcessorTests
private SQLiteCommand command;
private string columnName;
private string tableName;
private string tableNameThanMustBeEscaped;
[SetUp]
public void SetUp()
@@ -52,7 +53,8 @@ public void SetUp()
processor = new SqliteProcessor(connection, new SqliteGenerator(), new TextWriterAnnouncer(System.Console.Out), new ProcessorOptions());
column = new Mock<ColumnDefinition>();
tableName = "NewTable";
tableName = "NewTable";
tableNameThanMustBeEscaped = "123NewTable";
columnName = "ColumnName";
column.SetupGet(c => c.Name).Returns(columnName);
column.SetupGet(c => c.IsNullable).Returns(true);
@@ -94,12 +96,43 @@ public void CanCreateTableExpression()
}
}
public void InsertTable()
{
SQLiteCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = string.Format("CREATE TABLE {0} ({1})", tableName, columnName);
cmd.ExecuteNonQuery();
}
[Test]
public void IsEscapingTableNameCorrectlyOnTableCreate()
{
CreateTableExpression expression = new CreateTableExpression { TableName = tableNameThanMustBeEscaped };
expression.Columns.Add(column.Object);
processor.Process(expression);
}
[Test]
public void IsEscapingTableNameCorrectlyOnReadTableData()
{
CreateTableExpression expression = new CreateTableExpression { TableName = tableNameThanMustBeEscaped };
expression.Columns.Add(column.Object);
processor.Process(expression);
processor.ReadTableData(tableNameThanMustBeEscaped).Tables.Count.ShouldBe(1);
}
[Test]
public void IsEscapingTableNameCorrectlyOnTableExists()
{
CreateTableExpression expression = new CreateTableExpression { TableName = tableNameThanMustBeEscaped };
expression.Columns.Add(column.Object);
processor.Process(expression);
processor.TableExists(tableNameThanMustBeEscaped).ShouldBeTrue();
}
[Test]
public void IsEscapingTableNameCorrectlyOnColumnExists()
{
string columnName = "123ColumnName";
CreateTableExpression expression = new CreateTableExpression { TableName = tableNameThanMustBeEscaped };
expression.Columns.Add(new ColumnDefinition() { Name = "123ColumnName", Type = DbType.AnsiString, IsNullable = true });
processor.Process(expression);
processor.ColumnExists(tableNameThanMustBeEscaped, columnName).ShouldBeTrue();
}
}
}
@@ -86,19 +86,19 @@ public void CustomTypeIsBare()
{
formatter.Format(new CustomClass())
.ShouldBe("CustomClass");
}
[Test]
public void EnumIsFormattedAsString()
{
formatter.Format(Foo.Bar)
.ShouldBe("'Bar'");
}
[Test]
public void EnumIsFormattedAsString()
{
formatter.Format(Foo.Bar)
.ShouldBe("'Bar'");
}
private enum Foo
{
Bar,
Baz
private enum Foo
{
Bar,
Baz
}
private class CustomClass
@@ -63,7 +63,7 @@ public void CanAddColumn()
expression.TableName = tableName;
var sql = generator.Generate(expression);
sql.ShouldBe("ALTER TABLE [NewTable] ADD NewColumn NVARCHAR(5) NOT NULL");
sql.ShouldBe("ALTER TABLE [NewTable] ADD [NewColumn] NVARCHAR(5) NOT NULL");
}
[Test]
@@ -82,7 +82,7 @@ public void CanAddDecimalColumn()
expression.TableName = tableName;
var sql = generator.Generate(expression);
sql.ShouldBe("ALTER TABLE [NewTable] ADD NewColumn DECIMAL(19,2) NOT NULL");
sql.ShouldBe("ALTER TABLE [NewTable] ADD [NewColumn] DECIMAL(19,2) NOT NULL");
}
[Test]
@@ -97,7 +97,7 @@ public void CanCreateForeignKey()
var sql = generator.Generate(expression);
sql.ShouldBe(
"ALTER TABLE [TestForeignTable] ADD CONSTRAINT FK_Test FOREIGN KEY ([Column3],[Column4]) REFERENCES [TestPrimaryTable] ([Column1],[Column2])");
"ALTER TABLE [TestForeignTable] ADD CONSTRAINT [FK_Test] FOREIGN KEY ([Column3],[Column4]) REFERENCES [TestPrimaryTable] ([Column1],[Column2])");
}
[Test]
@@ -229,12 +229,13 @@ public void CanInsertGuidData()
public void CanRenameColumn()
{
var expression = new RenameColumnExpression();
expression.SchemaName = "Schema1";
expression.TableName = "Table1";
expression.OldName = "Column1";
expression.NewName = "Column2";
var sql = generator.Generate(expression);
sql.ShouldBe("sp_rename '[Table1].[Column1]', 'Column2'");
sql.ShouldBe("sp_rename '[Schema1].[Table1].[Column1]', 'Column2'");
}
[Test]
Oops, something went wrong.

0 comments on commit 7c38995

Please sign in to comment.