I have a code that reads metadata and it puts the information into a dataframe. That part works, I then use the to_sql
function and I get this error:
sqlalchemy.exc.ProgrammingError: (pyodbc.ProgrammingError) ('Unknown object type: IFDRational', 'HY000')
. My output shows everything that is in quotes besides what is an integer. Knowing SQL everything needs to be in the single quotes so I think that's that's my issue.
Here is my script:
info_list = []
info_list2 = []
for file in os.listdir(rootdir):
try:
# read the image data using PIL
image = Image.open(os.path.join(rootdir, file))
# extract other basic metadata
info_list.append([
os.path.basename(image.filename),
os.path.getsize(image.filename),
image.info['dpi'][0],
image.height,
image.width,
image.format,
image.mode,
getattr(image, "n_frames", 1)
])
Df1 = pd.DataFrame(info_list, columns=["FileName", "FileSize","DPI", "Height", "Width", "Format", "Mode", "Frames"])
except:
image = Image.open(os.path.join(rootdir, file))
# extract other basic metadata
info_list.append([
os.path.basename(image.filename),
os.path.getsize(image.filename),
pathlib.Path(image.filename).suffix,
image.height,
image.width,
image.format,
image.mode,
getattr(image, "n_frames", 1)
])
Df2 = pd.DataFrame(info_list2, columns=["FileName","Format", "Mode"])
Df1.to_sql("SuspensiaImageDetails", con = engine, if_exists = 'append', dtype= NVARCHAR('50'))
Df2.to_sql("SuspensiaImageDetails", con = engine, if_exists = 'append', dtype= NVARCHAR('50'))
I think I have to convert everything to a string? or is there supposed to do something else to pust this into the SQL table.