fetch returns a table full of cells for 'char' values

3 vues (au cours des 30 derniers jours)
Sara Brunner
Sara Brunner le 26 Jan 2020
Modifié(e) : Sara Brunner le 5 Fév 2020
I use fetch to get data from a MS Azure SQL Database into Matlab. My script worked when I last ran it - approximately 10 days ago. In the meanwhile the DB has been updated - the only change were changes in naming of tables and columns.
However, now I get a table where each field that should contain a character arrays, contains a cell. This makes it hard to work with the character arrays.
I tried to set the DB preferences, but it did not change the output.
setdbprefs('DataReturnFormat', 'table');
I also tried to put my simple SQL statement in a file and use runsqlscript instead of fetch - but I still got the char arrays in cells.
conn = database(datasource, username,password);
runsqlscript(conn,mySQLscript.sql)
This is the code I try to run (with some connetion details changed, of course)
conn = database(datasource, username,password);
sqlTest = 'select * from MyTableOfInterest'
conn = database('MyDB','DB_Reader_user','MyPassword','Vendor','MICROSOFT SQL SERVER','Server','myProjectServer.database.windows.net','PortNumber',1433,'AuthType','Server');
dataDB_ids = fetch(conn,sqlTest);
close(conn)
The result looks like this:
Matlab_Table_troubleShooting.JPG
I would like to have is the above picture without the curley brackets.
I know I can do that with using for-loops and changing field per field, but there must be a smarter solution. (Especially since I think the the result looked fine last time I ran the script).
Technical details:
MATLAB Version: 9.7.0.1247435 (R2019b) Update 2
Database Toolbox Version 9.2 (R2019b)
Best regards, Sara

Réponses (1)

Harsha Priya Daggubati
Harsha Priya Daggubati le 31 Jan 2020
  1 commentaire
Sara Brunner
Sara Brunner le 5 Fév 2020
Modifié(e) : Sara Brunner le 5 Fév 2020
Thanks Harsha,
I set the sqlimportoptions VariableTypes to 'char', but I still get {'char'} as a result in my table.
I guess it has something to do with fields containing NULL even if I do not have any in my selection.
However, I implemented a workaround (with for loops) which decreases the performance, but it works.

Connectez-vous pour commenter.

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by