Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Renamed DeleteTable to DropTable and added a test for it

  • Loading branch information...
commit 0c333f46eaa9dc8f572664a3d916cd613f9d3f9a 1 parent ea85640
@praeclarum praeclarum authored
Showing with 58 additions and 16 deletions.
  1. +4 −16 src/SQLite.cs
  2. +53 −0 tests/DropTableTest.cs
  3. +1 −0  tests/SQLite.Tests.csproj
View
20 src/SQLite.cs
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2009-2011 Krueger Systems, Inc.
+// Copyright (c) 2009-2012 Krueger Systems, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -210,25 +210,13 @@ private struct IndexInfo
/// <summary>
/// Executes a "drop table" on the database. This is non-recoverable.
/// </summary>
- public int DeleteTable<T>()
+ public int DropTable<T>()
{
- var ty = typeof(T);
+ var map = GetMapping (typeof (T));
- if (_tables == null)
- {
- _tables = new Dictionary<string, TableMapping>();
- }
- TableMapping map;
- if (!_tables.TryGetValue(ty.FullName, out map))
- {
- map = GetMapping(ty);
- _tables.Add(ty.FullName, map);
- }
var query = string.Format("drop table \"{0}\"", map.TableName);
- var count = Execute(query);
-
- return count;
+ return Execute (query);
}
/// <summary>
View
53 tests/DropTableTest.cs
@@ -0,0 +1,53 @@
+
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using SQLite;
+
+using NUnit.Framework;
+
+namespace SQLite.Tests
+{
+ [TestFixture]
+ public class DropTableTest
+ {
+ public class Product
+ {
+ [AutoIncrement, PrimaryKey]
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public decimal Price { get; set; }
+ }
+
+ public class TestDb : SQLiteConnection
+ {
+ public TestDb () : base(Path.GetTempFileName ())
+ {
+ Trace = true;
+ }
+ }
+
+ [Test, ExpectedException (typeof (SQLiteException))]
+ public void CreateInsertDrop ()
+ {
+ var db = new TestDb ();
+
+ db.CreateTable<Product> ();
+
+ db.Insert (new Product {
+ Name = "Hello",
+ Price = 16,
+ });
+
+ var n = db.Table<Product> ().Count ();
+
+ Assert.AreEqual (1, n);
+
+ db.DropTable<Product> ();
+
+ db.Table<Product> ().Count (); // Should throw
+ }
+ }
+}
View
1  tests/SQLite.Tests.csproj
@@ -45,5 +45,6 @@
<Compile Include="CollateTest.cs" />
<Compile Include="ContainsTest.cs" />
<Compile Include="NullableTest.cs" />
+ <Compile Include="DropTableTest.cs" />
</ItemGroup>
</Project>
Please sign in to comment.
Something went wrong with that request. Please try again.