MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / process_set_command

Function process_set_command

cdb2api/cdb2api.c:4224–4309  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4222}
4223
4224static int process_set_command(cdb2_hndl_tp *hndl, const char *sql)
4225{
4226 int i, j, k;
4227
4228 if (hndl->in_trans) {
4229 sprintf(hndl->errstr, "Can't run set query inside transaction.");
4230 hndl->error_in_trans = CDB2ERR_BADREQ;
4231 hndl->client_side_error = 1;
4232 return CDB2ERR_BADREQ;
4233 }
4234
4235 int rc = process_ssl_set_command(hndl, sql);
4236 if (rc >= 0)
4237 return rc;
4238
4239 i = hndl->num_set_commands;
4240 if (i > 0) {
4241 int skip_len = 4;
4242 char *dup_sql = strdup(sql + skip_len);
4243 char *rest = NULL;
4244 char *set_tok = strtok_r(dup_sql, " ", &rest);
4245 /* special case for spversion */
4246 if (set_tok && strcasecmp(set_tok, "spversion") == 0) {
4247 skip_len += 10;
4248 set_tok = strtok_r(rest, " ", &rest);
4249 }
4250 /* special case for transaction chunk */
4251 if (set_tok && strncasecmp(set_tok, "transaction", 11) == 0) {
4252 char *set_tok2 = strtok_r(rest, " ", &rest);
4253 if (set_tok2 && strncasecmp(set_tok2, "chunk", 5) == 0) {
4254 /* skip "transaction" if chunk, set we can set
4255 * both transaction and chunk mode
4256 */
4257 skip_len += 12;
4258 set_tok = set_tok2;
4259 }
4260 }
4261 if (!set_tok) {
4262 free(dup_sql);
4263 return 0;
4264 }
4265 int len = strlen(set_tok);
4266
4267 for (j = 0; j < i; j++) {
4268 /* If this matches any of the previous commands. */
4269 if ((strncasecmp(&hndl->commands[j][skip_len], set_tok, len) ==
4270 0) &&
4271 (hndl->commands[j][len + skip_len] == ' ')) {
4272 free(dup_sql);
4273 if (j == (i - 1)) {
4274 if (strcmp(hndl->commands[j], sql) == 0) {
4275 /* Do Nothing. */
4276 } else {
4277 hndl->commands[i - 1] =
4278 realloc(hndl->commands[i - 1], strlen(sql) + 1);
4279 strcpy(hndl->commands[i - 1], sql);
4280 }
4281 } else {

Callers 2

cdb2_openFunction · 0.85

Calls 6

process_ssl_set_commandFunction · 0.85
freeFunction · 0.85
reallocFunction · 0.85
mallocFunction · 0.85
process_set_localFunction · 0.85
strdupFunction · 0.50

Tested by

no test coverage detected