Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.OperationalError: unable to open database file #11

Closed
UtopianElectronics opened this issue Aug 11, 2022 · 36 comments
Closed

sqlite3.OperationalError: unable to open database file #11

UtopianElectronics opened this issue Aug 11, 2022 · 36 comments

Comments

@UtopianElectronics
Copy link

UtopianElectronics commented Aug 11, 2022

I'm getting the following error after trying to execute a dry run:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 27, in __init__
    self.conn = sqlite3.connect(file)
sqlite3.OperationalError: unable to open database file

How to fix it?

Additional info: Running on Windows 10

@Philipp91
Copy link
Owner

Can you log the value of file and check if it even exists?

@UtopianElectronics
Copy link
Author

Can you log the value of file and check if it even exists?

Sure, but unfortunately I'm not familiar with databases, yet. Could you please tell me how to do it?

@Philipp91
Copy link
Owner

No need for database knowledge, it's just a Python thing. Edit the file C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py, where around line 27 it does self.conn = sqlite3.connect(file). Immediately before that, add a line print(file), rerun the program and check the extra line that appears in the log output. If somehow you don't see any output, play around with print("Hello") or so.

@UtopianElectronics
Copy link
Author

UtopianElectronics commented Aug 12, 2022

Here's the output after adding the print(file) line:

'D:\digiKam_library\digikam4.db'
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 28, in __init__
    self.conn = sqlite3.connect(file)
sqlite3.OperationalError: unable to open database file

@UtopianElectronics
Copy link
Author

Any idea what's causing this error and how to fix it?

@Philipp91
Copy link
Owner

Philipp91 commented Aug 13, 2022

Does the file D:\digiKam_library\digikam4.db exist? And is it a valid SQLite file, i.e. can you open it with SQLite Browser?

And do you have write access, i.e. if you put sth like this near the print(file) statement, will it actually copy the file?

import shutil
shutil.copyfile('D:\\digiKam_library\\digikam4.db', 'D:\\digiKam_library\\digikam4.db.copy')

@UtopianElectronics
Copy link
Author

Does the file D:\digiKam_library\digikam4.db exist?

Yes, and it's about 18 MB in size.

And is it a valid SQLite file, i.e. can you open it with SQLite Browser?

Yes, I can open it with SQLite Browser.

And do you have write access, i.e. if you put sth like this near the print(file) statement, will it actually copy the file?

Also yes, it creates digikam4.db.copy file with the exact same size.

@Philipp91
Copy link
Owner

Is digiKam closed when you try this? (Perhaps the file is "locked" when opened in another application.)

@Philipp91
Copy link
Owner

For these versions I'm getting Python 3.10.4, sqlite3 2.6.0 and sqlite_version 3.37.2. Are those significantly different for you?

@Philipp91
Copy link
Owner

If you open a Python shell, can you use a simple tutorial to create a new database file with some dummy content? Just trying to see if the sqlite3 Python library works at all on your machine, or perhaps one of its dependencies is missing.

@Philipp91
Copy link
Owner

Thanks to this PR, if you upgrade your Python installation to the 3.11 release candidate, you can then wrap the sqlite3.connect(... line into a try-catch block and print additional information about the error, specifically the SQLite error code like they do here.

@UtopianElectronics
Copy link
Author

Is digiKam closed when you try this?

Yes.

Are those significantly different for you?

Only the Python version:
Python 3.9.13
sqlite3 2.6.0
sqlite_version 3.37.2

If you open a Python shell, can you use a simple tutorial to create a new database file with some dummy content?

Yes. I followed the tutorial and had no issues.

@UtopianElectronics
Copy link
Author

Thanks to this PR, if you upgrade your Python installation to the 3.11 release candidate, you can then wrap the sqlite3.connect(... line into a try-catch block and print additional information about the error, specifically the SQLite error code like they do here.

Sounds interesting, but I'm not sure what to do. Should I add the highlighted lines to digikam_db.py, or run the whole script for digiKam's database?

@Philipp91
Copy link
Owner

Philipp91 commented Aug 13, 2022

The former. It should result in sth like:

    def __init__(self, file: Path):
        self.file = file
        logging.debug("file=%s" % file)
        try:
            self.conn = sqlite3.connect(file)
        except sqlite3.Error as e:
            err_msg = str(e)
            err_code = e.sqlite_errorcode
            err_name = e.sqlite_errorname
            print(f"{err_name} ({err_code}): {err_msg}")
            raise e
        if os.name == 'nt':  # Windows
...

@UtopianElectronics
Copy link
Author

Okay, here's what I get after making the aforementioned changes:

./python main.py --dry_run --photos_dir='D:\gallery' --digikam_db='D:\digiKam_library\digikam4.db' --contacts='%LocalAppData%\Google\Picasa2\contacts\contacts.xml'
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 29, in __init__
    self.conn = sqlite3.connect(file)
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 32, in __init__
    error_code = e.sqlite_errorcode
AttributeError: 'OperationalError' object has no attribute 'sqlite_errorcode'

@Philipp91
Copy link
Owner

if you upgrade your Python installation to the 3.11 release candidate

Did you do this part?

@UtopianElectronics
Copy link
Author

Oops, I forgot that. Going to upgrade it and try again...

@UtopianElectronics
Copy link
Author

UtopianElectronics commented Aug 13, 2022

Which Python version should I upgrade to? I downloaded and installed Python 3.11.0rc1. Now I'm getting the following error:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 12, in <module>
    import digikam_db
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 3, in <module>
    import psutil
ModuleNotFoundError: No module named 'psutil'

And I'm having problems with pip install --upgrade psutil or just pip install psutil:

Collecting psutil
  Using cached psutil-5.9.1.tar.gz (479 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: psutil
  Building wheel for psutil (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for psutil (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [47 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-cpython-311
      creating build\lib.win-amd64-cpython-311\psutil
      copying psutil\_common.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_compat.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_psaix.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_psbsd.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_pslinux.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_psosx.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_psposix.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_pssunos.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\_pswindows.py -> build\lib.win-amd64-cpython-311\psutil
      copying psutil\__init__.py -> build\lib.win-amd64-cpython-311\psutil
      creating build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\foo.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\runner.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_aix.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_bsd.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_connections.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_contracts.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_linux.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_memleaks.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_misc.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_osx.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_posix.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_process.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_sunos.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_system.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_testutils.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_unicode.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\test_windows.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\__init__.py -> build\lib.win-amd64-cpython-311\psutil\tests
      copying psutil\tests\__main__.py -> build\lib.win-amd64-cpython-311\psutil\tests
      running build_ext
      building 'psutil._psutil_windows' extension
      creating build\temp.win-amd64-cpython-311
      creating build\temp.win-amd64-cpython-311\Release
      creating build\temp.win-amd64-cpython-311\Release\psutil
      creating build\temp.win-amd64-cpython-311\Release\psutil\arch
      creating build\temp.win-amd64-cpython-311\Release\psutil\arch\windows
      "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -DPSUTIL_SIZEOF_PID_T=4 -DPSUTIL_VERSION=591 -DPSUTIL_WINDOWS=1 -D_WIN32_WINNT=0x01000 -D_AVAIL_WINVER_=0x01000 -D_CRT_SECURE_NO_WARNINGS -DPSAPI_VERSION=1 -IC:\Users\USERNAME\AppData\Local\Programs\Python\Python311\include -IC:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tcpsutil/_psutil_common.c /Fobuild\temp.win-amd64-cpython-311\Release\psutil/_psutil_common.obj
      _psutil_common.c
      c:\users\USERNAME\appdata\local\programs\python\python311\include\pyconfig.h(207): fatal error C1083: Cannot open include file: 'basetsd.h': No such file or directory
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for psutil
Failed to build psutil
ERROR: Could not build wheels for psutil, which is required to install pyproject.toml-based projects

@Philipp91
Copy link
Owner

Philipp91 commented Aug 13, 2022

What about pip install --only-binary :all: psutil? Then it uses the pre-compiled wheels. Or perhaps those don't exist yet for 3.11, in which case it would output an error.

EDIT: Yes it seems like those wheels don't exist yet: giampaolo/psutil#2089 Unfortunately this means you'd first have to install Visual Studio. The instructions seem a little outdated. I'd follow these instructions (read the top portion of that page too) and if it keeps wanting to use C:\\Program Files (x86)\\Microsoft Visual Studio 14.0 for some reason, then this.

@UtopianElectronics
Copy link
Author

Okay, so I uninstalled Python and then installed Build Tools for Visual Studio 2019, and after that I installed Python 3.11.0rc1. pip install --only-binary :all: psutil gives the following error:

ERROR: Could not find a version that satisfies the requirement psutil (from versions: none)
ERROR: No matching distribution found for psutil

But ironically, I was able to install psutil-5.9.1 using pip install psutil.
However, I still get this error message:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 29, in __init__
    self.conn = sqlite3.connect(file)
                ^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 33, in __init__
    error_name = e.sqlite_name
                 ^^^^^^^^^^^^^
AttributeError: 'OperationalError' object has no attribute 'sqlite_name'. Did you mean: 'sqlite_errorname'?

@Philipp91
Copy link
Owner

Awesome!

object has no attribute 'sqlite_name'. Did you mean: 'sqlite_errorname'?

Yes, we do mean sqlite_errorname, please just update it in the code snippet you inserted. Apparently I copy-pasted some broken code, updated my comment above too.

@UtopianElectronics
Copy link
Author

Updated the code and still doesn't work:

Error SQLITE_CANTOPEN [Errno 14]: unable to open database file
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 35, in __init__
    raise e
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 29, in __init__
    self.conn = sqlite3.connect(file)
                ^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

Really makes me wonder why it can't open it.

@Philipp91
Copy link
Owner

Philipp91 commented Aug 13, 2022

still doesn't work

Well, the above steps were intended to get a more detailed error message, namely the SQLITE_CANTOPEN [Errno 14]: unable to open database file part of the new output. Hopefully this will help find the root cause.

Which environment do you run this in? Windows command prompt? Windows Terminal app? PowerShell? MinGW? WSL? I suspect that shutil does something smarter than the C++ code that gets linked into the sqlite3 Python package, which is why the file copying above worked but the database loading does not.

@Philipp91
Copy link
Owner

I'm assuming you're passing --digikam_db='D:\digiKam_library\digikam4.db' as an argument.

Can you change the aforementioned connect() code line to one of these variants (try one at a time):

self.conn = sqlite3.connect(f'{file}')  # This one should throw the same error.
self.conn = sqlite3.connect(f'file:{file}', uri=True)  # This one also.
self.conn = sqlite3.connect(f'file:{file}?mode=ro', uri=True)  # This loads in read-only mode.
self.conn = sqlite3.connect(f'file:{file}?mode=rw', uri=True)  # This loads in read-write (but no-create) mode.

@Philipp91
Copy link
Owner

Let's also do another sanity check on the value of file. After the shutil copying above worked, I would expect this to work too, if inserted in the place where the sqlite3.connect() currently happens (so that the file variable is available):

import shutil
shutil.copyfile(f'{file}', f'{file}.copy2')

It should create D:\digiKam_library\digikam4.db.copy2.

@UtopianElectronics
Copy link
Author

I'm running it in Windows Terminal, which gives the same output as CMD.
I tried changing the address formats (double quotation marks instead of single ones, and double backward slashes) and noticed that the error message changes:

python main.py --dry_run --photos_dir="D:\\gallery" --digikam_db="D:\\digiKam_library\\digikam4.db" --contacts="%LocalAppData%\\Google\\Picasa2\\contacts\\contacts.xml"
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 40, in __init__
    _, serial, _, _, _ = win32api.GetVolumeInformation(sdiskpart.mountpoint)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.error: (21, 'GetVolumeInformation', 'The device is not ready.')

Which is the same error if I run the command with single quotation marks and backward slashes in Powershell:

PS C:\Users\USERNAME\Downloads\picasa2digikam-main> python main.py --dry_run --photos_dir='D:\gallery' --digikam_db='D:\digiKam_library\digikam4.db' --contacts='%LocalAppData%\Google\Picasa2\contacts\contacts.xml'
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 40, in __init__
    _, serial, _, _, _ = win32api.GetVolumeInformation(sdiskpart.mountpoint)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.error: (21, 'GetVolumeInformation', 'The device is not ready.')

My digiKam database file and photos are on an external HDD. Is this a problem?

Can you change the aforementioned connect() code line to one of these variants (try one at a time)

I tried all of them and nothing changed.

Let's also do another sanity check on the value of file.

If this is what you mean:

    def __init__(self, file: Path):
        self.file = file
        logging.debug("file=%s" % file)
        try:
            print(file)
            import shutil
            shutil.copyfile(f'{file}', f'{file}.copy2')
            self.conn = sqlite3.connect(file)
        except sqlite3.Error as e:
            msg = str(e)
            error_code = e.sqlite_errorcode
            error_name = e.sqlite_errorname
            print(f"Error {error_name} [Errno {error_code}]: {msg}")
            raise e
        if os.name == 'nt':  # Windows

it gives the following output and error message:

'D:\digiKam_library\digikam4.db'
Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 31, in __init__
    shutil.copyfile(f'{file}', f'{file}.copy2')
  File "C:\Users\USERNAME\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 256, in copyfile
    with open(src, 'rb') as fsrc:
         ^^^^^^^^^^^^^^^
OSError: [Errno 22] Invalid argument: "'D:\\digiKam_library\\digikam4.db'"

And no D:\digiKam_library\digikam4.db.copy2.

@Philipp91
Copy link
Owner

digikam_db.py", line 40

That error message is much "better" than the one you previously got from digikam_db.py", line 29. As you can tell from those line numbers, the program has advanced further. So the SQLite opening succeeded there.

double quotation marks instead of single ones, and double backward slashes

Then I suspect that previously a broken path was fed to the program, e.g. sth like D:⍰igiKam_library⍰igikam4.db because \d was interpreted as an escape sequence rather than a backslash followed by a d.

Does this mean that we should update the example command in the readme because apparently it doesn't work right with cmd / Windows Terminal?

@Philipp91
Copy link
Owner

Invalid argument: "'D:\digiKam_library\digikam4.db'"

Nevermind that, I overlooked that file is of type Path, so my code wouldn't work like this. Anyway, not worth pursuing further because it works properly with the double backslashes as you described.

@Philipp91
Copy link
Owner

Philipp91 commented Aug 13, 2022

pywintypes.error: (21, 'GetVolumeInformation', 'The device is not ready.')

My digiKam database file and photos are on an external HDD. Is this a problem?

Good question. Is the HDD connected at this time?
This thread is already too long. Please open a new bug with that new error message as the first post, and we can finish this one here up with a potential update of the readme file.

@UtopianElectronics
Copy link
Author

Does this mean that we should update the example command in the readme because apparently it doesn't work right with cmd / Windows Terminal?

Not sure. Maybe it's better to implement it in the code that would automatically do this double backslashes and double quotations if being run on Windows CMD/Terminal.

Is the HDD connected at this time?

Yes. I always make sure about that.

This thread is already too long. Please open a new bug with that new error message as the first post, and we can finish this one here up with a potential update of the readme file.

Okay, moving on. Should I close this thread?

@Philipp91
Copy link
Owner

Not sure. Maybe it's better to implement it in the code that would automatically do this double backslashes and double quotations if being run on Windows CMD/Terminal.

That's not possible. The terminal (or rather the shell) is the program that interprets the user's input and transforms it to the string that is sent to the Python program. At this point, the broken characters like would already have been inserted and it's near-impossible for the Python program to undo this.

@Philipp91
Copy link
Owner

Does everything work if you simply use forward slashes instead of back slashes? (Only \ is used as an escape character, so this might be the simplest solution.)

Which of the following outputs the correct path (with a single \) in your terminal:

echo 'C:\test'
echo 'C:\\test'
echo "C:\test"
echo "C:\\test"

@Philipp91 Philipp91 reopened this Aug 14, 2022
Philipp91 added a commit that referenced this issue Aug 14, 2022
So that the user can more easily spot typos and shell escaping mistakes (see #11).
@Philipp91
Copy link
Owner

You could also try this patch with your original attempt (with the single back slash) to see if it results in a more useful error message this time. (I'm hoping that future users of this script won't have to spend this much time and effort just to find out about backslash escaping.)

@UtopianElectronics
Copy link
Author

Does everything work if you simply use forward slashes instead of back slashes?

You mean something like 'C:/test'? No. The sqlite3.OperationalError: unable to open database file error gets displayed again.

Which of the following outputs the correct path (with a single '') in your terminal

All of them show the exact thing in front of echo.

@UtopianElectronics
Copy link
Author

That's not possible.

Then I think something like how programs like FFmpeg or many others simply have switches like -i which are followed by normal directory paths would be great.

(with the single back slash)

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 28, in __init__
    self.conn = sqlite3.connect(file)
                ^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: unable to open database file

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 30, in __init__
    raise RuntimeError('Failed to open SQLite database from %s.' % file) from err
RuntimeError: Failed to open SQLite database from 'D:\digiKam_library\digikam4.db'.

With paths like "D:\\digiKam_library\\digikam4.db", it shows this error:

Traceback (most recent call last):
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 65, in <module>
    main()
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\main.py", line 50, in main
    db = digikam_db.DigikamDb(args.digikam_db)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\USERNAME\Downloads\picasa2digikam-main\digikam_db.py", line 36, in __init__
    _, serial, _, _, _ = win32api.GetVolumeInformation(sdiskpart.mountpoint)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pywintypes.error: (21, 'GetVolumeInformation', 'The device is not ready.')

@Philipp91
Copy link
Owner

Tried this on my own Windows now, after it installed years worth of updates ...

Turns out that single quotes aren't special to cmd at all, so it just passes them through and thus they become part of the path. But a path starting with 'C:\... is obviously invalid. I've updated the example command in the readme to hopefully work better with Windows cmd.

Double quotes work, but the double slash (i.e. a supposedly escaped slash) isn't correct then, because ^ is the escape character for cmd, and not \. So simply writing the path in double quotes is correct and should work even for paths that contain spaces or variables like %LocalAppData%.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants