New version of sqlite3 AddOn doesn't support NULL any more

조회 수: 9 (최근 30일)
Sebastian
Sebastian 2023년 4월 20일
댓글: Rik 2023년 4월 24일
sqlite3_new is the new version 3.0.0. In older versions the addon can handle NULL values in a table
>> a = sqlite3_new(f, 'SELECT CalibrationTable FROM CyclicValuesTableNames');
Error using sqlite3_new
unsupported column type
>> a = sqlite3(f, 'SELECT CalibrationTable FROM CyclicValuesTableNames');
>> a
a =
struct with fields:
CalibrationTable: []
>>
  댓글 수: 1
Rik
Rik 2023년 4월 20일
I will have a look at this as soon as I'm able to.
Note that a part of this change in version 3 is that I use a completely different source. This one I am able to compile myself, so I can support a much wider range of releases and operating systems with the exact same syntax. If this requires a change in the source code, you might need to provide a suggestion. I am not proficient enough in C to really make meaningful changes.

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2023년 4월 21일
First the reproduction steps in a MWE:
% https://www.mathworks.com/matlabcentral/fileexchange/68298-sqlite3
db=[tempname '.db'];
sqlite3(db,'CREATE TABLE test (some_real REAL);')
sqlite3(db,'INSERT INTO test (some_real) VALUES (2)') % This does not make a difference.
sqlite3(db,'INSERT INTO test (some_real) VALUES (NULL)')
data = sqlite3(db,'SELECT * FROM test;');
The problem is with the C function below. The v.3.0.0 version of this function also has a mexErrMsgIdAndTxt in there, which prevents releasing the database file. The updated version fixes this by throwing an error later.
mxArray *get_column(sqlite3_stmt *stmt, int index)
{
int type = sqlite3_column_type(stmt, index);
if (type == SQLITE_TEXT) {
const char *text = sqlite3_column_text(stmt, index);
return WRAPPERmxCreateCharMatrixFromStrings(1, &text);
} else if (type == SQLITE_FLOAT) {
return mxCreateDoubleScalar(sqlite3_column_double(stmt, index));
} else if (type == SQLITE_INTEGER) {
mxArray *a = mxCreateNumericMatrix(1, 1, mxINT64_CLASS, mxREAL);
int64_t val = sqlite3_column_int64(stmt, index);
memcpy(mxGetData(a), &val, sizeof val);
return a;
} else if (type == SQLITE_NULL) {
// This should be changed to convert NULL to the required class.
return NULL;
} else if (type == SQLITE_BLOB) {
// This returns an SQLITE_FORMAT error status later.
return NULL;
}
// This should never happen.
return NULL;
}
This function is unable to tell whether the NULL should be a char, a double, or an integer. It then fails (and keeps the file locked, which is one of the bugs I'm trying to fix in v3.0.1).
If you have any practical suggestions for how to fix this, please feel free to suggest them.
  댓글 수: 3
Sebastian
Sebastian 2023년 4월 24일
Thank you for your support. You bugfix solves the issue for me. Since I'm not a sqlite expert, I cannot make suggestions how the behaviour for a BLOB should be. I only recognized the error when updating to the new version and running my unit tests.
Rik
Rik 2023년 4월 24일
You're welcome. If I solved your issue, please consider marking it as accepted answer.
I will update the FEX submission when I get round to it. I want to merge this fix with a few other changes as well, so the update there may take a while.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by