Have a requirement of storing/retrieving bytes as a blob in SQLite3;
The column definition in as follows:"bytes_as_blob " BLOB,
Byte data is stored in the table using the following construct sqlite3.Binary(some_data) and the data when visualized via DB Browser is as below:
<memory at 0x000002157DA24F40>
However, the issue is me being unable to convert the blob stored in SQLite back to bytes.
The select statement to retrieve data is SELECT uid, bytes_as_blob from a_table LIMIT 10 and results from SQLite3 are retuned as a DataFrame. The dtypes for the dataframe columns are dobject ;
df = pd.read_sql_query(sql_statement, conn)
print(f"type(df.loc[1].iat[0]) = {type(df.loc[1].iat[0]))}") # uid
print(f"type(df.loc[1].iat[1]) = {type(df.loc[1].iat[1]))}") # bytes_as_blob
The type of the Python objects in the DF are of type <class 'str'>
Is there something that that is needed when converting a blob back to bytes - could not find anything in here https://pandas.pydata.org/docs/user_guide/io.html#io-sql
Tried BytesIO(df_cell_value).read() which which did not work as expected.
df_cell_value? What is the type of object? There is no type "blob" in Python.dobjectobjectjust means it can hold any type of python object. I am asking you what type of python object are you actually working with.