int flesh_depth = 0;
int offset = 0;
int limit = 0;
+ int can_get_cursor = 1;
+ int do_cursor = 0;
int cursor_page_size = 50;
- if (*methodtype != 'r') cursor_name = random_cursor_name(); /* Use a cursor for all but .retrieve */
+ if (cursor_name) can_get_cursor = 0; // There is already a cursor, and it is not local
+ if (*methodtype != 'r' && can_get_cursor) cursor_name = random_cursor_name(); /* Use a cursor for all but .retrieve */
+
+ if (cursor_name && can_get_cursor) do_cursor = 1;
char* sql = buildSELECT( where_hash, query_hash, class_meta, ctx );
if( !sql ) {
}
- if (cursor_name) {
+ if (do_cursor) {
const jsonObject* limit_o = jsonObjectGetKeyConst( query_hash, "limit" );
if( limit_o ) {
limit = (int) jsonObjectGetNumber( limit_o );
rs_size = (int *) safe_malloc( sizeof(int) ); // will be freed by sessionDataFree()
unsigned long long result_count = cursor_page_size;
- if (!cursor_name) {
+ if (!do_cursor) {
result_count = dbi_result_get_numrows( result );
}
*rs_size = (int) result_count * (flesh_depth + 1); // yes, we could lose some bits, but come on
osrfHashSet( (osrfHash *) ctx->session->userData, rs_size, "rs_size_req_%d", ctx->request );
}
- if (cursor_name) {
+ if (do_cursor) {
dbi_result_free( result ); // toss the declare result
result = dbi_conn_queryf( dbhandle, "FETCH %d FROM \"%s\";", cursor_page_size, cursor_name );
} else {
if( !enforce_pcrud || !need_to_verify ||
verifyObjectPCRUD( ctx, class_meta, row_obj, 0 /* means check user data for rs_size */ )) {
- if (cursor_name) {
+ if (do_cursor) {
if (offset > -1 && offset) {
offset--;
} else {
}
}
}
- if (cursor_name && !cursor_page_remaining) { // fetch next page
+ if (do_cursor && !cursor_page_remaining) { // fetch next page
cursor_page_remaining = cursor_page_size;
dbi_result_free( result );
result = dbi_conn_queryf( dbhandle, "FETCH %d FROM \"%s\";", cursor_page_size, cursor_name );
}
}
} while(
- (!cursor_name && dbi_result_next_row(result)) || (
- cursor_name && limit && ( // limit is -1 (none) or not yet decremented to 0
+ (!do_cursor && dbi_result_next_row(result)) || (
+ do_cursor && limit && ( // limit is -1 (none) or not yet decremented to 0
(cursor_page_remaining == cursor_page_size && dbi_result_first_row(result)) || // on a new page, and there's a row
(cursor_page_remaining != cursor_page_size && dbi_result_next_row(result)) // on the same page, and there's a row
)
/* clean up the query */
dbi_result_free( result );
- if (cursor_name) {
+ if (do_cursor) {
result = dbi_conn_queryf( dbhandle, "CLOSE \"%s\";", cursor_name );
dbi_result_free( result );
free_cursor_name(); // release the cursor name now so recursive fleshing calls can make their own without leaking