How to update value when working with SQlite database?
13 次查看(过去 30 天)
显示 更早的评论
I have a mysql lite database which is running via python. I am now trying to integrate control from MATLAB and read, write, and update values in the database from my MATLAB code.
Here is the link for sqlite database from Mathworks. https://www.mathworks.com/help/database/ug/sqlite.html
I already have my database configured via python (rows, colums, headers and so forth) and using the commands in the link above connect to the database and get my properties of the database and read the values also. I can also use the insert function if I want to add another row of data. The issue I am having is that how can I update a specific value in the database like I want to change row 2 column 2 value from lets says '0' to '1'? All the data is numerical and the headings are already defined.
If someone can guide me to which function I should be referring to simply UPDATE the value in the database?
Thanks.
0 个评论
采纳的回答
Shiva Kalyan Diwakaruni
2020-11-24
Hi,
exec(conn,sqlquery) performs database operations on an SQLite database file by executing the SQL statement SQL query for the SQLite connection conn using the MATLAB® interface to SQLite. For example, use this syntax to update the table using
example-
dbfile = fullfile(pwd,'tutorial.db')
conn = sqlite(dbfile,'create');
createInventoryTable =[‘UPDATE table’ ,’SET column_1 = new_value_1, column_2 = new_value_2’, ‘WHERE primary_key_value = current value’]
exec(conn,createInventoryTable)
Hope it helps.
References:
https://in.mathworks.com/help/database/ug/sqlite.exec.html
https://in.mathworks.com/help/database/ug/database.odbc.connection.update.html
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Database Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!