aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_realtime.c
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-10-14 00:08:52 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2008-10-14 00:08:52 +0000
commit4d59ca26413ca59d0b59ae3600ebcc0e204b7018 (patch)
treedefa29805f9479efc7793b15f9e31a97dfe89603 /res/res_realtime.c
parent1078121ae0495b161d852f75b6cd8e1fb4c55463 (diff)
Merge realtime_update2 branch, which adds a new realtime API call named
'update2', which permits updates which match across multiple columns, instead of requiring all tables to have a single unique identifier. All of the other API calls with the exception of 'update' already had the ability to match on multiple fields, so it was a missing and very desireable feature that an API call implementing an update should have this, too. This does not change any outward performance of Asterisk, but it should make life easier for application developers who use the RealTime framework. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@148570 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res/res_realtime.c')
-rw-r--r--res/res_realtime.c143
1 files changed, 139 insertions, 4 deletions
diff --git a/res/res_realtime.c b/res/res_realtime.c
index 5ecff8b94..15e25beec 100644
--- a/res/res_realtime.c
+++ b/res/res_realtime.c
@@ -76,7 +76,8 @@ static char *cli_realtime_load(struct ast_cli_entry *e, int cmd, struct ast_cli_
return CLI_SUCCESS;
}
-static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) {
+static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
int res = 0;
switch (cmd) {
@@ -93,18 +94,149 @@ static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cl
return NULL;
}
-
if (a->argc < 7)
return CLI_SHOWUSAGE;
res = ast_update_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
- if(res < 0) {
+ if (res < 0) {
+ ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
+ }
+
+ ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
+
+ return CLI_SUCCESS;
+}
+
+static char *cli_realtime_update2(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime update2";
+ e->usage =
+ "Usage: realtime update2 <family> <colupdate> <newvalue> <colmatch> <valuematch> [... <colmatch5> <valuematch5>]\n"
+ " Update a single variable using the RealTime driver.\n"
+ " You must supply a family name, a column to update on, a new value, column to match, and value to match.\n"
+ " Ex: realtime update sipfriends name bobsphone port 4343\n"
+ " will execute SQL as UPDATE sipfriends SET port = 4343 WHERE name = bobsphone\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 7)
+ return CLI_SHOWUSAGE;
+
+ if (a->argc == 7) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 9) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 11) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 13) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 15) {
+ res = ast_update2_realtime(a->argv[2], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], a->argv[13], a->argv[14], SENTINEL, a->argv[3], a->argv[4], SENTINEL);
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (res < 0) {
ast_cli(a->fd, "Failed to update. Check the debug log for possible SQL related entries.\n");
return CLI_FAILURE;
}
- ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
+ ast_cli(a->fd, "Updated %d RealTime record%s.\n", res, ESS(res));
+
+ return CLI_SUCCESS;
+}
+
+static char *cli_realtime_store(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime store";
+ e->usage =
+ "Usage: realtime store <family> <colname1> <value1> [<colname2> <value2> [... <colmatch5> <valuematch5>]]\n"
+ " Create a stored row using the RealTime driver.\n"
+ " You must supply a family name and name/value pairs (up to 5). If\n"
+ " you need to store more than 5 key/value pairs, start with the first\n"
+ " five, then use 'realtime update' or 'realtime update2' to add\n"
+ " additional columns.\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 5) {
+ return CLI_SHOWUSAGE;
+ } else if (a->argc == 5) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 7) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
+ } else if (a->argc == 9) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
+ } else if (a->argc == 11) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
+ } else if (a->argc == 13) {
+ res = ast_store_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (res < 0) {
+ ast_cli(a->fd, "Failed to store record. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
+ }
+
+ ast_cli(a->fd, "Stored RealTime record.\n");
+
+ return CLI_SUCCESS;
+}
+
+static char *cli_realtime_destroy(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+ int res = -1;
+
+ switch (cmd) {
+ case CLI_INIT:
+ e->command = "realtime destroy";
+ e->usage =
+ "Usage: realtime destroy <family> <colname1> <value1> [<colname2> <value2> [... <colmatch5> <valuematch5>]]\n"
+ " Remove a stored row using the RealTime driver.\n"
+ " You must supply a family name and name/value pairs (up to 5).\n";
+ return NULL;
+ case CLI_GENERATE:
+ return NULL;
+ }
+
+ if (a->argc < 5) {
+ return CLI_SHOWUSAGE;
+ } else if (a->argc == 5) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], SENTINEL);
+ } else if (a->argc == 7) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], SENTINEL);
+ } else if (a->argc == 9) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], SENTINEL);
+ } else if (a->argc == 11) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], SENTINEL);
+ } else if (a->argc == 13) {
+ res = ast_destroy_realtime(a->argv[2], a->argv[3], a->argv[4], a->argv[5], a->argv[6], a->argv[7], a->argv[8], a->argv[9], a->argv[10], a->argv[11], a->argv[12], SENTINEL);
+ } else {
+ return CLI_SHOWUSAGE;
+ }
+
+ if (res < 0) {
+ ast_cli(a->fd, "Failed to remove record. Check the debug log for possible SQL related entries.\n");
+ return CLI_FAILURE;
+ }
+
+ ast_cli(a->fd, "Removed %d RealTime record%s.\n", res, ESS(res));
return CLI_SUCCESS;
}
@@ -112,6 +244,9 @@ static char *cli_realtime_update(struct ast_cli_entry *e, int cmd, struct ast_cl
static struct ast_cli_entry cli_realtime[] = {
AST_CLI_DEFINE(cli_realtime_load, "Used to print out RealTime variables."),
AST_CLI_DEFINE(cli_realtime_update, "Used to update RealTime variables."),
+ AST_CLI_DEFINE(cli_realtime_update2, "Used to test the RealTime update2 method"),
+ AST_CLI_DEFINE(cli_realtime_store, "Store a new row into a RealTime database"),
+ AST_CLI_DEFINE(cli_realtime_destroy, "Delete a row from a RealTime database"),
};
static int unload_module(void)