From 93dd961a30d3d41a7d97c2738d4268ff46d789eb Mon Sep 17 00:00:00 2001 From: kougyokugentou <41278462+kougyokugentou@users.noreply.github.com> Date: Sat, 9 May 2020 21:50:24 -0700 Subject: [PATCH] bugfix: GetStudentByDbID where dbid_in < 1 should return null. --- SqliteDataAccess.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SqliteDataAccess.cs b/SqliteDataAccess.cs index 17faad4..d8b19cf 100644 --- a/SqliteDataAccess.cs +++ b/SqliteDataAccess.cs @@ -54,10 +54,17 @@ namespace DBWizard */ public Student GetStudentByDbID(int dbid_in) { + /* protect query from 0 or negative indexes. + * this is needed when creating a new student + * as dbid_in will be zero. + */ + if (dbid_in < 1) + return null; + using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { string strQuery = "SELECT * FROM students WHERE id=@id"; - var stu_out = cnn.Query(strQuery, new { id = dbid_in }).Single(); + Student stu_out = cnn.Query(strQuery, new { id = dbid_in }).Single(); return stu_out; }