refactor db_subscr_ps() to db_subscr_nam()

Allow to set nam_ps and nam_cs from this same function, by adding the is_ps
arg.

Combine both NAM_PS stmts to DB_STMT_UPD_NAM_PS_BY_IMSI, add another such stmt
for CS. Use named parameters instead of parameter indexes.

Improve error return values as well as error logging to clearly indicate
whether the operation could not find the requested IMSI, or other errors
occured.

Adjust the single caller.

This prepares for upcoming VTY and possibly CTRL commands, and the error
handling introduced here has been or will be adopted by other functions in
previous or subsequent patches.

Change-Id: I6e70e15228f5bb10bee6758ae5dc9687d65839bd
diff --git a/tests/db/db_test.c b/tests/db/db_test.c
index 250b363..30de51d 100644
--- a/tests/db/db_test.c
+++ b/tests/db/db_test.c
@@ -244,6 +244,45 @@
 	ASSERT_RC(db_subscr_update_msisdn_by_imsi(dbc, "foobar", "99"), -ENOENT);
 	ASSERT_SEL(msisdn, "99", -ENOENT);
 
+	comment("Set / unset nam_cs and nam_ps");
+
+	/*                                nam_val, is_ps */
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+
+	comment("Set / unset nam_cs and nam_ps *again*");
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, false, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, true), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+	ASSERT_RC(db_subscr_nam(dbc, imsi0, true, false), 0);
+	ASSERT_SEL(imsi, imsi0, 0);
+
+	comment("Set nam_cs and nam_ps on non-existent / invalid IMSI");
+
+	ASSERT_RC(db_subscr_nam(dbc, unknown_imsi, false, true), -ENOENT);
+	ASSERT_RC(db_subscr_nam(dbc, unknown_imsi, false, false), -ENOENT);
+	ASSERT_SEL(imsi, unknown_imsi, -ENOENT);
+
+	ASSERT_RC(db_subscr_nam(dbc, "foobar", false, true), -ENOENT);
+	ASSERT_RC(db_subscr_nam(dbc, "foobar", false, false), -ENOENT);
+
 	comment("Delete non-existent / invalid IDs");
 
 	ASSERT_RC(db_subscr_delete_by_id(dbc, 999), -ENOENT);