HarbingerOfFire / bivittatusDB

Operator Based Relational Database Management system for python
https://pypi.org/project/bivittatusDB/
4 stars 1 forks source link

Autocommit Corrupting datafile #8

Closed HarbingerOfFire closed 2 weeks ago

HarbingerOfFire commented 3 weeks ago

When I start using auto commit, I can add two rows to a table, but during the second run, it removes the data from the metadata segment of the database file. I can't figure out why this is happening.

To Reproduce In the example file contained in the src directory, add the line tb1@bdb.ON to turn on auto commit, and then run that. It doesn't error with a normal traceback, but windows says it exits with code -1073740791. You'll also notice that it doesn't run the print table step.

Screenshots If you can read this, you'll see the metadata table here is intact. image Here is the same data after the adding of the second table. That metadata is corrupted: image

ScriptSlayer0 commented 3 weeks ago

Can you provide a video reproducing this issue? It can help to see how it runs on your system and maybe can help to get a fix for this.

HarbingerOfFire commented 3 weeks ago

you should be able to view it here

ScriptSlayer0 commented 3 weeks ago

Only happens when I run auto_commit: Traceback (most recent call last): File "d:\github\bivittatusDB\src\ex_auto_commit.py", line 2, in <module> import BivittatusDB as bdb File "d:\github\bivittatusDB\src\BivittatusDB.py", line 2, in <module> from BDB_tb import * File "d:\github\bivittatusDB\src\BDB_tb.py", line 1, in <module> import datetime, BDB_metadata File "d:\github\bivittatusDB\src\BDB_metadata.py", line 4, in <module> from BDB_io import DBio_lib File "d:\github\bivittatusDB\src\BDB_io.py", line 4, in <module> io_lib = ctypes.CDLL("./lib_bdb.so") ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: Could not find module 'D:\github\bivittatusDB\lib_bdb.so' (or one of its dependencies). Try using the full path with constructor syntax.

HarbingerOfFire commented 3 weeks ago

Are you running from inside the src folder?

Sorry about those typos...

ScriptSlayer0 commented 2 weeks ago

Yes, I was running in the src folder, now the question is why it doesn't work for me now.

HarbingerOfFire commented 2 weeks ago

it looks like the code isn't run from the folder though, since it's looking for D:\github\bivittatusDB\lib_bdb.so when it should be looking for D:\github\bivittatusDB\src\lib_bdb.so

ScriptSlayer0 commented 2 weeks ago

What?, but in my computer appears in this path image

HarbingerOfFire commented 2 weeks ago

yeah, but what directory is your ide located in?

ScriptSlayer0 commented 2 weeks ago

C:\Users\dev\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Visual Studio Code

HarbingerOfFire commented 2 weeks ago

I meant like what folder is it opened to. Like: image

ScriptSlayer0 commented 2 weeks ago

image

HarbingerOfFire commented 2 weeks ago

interesting, right folder, but the file isn't there?

ScriptSlayer0 commented 2 weeks ago

If I take out the lib_bdb.so file it doesn't give error, but if it's inside src it jumps

HarbingerOfFire commented 2 weeks ago

in the bdb_io.py file add the following lines before loading the c-lib.

from pathlib import Path
print(Path("mydir/myfile.txt").absolute())
ScriptSlayer0 commented 2 weeks ago

D:\github\bivittatusDB\mydir\myfile.txt

HarbingerOfFire commented 2 weeks ago

Yeah, the code seems to be running outside of the src directory for you. That is weird

ScriptSlayer0 commented 2 weeks ago

Which python version are you running? Maybe it's the interpreter version of python (to be ruled out)

HarbingerOfFire commented 2 weeks ago

3.12.2 I don't know if this is an issue with a code as much as the ide though

ScriptSlayer0 commented 2 weeks ago

@HarbingerOfFire I have made a test, using the next code:

import os
current_dir = os.path.dirname(os.path.realpath(__file__))
print("This is the current dir:",current_dir)

And the output it's: This is the current dir: D:\github\bivittatusDB\src When this file it's out of src or inside in the same directory the output is the same

HarbingerOfFire commented 2 weeks ago

Yeah, that's telling you the path of the file you're running. Try replacing __file__ with lib_bdb.so and is probably going to give This is the current dir: D:\github\bivittatusDB

HarbingerOfFire commented 2 weeks ago

I'm going to go ahead and close this as I'm making a lot of updates for the file-per-table version which should hopefully fix the initial error. Hopefully when you sync your changes it will solve your errors as well.

ScriptSlayer0 commented 2 weeks ago

@HarbingerOfFire I have a very strange question. In VS in the terminal the output is: This is the current directory: D:\github\bivittatusDB But using CMD running the code the output is: This is the current directory: D:\github\bivittatusDBDB\src Is it a problem with VS or what is going on? CMD: image VS: image

HarbingerOfFire commented 2 weeks ago

Notice the difference in the prompt. CMD has you in the src/ directory but in VS you are in it's parent folder. Just to make sure, this is Visual Studio Code and not Visual Studio \, right?

HarbingerOfFire commented 1 week ago

@ScriptSlayer0 If you are in VSCode, you can use ctrl+k, ctrl+o then you can select the /src directory. Then run the test.py code again

HarbingerOfFire commented 1 week ago

Actually, the last update should fix your problem. Let me know if you still experience the error

ScriptSlayer0 commented 1 week ago

I have improved the code at the beginning I was doing quite a lot of testing to get it right. Code:

import os

def find_path(file_name):
    for root, dirs, files in os.walk('/'):
        if file_name in files:
            return os.path.join(root, file_name)

file_path = find_path('lib_bdb.so')

if file_path:
    print(f"The file 'lib_bdb.so' is located in: {file_path}")
else:
    print("File 'lib_bdb.so' was not found.")

Output: The file 'lib_bdb.so' is located in: /github\BivitattusDatabase\lib_bdb.so

ScriptSlayer0 commented 1 week ago

Actually, the last update should fix your problem. Let me know if you still experience the error

I already working: ex_autocommit.py, ex_use_table.py

Using ex_update.py (output): Couldn't make directory: File exists

HarbingerOfFire commented 1 week ago

Noted, that should be from the fact that you haven't deleted the old database when changing example files and most of the example files initialize the same database. Since you can't reinitialize the same database, this throws up an error. I'll add a fix later today for a drop clause that will be noted for best practices.

HarbingerOfFire commented 1 week ago

Fix made. Let me know if error continues

ScriptSlayer0 commented 1 week ago

When I generate a new DB with autocommit, then I executing the ex_use_table.py it throws me: No data to show. So strange...

HarbingerOfFire commented 1 week ago

That means the table is empty. add a few rows and then print it.

ScriptSlayer0 commented 1 week ago

I think ex_add_rows.py it's bugged, after adding rows to the table throws when you are using the same table like a blank table.

HarbingerOfFire commented 1 week ago

ex_add_rows.py doesn't commit the changes in any way. They are just staged in memory. Either turn on autocommit (ex_auto_commit.py) or save the change (ex_save.py) and retry.

HarbingerOfFire commented 1 week ago

I tested the example files and they all work as expected. I pushed this to release as version 4.1.0. I'm going to go ahead and lock this issue. If you find anything else you can always open a new issue.