return code of 1 means we encountered an error and the caller * needs to cleanup this rec->stmt */
| 511 | /* return code of 1 means we encountered an error and the caller |
| 512 | * needs to cleanup this rec->stmt */ |
| 513 | int stmt_cache_put_int(struct sqlthdstate *thd, struct sqlclntstate *clnt, |
| 514 | struct sql_state *rec, int noCache, int outrc, |
| 515 | int distributed) |
| 516 | { |
| 517 | if (noCache) { |
| 518 | goto cleanup; |
| 519 | } |
| 520 | if (gbl_enable_sql_stmt_caching == STMT_CACHE_NONE) { |
| 521 | goto cleanup; |
| 522 | } |
| 523 | if (distributed || clnt->conns || clnt->plugin.state) { |
| 524 | goto cleanup; |
| 525 | } |
| 526 | if (thd && thd->authState.numDdls > 0) { /* NOTE: Never cache DDL. */ |
| 527 | goto cleanup; |
| 528 | } |
| 529 | if (dont_cache_this_sql(rec)) { |
| 530 | goto cleanup; |
| 531 | } |
| 532 | sqlite3_stmt *stmt = rec->stmt; |
| 533 | if (stmt == NULL) { |
| 534 | goto cleanup; |
| 535 | } |
| 536 | if (gbl_enable_sql_stmt_caching == STMT_CACHE_PARAM && |
| 537 | param_count(clnt) == 0) { |
| 538 | goto cleanup; |
| 539 | } |
| 540 | if (bdb_attr_get(thedb->bdb_attr, BDB_ATTR_DISABLE_CACHING_STMT_WITH_FDB) && |
| 541 | sqlite3_stmt_has_remotes(stmt)) { |
| 542 | goto cleanup; |
| 543 | } |
| 544 | |
| 545 | if (rec->status & (CACHE_FOUND_STMT | CACHE_FOUND_STR)) { /* we found this stmt in the cache */ |
| 546 | if (rec->stmt_entry == NULL) { |
| 547 | query_data_func(clnt, NULL, NULL, QUERY_HINT_DATA, QUERY_DATA_SET); |
| 548 | } else { |
| 549 | if (rec->status & CACHE_HAS_HINT) { |
| 550 | /* Leave the ownership of stmt data. */ |
| 551 | query_data_func(clnt, NULL, NULL, QUERY_STMT_DATA, QUERY_DATA_SET); |
| 552 | } |
| 553 | if (stmt_cache_requeue_old_entry(thd->stmt_cache, rec->stmt_entry)) { /* put back in queue... */ |
| 554 | stmt_cache_finalize_entry(rec->stmt_entry); /* ...and on error, cleanup */ |
| 555 | } |
| 556 | return 0; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /* this is a new stmt (never was in cache before) so create cache object */ |
| 561 | const char *sqlptr = clnt->sql; |
| 562 | if (rec->sql) |
| 563 | sqlptr = rec->sql; |
| 564 | |
| 565 | if (rec->status & CACHE_HAS_HINT) { |
| 566 | sqlptr = rec->cache_hint; |
| 567 | if (!(rec->status & CACHE_FOUND_STR)) { |
| 568 | void *data = NULL; |
| 569 | int data_sz = 0; |
| 570 | query_data_func(clnt, &data, &data_sz, QUERY_HINT_DATA, QUERY_DATA_GET); |
no test coverage detected