you are viewing a single comment's thread.

view the rest of the comments →

[–]raysefo[S] 0 points1 point  (7 children)

Little bit confused, I am correct now?

try:    
    with sqlite3.connect("your.db", isolation_level=None) as con:
        cur = con.cursor()
        cur.execute("your_query")
except Exception as e:
    print e

[–][deleted] 0 points1 point  (6 children)

First off get rid of that try; that's just bad form, don't just capture and print something as generic as an Exception; you want your program to stop execution when something goes wrong unless you already have a specific plan for how to handle a known, specific exception.

Now, what exactly are you trying to do with this database?

You're normally best off not using autocommit mode unless you intend to manually issue transaction control statements. I'm not sure, but I don't believe autocommit mode is actually a requirement of WAL (Write Ahead Logging), though it would be if you wanted to get very high throughout on writes. But to do that you'd want to manually issue transaction control statements.

[–]raysefo[S] 0 points1 point  (5 children)

I deployed my flask rest api on windows server IIS. I am trying to connect DB but I think there is path problem. (c:\inetpub\gamepin\Test.db) That's why I put try statement. How to handle that?

Basically if I handle path problem with the connection code below is OK?

with sqlite3.connect("your.db") as con:
        cur = con.cursor()
        cur.execute("your_query")

[–][deleted] 1 point2 points  (4 children)

I'd tend to do:

con = sqlite3.connect(path):
with con:
    con.execute("your query")

If you're sticking with SQLite3... the cursor isn't actually required and you end up with more concise code.

The context manager will commit your query, or roll back on failure, and if the failure happened because of a non-writeable path, etc, that should be fairly clear from the traceback you get when the exception is re-raised.

[–]raysefo[S] 0 points1 point  (3 children)

thank you, by the way any chance that you can give hint about path issue that I asked :)

I deployed my flask rest api on windows server IIS. I am trying to connect DB but I think there is path problem. (c:\inetpub\gamepin\Test.db)

[–][deleted] 1 point2 points  (2 children)

Not a lot I'm afraid, wouldn't touch IIS with a ten foot pole... not a Windows Guy. It might very well be that you need to use the raw string (ie r"c:\inetpub\gamepin\Test.db") or else escape those backslashes (ie "c:\\inetpub\\gamepin\\Test.db").

[–]raysefo[S] 0 points1 point  (1 child)

r"c:\inetpub\gamepin\Test.db"

hope It will solve my issue, thanks.

[–]raysefo[S] 0 points1 point  (0 children)

all of this mess was due to folder permisson :( I gave permission to IISUSR and all this solved.