Skip to content

Commit

Permalink
implement the proposed chg of the default for enable of sqlite3_next_…
Browse files Browse the repository at this point in the history
…stmt to OFF. and update the test case accordingly. see #255
  • Loading branch information
ericsink committed Mar 1, 2019
1 parent 3fb6f59 commit 65beba0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/SQLitePCLRaw.core/intptrs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ internal static sqlite3 New(IntPtr p)
{
var h = new sqlite3();
h.SetHandle(p);
#if true // TODO consider changing this to default OFF for v2
#if not // changing this to default OFF for v2
h.enable_sqlite3_next_stmt(true);
#endif
return h;
Expand Down Expand Up @@ -284,6 +284,7 @@ internal sqlite3_stmt find_stmt(IntPtr p)
}
else
{
// any change to the wording of this error message might break a test case
throw new Exception("The sqlite3_next_stmt() function is disabled. To enable it, call sqlite3.enable_sqlite3_next_stmt(true) immediately after opening the sqlite3 connection.");
}
}
Expand Down
75 changes: 65 additions & 10 deletions src/common/tests_xunit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -814,16 +814,71 @@ public void test_stmt_complete()
[Fact]
public void test_next_stmt()
{
using (sqlite3 db = ugly.open(":memory:"))
{
Assert.Equal(db.next_stmt(null), null);
using (sqlite3_stmt stmt = db.prepare("SELECT 5;"))
{
Assert.Equal(db.next_stmt(null), stmt);
Assert.Equal(db.next_stmt(stmt), null);
}
Assert.Equal(db.next_stmt(null), null);
}
const int ENABLE_DEFAULT = 1;
const int ENABLE_OFF = 2;
const int ENABLE_ON = 3;
void tryit(int enable)
{
using (sqlite3 db = ugly.open(":memory:"))
{
switch (enable)
{
case ENABLE_DEFAULT:
// do nothing
break;
case ENABLE_OFF:
db.enable_sqlite3_next_stmt(false);
break;
case ENABLE_ON:
db.enable_sqlite3_next_stmt(true);
break;
default:
throw new NotImplementedException();
}

Assert.Equal(db.next_stmt(null), null);
using (sqlite3_stmt stmt = db.prepare("SELECT 5;"))
{
Assert.Equal(db.next_stmt(null), stmt);
Assert.Equal(db.next_stmt(stmt), null);
}
Assert.Equal(db.next_stmt(null), null);
}
}

void should_throw(Action f, string err_should_contain)
{
bool threw;
try
{
f();
threw = false;
}
catch (Exception e)
{
if (e.ToString().Contains(err_should_contain))
{
threw = true;
}
else
{
// yeah, it threw, but not the error we were looking for
threw = false;
}
}
Assert.True(threw);
}

var msg_should_contain = "is disabled. To enable it, call sqlite3.enable_sqlite3_next_stmt(true)";
should_throw(
() => tryit(ENABLE_DEFAULT),
msg_should_contain
);
should_throw(
() => tryit(ENABLE_OFF),
msg_should_contain
);
tryit(ENABLE_ON);
}

[Fact]
Expand Down

0 comments on commit 65beba0

Please sign in to comment.