HarbingerOfFire / bivittatusDB

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

Fix: ex_auto_commit data viewing #6

Closed ScriptSlayer0 closed 2 months ago

ScriptSlayer0 commented 2 months ago

Password for test: +--+-----+ |id|name | +--+-----+ |1 |Alice| |2 |Bob | |3 |Cindy| +--+-----+

Now works

HarbingerOfFire commented 2 months ago

Does ex_use_table.py work now too?

ScriptSlayer0 commented 2 months ago

Doesn't work yet, I'm working on it.

ScriptSlayer0 commented 2 months ago

I'm experimenting with these next errors: binascii.Error: Non-hexadecimal digit found

binascii.Error: Odd-length string Error loading table table1 from database test: 'str' object has no attribute 'pop' (right now) (Only happens when I run ex_use_table.py)

HarbingerOfFire commented 2 months ago

what line is throwing the error?

ScriptSlayer0 commented 2 months ago

Line 21 BivittatusDB.py with traceback.format_exc():

Error loading table table1 from database test: 'str' object has no attribute 'pop'
Traceback (most recent call last):
  File "d:\github\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 20, in load_table
    return table(self.database_name, table_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 13, in __init__
    self.__read__()
  File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 46, in __read__
    self.columns = self.data.pop(0)
                   ^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'pop'
HarbingerOfFire commented 2 months ago

print the value of self.data before line 46

ScriptSlayer0 commented 2 months ago

It thows me None

HarbingerOfFire commented 2 months ago

you do have a pydb file in the directory your running it from, right?

ScriptSlayer0 commented 2 months ago

Yes

HarbingerOfFire commented 2 months ago

Try regenerating the file using ex_auto_commit.py, and see if the error persists

ScriptSlayer0 commented 2 months ago

With this change works ex_use_table.py not ex_auto_commit.py:

def __read__(self):
        '''Read data from a file'''
        try:
            reader = io.HDF5Handler(self.database)
        except Exception as e:
            print(f"Error reading the database: {e}")
            return None

        try:
            self.data = reader.read_table(self.table_name)
            print(f"Value of self.data before processing: {self.data}")  # Added print statement

            # Assuming the data is returned as a JSON string, decode it
            self.data = json.loads(self.data)
            print(f"Value of self.data after JSON decoding: {self.data}")
        except Exception as e:
            print(f"Error reading the table {self.table_name}: {e}")
            return None

        # Check if self.data is a list
        if isinstance(self.data, list):
            self.columns = self.data.pop(0)
        else:
            print(f"Unexpected data format: {type(self.data)}")
            return None

        return self.data

And with this one only works auto_commit.py:

def __read__(self):
        '''Read data from a file'''
        try:
            reader = io.HDF5Handler(self.database)
        except Exception as e:
            print(f"Error reading the database:  {e}")
            return None

        try:
            self.data = reader.read_table(self.table_name)
        except Exception as e:
            print(f"Error reading the table {self.table_name}: {e}")
            return None

        self.columns = self.data.pop(0)

        return self.data`

Why?. I don't really know for the moment. (All changes are made in DBD_tb.py)

HarbingerOfFire commented 2 months ago

use_table.py shouldn't work with that code since the reader.read_table() should return an already decoded form of the data. In auto_commit.py that same code errors because it's trying to decode an already decoded object, which causes it to exit. It'll probably work for both if you remove the return None line in the first code, but I think we still need to figure out why use_table.py isn't properly being decoded during by the reader.

HarbingerOfFire commented 2 months ago

also, can I ask what system you are running on?

ScriptSlayer0 commented 2 months ago

also, can I ask what system you are running on?

I'm running windows 11.

HarbingerOfFire commented 2 months ago

https://github.com/HarbingerOfFire/BivitattusDatabase/issues/1

HarbingerOfFire commented 2 months ago

Ok, I'm going to go ahead and merge it, but not going to make a stable release then, and I'll work on getting everything updated with the new database system this week.