question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cache select query

See original GitHub issue

Hello guys. I used a simple code to print every n seconds result from db:

with pyodbc.connect(**odbcconnection) as cnxn:
    cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
    cnxn.setencoding(encoding='utf-8')
    while True:
        cursor = cnxn.cursor()
        time.sleep(2)
        cursor.execute("SELECT * FROM table GROUP by `name` DESC LIMIT 100")
        rows = cursor.fetchall()
        for row in rows:
            print(row)

All ok, but if i change some information on db its nothing change when print show output Only if i restarted script i see a changed iformation

Whats i am doing wrong?! Thanks.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
gordthompsoncommented, Aug 21, 2018

I was able to reproduce your issue under MySQL. You can ensure that you get the latest results by adding

cnxn.rollback()

at the end of your while True: loop.

1reaction
keitherskinecommented, Aug 21, 2018

Without an ORDER BY clause on your SQL, the results from the query are indeterminate, particularly so with a LIMIT on it. Put an ORDER BY clause on the SQL query and try again.

(also, minor point, but the line cursor = cnxn.cursor() does not need to be in the loop, it could be placed before the while statement)

Read more comments on GitHub >

github_iconTop Results From Across the Web

8.10.3.2 Query Cache SELECT Options
SQL_CACHE. The query result is cached if it is cacheable and the value of the query_cache_type system variable is ON or DEMAND ....
Read more >
CACHE SELECT | Databricks on AWS
Caches the data accessed by the specified simple SELECT query in the disk cache. You can choose a subset of columns to be...
Read more >
Query Cache - MariaDB Knowledge Base
The query cache stores results of SELECT queries so that if the identical query is received in future, the results can be quickly...
Read more >
Cached Queries | Caché SQL Optimization Guide
A cached query is created when certain SQL statements are prepared using ... SELECT: a SELECT cached query is shown in the Catalog...
Read more >
What is query caching? How do I cache my query?
Cached Queries are a way for you to build applications with charts and tables that load instantly. A common use case for caching...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found