| 5326 | } |
| 5327 | |
| 5328 | static void comdb2AddIndexInt( |
| 5329 | Parse *pParse, /* All information about this parse */ |
| 5330 | char *keyname, /* Index name (Optional) */ |
| 5331 | ExprList *pList, /* A list of columns to be indexed */ |
| 5332 | int onError, /* OE_Abort, OE_Ignore, OE_Replace, or OE_None */ |
| 5333 | Expr *pPIWhere, /* WHERE clause for partial indices */ |
| 5334 | const char *zStart, /* Start of WHERE clause token text */ |
| 5335 | const char *zEnd, /* End of WHERE clause token text */ |
| 5336 | int sortOrder, /* Sort order of primary key when pList==NULL */ |
| 5337 | u8 idxType, /* The index type */ |
| 5338 | int withOpts, /* WITH options (DATACOPY) */ |
| 5339 | ExprList *pdList /* A list of columns in the partial datacopy */ |
| 5340 | ) |
| 5341 | { |
| 5342 | struct comdb2_ddl_context *ctx = pParse->comdb2_ddl_ctx; |
| 5343 | struct comdb2_key *key; |
| 5344 | |
| 5345 | if (use_sqlite_impl(pParse)) { |
| 5346 | assert(ctx == 0); |
| 5347 | assert(idxType != SQLITE_IDXTYPE_DUPKEY); |
| 5348 | sqlite3CreateIndex(pParse, 0, 0, 0, pList, onError, 0, 0, 0, 0, |
| 5349 | idxType); |
| 5350 | return; |
| 5351 | } |
| 5352 | |
| 5353 | if (ctx == 0) { |
| 5354 | /* An error must have been set. */ |
| 5355 | assert(pParse->rc != 0); |
| 5356 | return; |
| 5357 | } |
| 5358 | |
| 5359 | if ((ctx->flags & DDL_NOOP) != 0) { |
| 5360 | return; |
| 5361 | } |
| 5362 | |
| 5363 | key = comdb2_calloc(ctx->mem, 1, sizeof(struct comdb2_key)); |
| 5364 | if (key == 0) |
| 5365 | goto oom; |
| 5366 | |
| 5367 | if (keyname) { |
| 5368 | if (idxType != SQLITE_IDXTYPE_PRIMARYKEY && is_pk(keyname)) { |
| 5369 | pParse->rc = SQLITE_ERROR; |
| 5370 | sqlite3ErrorMsg(pParse, "Invalid key name '%s'.", keyname); |
| 5371 | goto cleanup; |
| 5372 | } |
| 5373 | key->name = keyname; |
| 5374 | } else { |
| 5375 | /* Key name not specified, will be generated later. */ |
| 5376 | } |
| 5377 | |
| 5378 | switch (idxType) { |
| 5379 | case SQLITE_IDXTYPE_APPDEF: |
| 5380 | /* For CREATE INDEX, we need to check onError */ |
| 5381 | if (onError != OE_Abort) { |
| 5382 | key->flags |= KEY_DUP; |
| 5383 | } else { |
| 5384 | key->flags |= KEY_UNIQNULLS; |
| 5385 | } |
no test coverage detected