Permalink
Browse files

Add a test for prepared inserts

git-svn-id: http://fracture.googlecode.com/svn/trunk@418 1953d6fe-3836-0410-a91e-07494a8b0067
  • Loading branch information...
1 parent 0f65795 commit afe4ff5d9547b2b25410b9f4ac64f38aa8188bb6 kevin.gadd committed Mar 17, 2011
Binary file not shown.
Binary file not shown.
@@ -373,11 +373,15 @@ public class PreparedInsert : IDisposable {
Table = tableName;
var typeColumns = ColumnNames;
+ int numExtraColumns = 0;
+ if (extraColumns != null)
+ numExtraColumns = extraColumns.Length;
- Columns = new string[typeColumns.Length + extraColumns.Length];
+ Columns = new string[typeColumns.Length + numExtraColumns];
Array.Copy(typeColumns, Columns, typeColumns.Length);
- Array.Copy(extraColumns, 0, Columns, typeColumns.Length, extraColumns.Length);
+ if (numExtraColumns > 0)
+ Array.Copy(extraColumns, 0, Columns, typeColumns.Length, extraColumns.Length);
var sql = BuildSQL();
Query = Connection.BuildQuery(sql);
@@ -54,7 +54,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DefineConstants>TRACE;DEBUG;SQLITE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
@@ -97,7 +97,7 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.SQLite">
- <HintPath>..\..\..\..\..\..\..\..\Program Files (x86)\SQLite.NET\bin\System.Data.SQLite.dll</HintPath>
+ <HintPath>..\..\..\Ext\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
@@ -590,6 +590,30 @@ public class NullableInt {
Assert.AreEqual(null, items[1].Foo);
}
}
+
+ [Test]
+ public void TestPreparedInsert () {
+ var value = new ExplicitlyMappedClass {
+ Bar = 1, Foo = 2
+ };
+
+ // Foo is a numeric column, so prepared inserts will use Foo as a default column name
+ // But Bar has a column name explicitly set to B
+ Scheduler.WaitFor(Wrapper.ExecuteSQL("CREATE TEMPORARY TABLE Test (Foo INTEGER, B INTEGER)"));
+
+ using (var pi = Mapper<ExplicitlyMappedClass>.PrepareInsert(Wrapper, "Test"))
+ Scheduler.WaitFor(pi.Insert(value));
+
+ using (var q = Wrapper.BuildQuery("SELECT Foo, B FROM Test"))
+ using (var e = q.Execute<ExplicitlyMappedClass>()) {
+ var items = (ExplicitlyMappedClass[])Scheduler.WaitFor(e.GetArray());
+
+ Assert.AreEqual(1, items.Length);
+
+ Assert.AreEqual(1, items[0].Bar);
+ Assert.AreEqual(2, items[0].Foo);
+ }
+ }
}
[TestFixture]

0 comments on commit afe4ff5

Please sign in to comment.