Skip to content

Commit

Permalink
No NULL strings in SQL query for Gallery.
Browse files Browse the repository at this point in the history
String fields filename, name, path (comment) and extension in database table gallery_files cannot be NULL.
Scanning the storage group for pictures can result in a database error like this:
2022-10-11 21:56:11.606192 E  Original query failed, but resend with empty strings in place of NULL strings worked.
DB Error (MSqlQuery):
Query was:
INSERT INTO gallery_files (file_id, filename, name, dir_id, type, modtime, size, extension, date, hidden, orientation, angle, path, zoom) VALUES (0, ?, ?,      ?, ?,   ?, ?,     ?, ?,   ?, ?, ?,    ?,   ?);
Bindings were:
:COMMENT="", :COVER=0, :DATE=1665518171, :EXTENSION=NULL, :FILEPATH="", :FS=0,
:HIDDEN=false, :MODTIME=1665518171, :NAME="", :ORIENT=0, :PARENT=0, :SIZE=0,
:TYPE=1
Driver error was [2/1048]:
QMYSQL3: Unable to execute statement
Database error was:
Column 'extension' cannot be null
This is fixed for all four string fields by using the bindValueNoNull function to bind the value.
  • Loading branch information
kmdewaal committed Oct 11, 2022
1 parent 84a9131 commit 26804b7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mythtv/libs/libmythmetadata/imagemanager.cpp
Expand Up @@ -817,17 +817,17 @@ int ImageDb<FS>::InsertDbImage(ImageItemK &im, bool checkForDuplicate) const
":SIZE, :EXTENSION, :DATE, :HIDDEN, :ORIENT, "
":COVER, :COMMENT, :FS);").arg(m_table, kDBColumns));

query.bindValue(":FILEPATH", im.m_filePath);
query.bindValue(":NAME", FS::BaseNameOf(im.m_filePath));
query.bindValueNoNull(":FILEPATH", im.m_filePath);
query.bindValueNoNull(":NAME", FS::BaseNameOf(im.m_filePath));
query.bindValue(":FS", im.m_device);
query.bindValue(":PARENT", FS::DbId(im.m_parentId));
query.bindValue(":TYPE", im.m_type);
query.bindValue(":MODTIME", static_cast<qint64>(im.m_modTime.count()));
query.bindValue(":SIZE", im.m_size);
query.bindValue(":EXTENSION", im.m_extension);
query.bindValueNoNull(":EXTENSION", im.m_extension);
query.bindValue(":DATE", static_cast<qint64>(im.m_date.count()));
query.bindValue(":ORIENT", im.m_orientation);
query.bindValueNoNull(":COMMENT", im.m_comment);
query.bindValueNoNull(":COMMENT", im.m_comment);
query.bindValue(":HIDDEN", im.m_isHidden);
query.bindValue(":COVER", FS::DbId(im.m_userThumbnail));

Expand Down

0 comments on commit 26804b7

Please sign in to comment.