How do I pull data from an SQLite daatbase into Matlab workspace
39 ビュー (過去 30 日間)
表示 古いコメント
Hi I have somehow managed to put together some python code to retrieve data in an SQL lite database, I know which to pull that same data from the SQLite data base into the Matlab workspace. Do I merely connect to the database using 'conn' and then use 'fetch'? Is there another means by which I can pull the data into a cell array structure?
0 件のコメント
回答 (1 件)
Kojiro Saito
2017 年 9 月 5 日
4 件のコメント
Christian Hager
2021 年 2 月 25 日
編集済み: Christian Hager
2021 年 2 月 25 日
It seems your database is in a different location than your Matlab active directory. Below how I use it to get all table names and column names for each table.
%%%%% CONNECT %%%%%%%%%
dbfile = fullfile(path,'fj.sqlite');
conn = sqlite(dbfile);
%%%%% TABLES & COLUMNS %%%%%
query = 'SELECT * FROM sqlite_master WHERE type = "table"';
TableSet = fetch(conn,query);
DBA_Tables = TableSet(:,2:3); % col 2 and 3 both have table names
for i = 1:size(DBA_Tables,1)
query = ['SELECT sql FROM sqlite_master WHERE tbl_name = ','''',DBA_Tables{i,1},'''',' AND type = "table"'];
cols = fetch(conn,Query);
cols = regexp(cols,'(?<=")\w+(?=")','match');
DBA_Tables{i,2} = unique(cols{1})'; % replace table name cell with column names for each table
end
参考
カテゴリ
Find more on Database Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!