summaryrefslogtreecommitdiff
path: root/Aktywator
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2017-07-30 14:23:45 +0200
committeremkael <emkael@tlen.pl>2017-07-30 14:26:59 +0200
commit808116c88329954ce07280fb6caf12d60c5b59df (patch)
tree6e0c4d472dafa18dc7817e3282c8508b64a610e1 /Aktywator
parent915e4fd49087c38a2559f08512db5d2e2cfb37bc (diff)
Sql.selectOne now can distinguish no value in result row from no result at all
Diffstat (limited to 'Aktywator')
-rw-r--r--Aktywator/Sql.cs17
1 files changed, 14 insertions, 3 deletions
diff --git a/Aktywator/Sql.cs b/Aktywator/Sql.cs
index c35b0dd..cf0eb38 100644
--- a/Aktywator/Sql.cs
+++ b/Aktywator/Sql.cs
@@ -7,6 +7,10 @@ using data = System.Data.OleDb.OleDbDataReader;
namespace Aktywator
{
+ class OleDbRowMissingException : Exception
+ {
+ }
+
class Sql
{
private OleDbConnection connection;
@@ -34,12 +38,19 @@ namespace Aktywator
OleDbCommand cmd = new OleDbCommand(q, connection);
return cmd.ExecuteNonQuery();
}
- public string selectOne(string q)
+ public string selectOne(string q, bool checkForRow = false)
{
OleDbCommand cmd = new OleDbCommand(q, connection);
object o = cmd.ExecuteScalar();
- if (o == null) return "";
- else return o.ToString();
+ if (o == null) // it's null if the row does not exist, it'd be DBNull.Value if NULL was the value in existing row
+ {
+ if (!checkForRow)
+ {
+ return "";
+ }
+ throw new OleDbRowMissingException();
+ }
+ return o.ToString();
}
public data select(string q)
{