Skip to content

Commit

Permalink
error checking for ExecuteScalar
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Sink authored and Eric Sink committed Mar 19, 2013
1 parent 9fdc7de commit 32910bf
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/SQLite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,11 +1889,25 @@ public T ExecuteScalar<T> ()
T val = default(T);

var stmt = Prepare ();
if (SQLite3.Step (stmt) == SQLite3.Result.Row) {
var colType = SQLite3.ColumnType (stmt, 0);
val = (T)ReadCol (stmt, 0, colType, typeof(T));
}
Finalize (stmt);

try
{
var r = SQLite3.Step (stmt);
if (r == SQLite3.Result.Row) {
var colType = SQLite3.ColumnType (stmt, 0);
val = (T)ReadCol (stmt, 0, colType, typeof(T));
}
else if (r == SQLite3.Result.Done) {
}
else
{
throw SQLiteException.New (r, SQLite3.GetErrmsg (_conn.Handle));
}
}
finally
{
Finalize (stmt);
}

return val;
}
Expand Down

0 comments on commit 32910bf

Please sign in to comment.