- “contains" function: https://in.mathworks.com/help/matlab/ref/string.contains.html
- “database": https://in.mathworks.com/help/database/ug/database.html
database catalog is a full path not a word
3 次查看(过去 30 天)
显示 更早的评论
I want to use 'SQL USE CLAUSE' to change database catalog based on Matlab and access 2013, but it seems dificult to realize when catalog is a full path. how can I do or change my codes?
connin = database('inputmatlab','','');
MSin=connin.Message;
B=connin.Catalogs;
sqlquery = 'Use C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb';
A=exec(connin,sqlquery);
The 'A=exec(connin,sqlquery)' is a error.
close(connin);
The connin information is :
DataSource: 'inputmatlab'
UserName: ''
Message: ''
Type: 'ODBC Connection Object'
Database Properties:
AutoCommit: 'on'
ReadOnly: 'off'
LoginTimeout: -1
MaxDatabaseConnections: -1
Catalog and Schema Information:
DefaultCatalog: 'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb'
Catalogs: {'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\ASCE3.accdb', ' ...\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\HINDAWI3.accdb', 'C:\Users\dell-pc\Desktop\ACCESSstudy\JournalRPaperTitle3\MDPI3.accdb' ... and 6 more}
Schemas: {}
Database and Driver Information:
DatabaseProductName: 'ACCESS'
DatabaseProductVersion: '12.00.0000'
DriverName: 'ACEODBC.DLL'
DriverVersion: 'Microsoft Access database engine'
0 个评论
回答(1 个)
Ravi
2023-11-27
Hi PP Wei,
I assume you want to search for a catalog based on a single word instead of using the complete path for that catalog.
One possible solution to your question is, you can obtain the list of catalogs from the connection object and search for the word in every catalog path. If the catalog path contains the word you are searching for, then use that catalog present at that index in your SQL USE query. Please note that, the word contains the extension of the database. Example, word = “ACSE3.accdb”.
Please refer to the code snippet that illustrates the workflow mentioned above:
db = '';
found = false;
isPresent = contains(catalogs, word);
for i = 1:length(catalogs)
if(isPresent(i))
disp(catalogs{i});
db = catalogs{i};
found = true;
end
end
if ~found
disp('file not found');
else
query = "use " + db;
end
Please refer to the below documentation to learn more about:
Hope this helps.
Thanks,
Ravi Chandra
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!