619 |
static void |
static void |
620 |
sql_cache_insert(struct sql_connection *conn, SQL_RESULT *res) |
sql_cache_insert(struct sql_connection *conn, SQL_RESULT *res) |
621 |
{ |
{ |
622 |
debug(1,("cache: %d,(%d,%d)",sql_cache_level(conn),conn->head,conn->tail)); |
debug(20, |
623 |
|
("cache: %d,(%d,%d)", |
624 |
|
sql_cache_level(conn),conn->head,conn->tail)); |
625 |
if (sql_cache_level(conn) >= SQL_CACHE_SIZE-1) { |
if (sql_cache_level(conn) >= SQL_CACHE_SIZE-1) { |
626 |
sql_result_destroy(conn->cache[conn->head]); |
sql_result_destroy(conn->cache[conn->head]); |
627 |
conn->head = (conn->head + 1) % SQL_CACHE_SIZE; |
conn->head = (conn->head + 1) % SQL_CACHE_SIZE; |
628 |
debug(1,("head: %d,%d", conn->head,conn->tail)); |
debug(20,("head: %d,%d", conn->head,conn->tail)); |
629 |
} |
} |
630 |
debug(1,("inserting at pos %d", conn->tail)); |
debug(20,("inserting at pos %d", conn->tail)); |
631 |
conn->cache[conn->tail] = res; |
conn->cache[conn->tail] = res; |
632 |
conn->tail = (conn->tail + 1) % SQL_CACHE_SIZE; |
conn->tail = (conn->tail + 1) % SQL_CACHE_SIZE; |
633 |
debug(1,("tail: %d,%d", conn->head,conn->tail)); |
debug(20,("tail: %d,%d", conn->head,conn->tail)); |
634 |
} |
} |
635 |
|
|
636 |
static SQL_RESULT * |
static SQL_RESULT * |
640 |
SQL_RESULT *res; |
SQL_RESULT *res; |
641 |
size_t i; |
size_t i; |
642 |
|
|
643 |
debug(1,("query: %s",query)); |
debug(20,("query: %s",query)); |
644 |
res = emalloc(sizeof(*res)); |
res = emalloc(sizeof(*res)); |
645 |
res->query = estrdup(query); |
res->query = estrdup(query); |
646 |
res->nfields = res->ntuples = 0; |
res->nfields = res->ntuples = 0; |
685 |
{ |
{ |
686 |
size_t i; |
size_t i; |
687 |
|
|
688 |
debug(1,("looking up %s", query)); |
debug(20,("looking up %s", query)); |
689 |
for (i = conn->head; i != conn->tail; |
for (i = conn->head; i != conn->tail; |
690 |
i = (i + 1) % SQL_CACHE_SIZE) { |
i = (i + 1) % SQL_CACHE_SIZE) { |
691 |
if (strcmp(conn->cache[i]->query, query) == 0) { |
if (strcmp(conn->cache[i]->query, query) == 0) { |
692 |
debug(1,("found at %d", i)); |
debug(20,("found at %d", i)); |
693 |
return conn->cache[i]; |
return conn->cache[i]; |
694 |
} |
} |
695 |
} |
} |
696 |
debug(1,("NOT FOUND")); |
debug(20,("NOT FOUND")); |
697 |
return NULL; |
return NULL; |
698 |
} |
} |
699 |
|
|