Results from DB are truncated
6 views (last 30 days)
Show older comments
I am encountering a strange limitation in retreteiving the results from SQL database.
So I'm able to store 500000 characters (probably could save more but didn't had the need to test it) in DB without any issue. I can verify this by executing SELECT LEN(Value) FROM my_test_table.
The issue is when I try to read the data I get a table and length(data.Value{1}) is 3999, no metter if I use select, fetch, readall,...
Does anyone know how to remove this limit of 3999 charaters and read all the chars from that field in DB?
4 Comments
Strider
on 24 Mar 2024
I tried to recreate your problem in sqlite, out of convenience, and I was unable to.
Try this example and see if it is giving you the same issue.
% ---- my additions
clearvars
dbfile = 'tstdb.db';
if isfile(dbfile); delete(dbfile); end
conn = sqlite(dbfile,'create');
tableName = "TestTable";
sq = sprintf("CREATE TABLE %s(Data char)",tableName);
% ---- my additions
execute(conn,sq)
% Create a long string
N = 500000;
longText = char(zeros(1, N) + 'A');
% write data to DB
inserQuery = sprintf("INSERT INTO [%s] (Data) VALUES ('%s')", tableName, longText);
execute(conn, inserQuery);
% Everything works just fine up till this point. If you check DB now you
% should see the correct entry in DB with all chars written. The issue
% starts when we want to retreive the data from DB
% read data from DB
query = sprintf("SELECT Data, length(Data) as LenInDb FROM [%s]", tableName);
res = fetch(conn, query);
% This doesn't work either
%res = select(conn, query);
% Display results
disp('Result from DB:');
numOfRows = numel(res.Data);
for i = 1:numOfRows
disp([strlength(res.Data{i}), res(i, "LenInDb").LenInDb]);
end
% Close connection
close(conn);
Answers (1)
James Anderson
on 7 Aug 2024
I think the issue here is related to ODBC, I beleive if you switch to JDBC your problem will go away.
I can't particularly find any generic issues with ODBC and data truncation online, so I think this is a specific Matlab ODBC integration issue.
0 Comments
See Also
Categories
Find more on Database Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!