2023年11月3日 星期五

SQLITE Database範例

SQLITE Database範例

DB Browser for SQLite 下載位置 https://sqlitebrowser.org/dl/

DB Browser 建立資料庫的方法

資料位置 : C:\Users\User\.node-red\LED_STATUS.db  若是路徑C:\Users\User\.node-red不對 請修正









利用Node-Red 建立資料庫

CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));

Node-Red 程式暨畫面




[{"id":"4a40fc27017c4aee","type":"inject","z":"0fce84474a62af64","name":"CREATE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));","payload":"","payloadType":"date","x":120,"y":80,"wires":[["c0d2ae99a4a73349"]]},{"id":"a4cb50b05f479276","type":"inject","z":"0fce84474a62af64","name":"SELECT","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"SELECT * FROM LEDSTATUS","payload":"","payloadType":"date","x":120,"y":160,"wires":[["c0d2ae99a4a73349"]]},{"id":"e415790f1e84d8a8","type":"inject","z":"0fce84474a62af64","name":"INSERT","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"INSERT INTO LEDSTATUS (STATUS ,  Date , Time )values(\"on\", \"11/01\" , \"21:05\") ","payload":"","payloadType":"date","x":120,"y":120,"wires":[["c0d2ae99a4a73349"]]},{"id":"d375168ccfdb75e5","type":"inject","z":"0fce84474a62af64","name":"DELETE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"DELETE from LEDSTATUS","payload":"","payloadType":"date","x":120,"y":200,"wires":[["c0d2ae99a4a73349"]]},{"id":"05a9d9bdea7d1628","type":"inject","z":"0fce84474a62af64","name":"DROP TABLE","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"DROP TABLE LEDSTATUS","payload":"","payloadType":"date","x":130,"y":240,"wires":[["c0d2ae99a4a73349"]]},{"id":"c0d2ae99a4a73349","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":380,"y":160,"wires":[["1956224795d14e15"]]},{"id":"1956224795d14e15","type":"debug","z":"0fce84474a62af64","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":160,"wires":[]},{"id":"7c3e8c967f2eb1af","type":"comment","z":"0fce84474a62af64","name":"TABLE LEDSTATUS","info":"CREATE TABLE LEDSTATUS (\nid INTEGER,\nSTATUS TEXT,\nDate DATE,\nTime TIME,\nPRIMARY KEY (id)\n);","x":130,"y":40,"wires":[]},{"id":"60cd47793ea467da","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":520,"y":320,"wires":[["3f5d47f9347bd813"]]},{"id":"86890c516abc64f3","type":"function","z":"0fce84474a62af64","name":"CREATE DATABASE","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id))\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":320,"wires":[["60cd47793ea467da"]]},{"id":"b71764bc7d416065","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":8,"width":0,"height":0,"passthru":false,"label":"建立資料庫","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"建立資料庫","payloadType":"str","topic":"topic","topicType":"msg","x":110,"y":320,"wires":[["86890c516abc64f3","af73b77670b68487"]]},{"id":"af73b77670b68487","type":"ui_audio","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":235,"y":280,"wires":[],"l":false},{"id":"92e3aaf631114a93","type":"ui_button","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","order":2,"width":0,"height":0,"passthru":false,"label":"ON","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"on","payloadType":"str","topic":"topic","topicType":"msg","x":90,"y":360,"wires":[["d1059aaa9c5af665","a23a21b05a85191f"]]},{"id":"0b6f9a928c5974e3","type":"ui_button","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","order":3,"width":0,"height":0,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"off","payloadType":"str","topic":"topic","topicType":"msg","x":90,"y":400,"wires":[["d1059aaa9c5af665","a23a21b05a85191f"]]},{"id":"f7c8be64ba8c0a1b","type":"ui_button","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","order":4,"width":0,"height":0,"passthru":false,"label":"TOGGLE","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"toggle","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":440,"wires":[["d1059aaa9c5af665","a23a21b05a85191f"]]},{"id":"95883ea8be2abb9b","type":"ui_button","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","order":5,"width":0,"height":0,"passthru":false,"label":"TIMER","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"timer","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":480,"wires":[["d1059aaa9c5af665","a23a21b05a85191f"]]},{"id":"c8aa802f0a761174","type":"ui_button","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","order":6,"width":0,"height":0,"passthru":false,"label":"FLASH","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"flash","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":520,"wires":[["a23a21b05a85191f","d1059aaa9c5af665"]]},{"id":"a23a21b05a85191f","type":"function","z":"0fce84474a62af64","name":"INSERT","func":"var Today = new Date();\nvar yyyy = Today.getFullYear(); //年\nvar MM = Today.getMonth()+1;    //月\nvar dd = Today.getDate();       //日\nvar h = Today.getHours();       //時\nvar m = Today.getMinutes();     //分\nvar s = Today.getSeconds();     //秒\nif(MM<10)\n{\n   MM = '0'+MM;\n}\n\nif(dd<10)\n{\n   dd = '0'+dd;\n}\n\nif(h<10)\n{\n   h = '0'+h;\n}\n\nif(m<10)\n{\n  m = '0' + m;\n}\n\nif(s<10)\n{\n  s = '0' + s;\n}\nvar var_date = yyyy+'/'+MM+'/'+dd;\nvar var_time = h+':'+m+':'+s;\n\nvar myLED = msg.payload;\n\n\nmsg.topic = \"INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED,  $var_date ,  $var_time ) \" ;\nmsg.payload = [myLED, var_date , var_time ]\nreturn msg;\n\n\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":460,"wires":[["b9d317cad4523445"]]},{"id":"d1059aaa9c5af665","type":"ui_audio","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":255,"y":420,"wires":[],"l":false},{"id":"b9d317cad4523445","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":460,"y":460,"wires":[["1723ef473e3dde7e","d5663f9afbb3fa6d"]]},{"id":"3f5d47f9347bd813","type":"debug","z":"0fce84474a62af64","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":320,"wires":[]},{"id":"1723ef473e3dde7e","type":"debug","z":"0fce84474a62af64","name":"debug ","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":460,"wires":[]},{"id":"d135a6ec97fba847","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":2,"width":0,"height":0,"passthru":false,"label":"檢視資料庫資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"檢視資料","payloadType":"str","topic":"topic","topicType":"msg","x":140,"y":620,"wires":[["d5663f9afbb3fa6d","2e1fb770146e7bd5"]]},{"id":"d5663f9afbb3fa6d","type":"function","z":"0fce84474a62af64","name":"檢視資料","func":"//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY  id DESC LIMIT 50;\n\nmsg.topic = \"SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":620,"wires":[["be334eb3c9c72c77"]]},{"id":"c833d46f61a95f22","type":"ui_table","z":"0fce84474a62af64","group":"821196f103500796","name":"","order":1,"width":10,"height":10,"columns":[],"outputs":0,"cts":false,"x":790,"y":620,"wires":[]},{"id":"be334eb3c9c72c77","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":520,"y":620,"wires":[["c833d46f61a95f22"]]},{"id":"9244615e88c96c40","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":3,"width":2,"height":1,"passthru":false,"label":"刪除資料庫 ","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除資料庫 ","payloadType":"str","topic":"topic","topicType":"msg","x":130,"y":860,"wires":[["2d3cc6f5ba1af6f0","7ca5dd04f5e01509"]]},{"id":"cd1d9de75df07cd0","type":"function","z":"0fce84474a62af64","name":"DROP DATABASE","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DROP TABLE LEDSTATUS\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":800,"wires":[["28ecf1d0f6f3982f"]]},{"id":"28ecf1d0f6f3982f","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":740,"y":720,"wires":[["3f3c89fd5a478259"]]},{"id":"d71be695ba437ed1","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":4,"width":2,"height":1,"passthru":false,"label":"刪除所有資料 ","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除所有資料 ","payloadType":"str","topic":"topic","topicType":"msg","x":140,"y":760,"wires":[["7ca5dd04f5e01509","d74709cfd5386eb4"]]},{"id":"6f16cd694e3efb89","type":"function","z":"0fce84474a62af64","name":"DELETE ALL DATA","func":"//CREATE TABLE LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));\nmsg.topic = \"DELETE from LEDSTATUS\";\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":700,"wires":[["28ecf1d0f6f3982f"]]},{"id":"2d3cc6f5ba1af6f0","type":"ui_toast","z":"0fce84474a62af64","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":310,"y":860,"wires":[["9acf06a4cf765e75"]]},{"id":"9acf06a4cf765e75","type":"function","z":"0fce84474a62af64","name":"function 84","func":"var topic=msg.payload;\nif (topic==\"\"){\n    return [msg,null];\n    \n}\nif (topic==\"Cancel\"){\n    return [null,msg];\n    \n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":860,"wires":[["cd1d9de75df07cd0"],[]]},{"id":"7ca5dd04f5e01509","type":"ui_audio","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":205,"y":800,"wires":[],"l":false},{"id":"d74709cfd5386eb4","type":"ui_toast","z":"0fce84474a62af64","position":"prompt","displayTime":"3","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":true,"className":"","topic":"","name":"","x":330,"y":760,"wires":[["eeaa85327128f533"]]},{"id":"eeaa85327128f533","type":"function","z":"0fce84474a62af64","name":"function 85","func":"var topic=msg.payload;\nif (topic==\"\"){\n    return [msg,null];\n    \n}\nif (topic==\"Cancel\"){\n    return [null,msg];\n    \n}\nreturn msg;","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":760,"wires":[["6f16cd694e3efb89"],[]]},{"id":"2e1fb770146e7bd5","type":"ui_audio","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":295,"y":560,"wires":[],"l":false},{"id":"968be0bad8c6a400","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":5,"width":2,"height":1,"passthru":false,"label":"查詢一筆資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"查詢一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":140,"y":920,"wires":[["7ca5dd04f5e01509","4fd8732e3834030b"]]},{"id":"1d68074d89550fe0","type":"function","z":"0fce84474a62af64","name":"查詢一筆資料","func":"//\nvar id = msg.payload.id;\nmsg.topic=\"\";\nlet temp =\"SELECT * FROM LEDSTATUS\";\ntemp=temp+\" WHERE id LIKE '\"+ id +\"'\";\nmsg.topic=temp;\n\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE  LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//SELECT * FROM LEDSTATUS ORDER BY  id DESC LIMIT 50;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":920,"wires":[["a7451617bea651ab"]]},{"id":"4fd8732e3834030b","type":"ui_form","z":"0fce84474a62af64","name":"","label":"輸入id (查詢)一筆","group":"a46cce9233c736c8","order":7,"width":4,"height":1,"options":[{"label":"ID","value":"id","type":"number","required":true,"rows":null}],"formValue":{"id":""},"payload":"","submit":"Submit","cancel":"Cancle","topic":"Form","topicType":"str","splitLayout":false,"className":"","x":370,"y":920,"wires":[["1d68074d89550fe0"]]},{"id":"a7451617bea651ab","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":720,"y":840,"wires":[["c833d46f61a95f22"]]},{"id":"1b74c7a4478ca5ac","type":"ui_button","z":"0fce84474a62af64","name":"","group":"a46cce9233c736c8","order":6,"width":2,"height":1,"passthru":false,"label":"刪除一筆資料","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"刪除一筆資料","payloadType":"str","topic":"topic","topicType":"msg","x":140,"y":980,"wires":[["b6bffe3d5d1a6d85","d4eb7ebe30fccb1a"]]},{"id":"b6bffe3d5d1a6d85","type":"ui_audio","z":"0fce84474a62af64","name":"","group":"11d8514.a44dcaf","voice":"Microsoft Hanhan - Chinese (Traditional, Taiwan)","always":true,"x":245,"y":1040,"wires":[],"l":false},{"id":"d4eb7ebe30fccb1a","type":"ui_form","z":"0fce84474a62af64","name":"","label":"輸入id (刪除)一筆","group":"a46cce9233c736c8","order":1,"width":0,"height":0,"options":[{"label":"ID","value":"id","type":"number","required":true,"rows":null}],"formValue":{"id":""},"payload":"","submit":"Submit","cancel":"Cancle","topic":"Form","topicType":"str","splitLayout":false,"className":"","x":350,"y":980,"wires":[["acef5c22c3f96d7c"]]},{"id":"acef5c22c3f96d7c","type":"function","z":"0fce84474a62af64","name":"刪除一筆資料","func":"//\nvar id = msg.payload.id;\nmsg.topic=\"\";\nlet temp =\"DELETE FROM LEDSTATUS\";\ntemp=temp+\" WHERE id LIKE '\"+ id +\"'\";\nmsg.topic=temp;\n\nreturn msg;\n\n//SELECT * FROM COMPANY WHERE AGE  LIKE 'XXX%';\n//INSERT INTO LEDSTATUS (\n//id INTEGER,\n//STATUS TEXT,\n//Date DATE,\n//Time TIME,\n//PRIMARY KEY (id)\n//);\n\n//DELETE FROM COMPANY WHERE ID = 7;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":980,"wires":[["8686af22dec010df"]]},{"id":"3f3c89fd5a478259","type":"link out","z":"0fce84474a62af64","name":"link out 38","mode":"link","links":["c2630df45cb7cf5a"],"x":875,"y":720,"wires":[]},{"id":"c2630df45cb7cf5a","type":"link in","z":"0fce84474a62af64","name":"link in 35","links":["3f3c89fd5a478259"],"x":255,"y":660,"wires":[["d5663f9afbb3fa6d"]]},{"id":"8686af22dec010df","type":"sqlite","z":"0fce84474a62af64","mydb":"4e71ffcc.32ba8","sqlquery":"msg.topic","sql":"","name":"LED_STATUS","x":780,"y":960,"wires":[["3f3c89fd5a478259"]]},{"id":"4e71ffcc.32ba8","type":"sqlitedb","db":"C:\\Users\\User\\.node-red\\LED_STATUS.db","mode":"RWC"},{"id":"a46cce9233c736c8","type":"ui_group","name":"命令","tab":"8f1ada5fa4df30e2","order":3,"disp":true,"width":4,"collapse":false,"className":""},{"id":"11d8514.a44dcaf","type":"ui_group","name":"新增","tab":"8f1ada5fa4df30e2","order":2,"disp":true,"width":"4","collapse":false,"className":""},{"id":"821196f103500796","type":"ui_group","name":"顯示","tab":"8f1ada5fa4df30e2","order":2,"disp":true,"width":10,"collapse":false,"className":""},{"id":"8f1ada5fa4df30e2","type":"ui_tab","name":"控制","icon":"dashboard","disabled":false,"hidden":false}]



資料位置 : C:\Users\User\.node-red\LED_STATUS.db  若是路徑C:\Users\User\.node-red不對 請修正

命令

SQLite語法

 

CREATE

CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));

 

INSERT

INSERT INTO LEDSTATUS (STATUS ,  Date , Time )values("on", "11/01" , "21:05")

 

SELECT

SELECT * FROM LEDSTATUS

 

DELETE

DELETE from LEDSTATUS

 

DROP TABLE

DROP TABLE LEDSTATUS

 

Function

CREATE DATABASE

//CREATE TABLE LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));

msg.topic = "CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id))";

return msg;

 

INSERT

var Today = new Date();

var yyyy = Today.getFullYear(); //

var MM = Today.getMonth()+1;    //

var dd = Today.getDate();       //

var h = Today.getHours();       //

var m = Today.getMinutes();     //

var s = Today.getSeconds();     //

if(MM<10)

{

   MM = '0'+MM;

}

 

if(dd<10)

{

   dd = '0'+dd;

}

 

if(h<10)

{

   h = '0'+h;

}

 

if(m<10)

{

  m = '0' + m;

}

 

if(s<10)

{

  s = '0' + s;

}

var var_date = yyyy+'/'+MM+'/'+dd;

var var_time = h+':'+m+':'+s;

 

var myLED = msg.payload;

 

 

msg.topic = "INSERT INTO LEDSTATUS ( STATUS , Date , Time ) VALUES ($myLED,  $var_date ,  $var_time ) " ;

msg.payload = [myLED, var_date , var_time ]

return msg;

 

 

//INSERT INTO LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

 

 

檢視資料

//INSERT INTO LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

 

//SELECT * FROM LEDSTATUS ORDER BY  id DESC LIMIT 50;

 

msg.topic = "SELECT * FROM LEDSTATUS ORDER BY id DESC LIMIT 50";

return msg;

 

DELETE ALL DATA

//CREATE TABLE LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));

msg.topic = "DELETE from LEDSTATUS";

return msg;

 

function  84

function  85

var topic=msg.payload;

if (topic==""){

    return [msg,null];

   

}

if (topic=="Cancel"){

    return [null,msg];

   

}

return msg;

 

DROP DATABASE

//CREATE TABLE LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

//CREATE TABLE LEDSTATUS (id INTEGER,STATUS TEXT,Date DATE,Time TIME,PRIMARY KEY (id));

msg.topic = "DROP TABLE LEDSTATUS";

return msg;

 

查詢一筆資料

//

var id = msg.payload.id;

msg.topic="";

let temp ="SELECT * FROM LEDSTATUS";

temp=temp+" WHERE id LIKE '"+ id +"'";

msg.topic=temp;

 

return msg;

 

//SELECT * FROM COMPANY WHERE AGE  LIKE 'XXX%';

//INSERT INTO LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

 

//SELECT * FROM LEDSTATUS ORDER BY  id DESC LIMIT 50;

 

刪除一筆資料

//

var id = msg.payload.id;

msg.topic="";

let temp ="DELETE FROM LEDSTATUS";

temp=temp+" WHERE id LIKE '"+ id +"'";

msg.topic=temp;

 

return msg;

 

//SELECT * FROM COMPANY WHERE AGE  LIKE 'XXX%';

//INSERT INTO LEDSTATUS (

//id INTEGER,

//STATUS TEXT,

//Date DATE,

//Time TIME,

//PRIMARY KEY (id)

//);

 

//DELETE FROM COMPANY WHERE ID = 7;

 

資料位置 : C:\Users\User\.node-red\LED_STATUS.db

沒有留言:

張貼留言

2024_09 作業3 以Node-Red 為主

 2024_09 作業3  (以Node-Red 為主  Arduino 可能需要配合修改 ) Arduino 可能需要修改的部分 1)mqtt broker  2) 主題Topic (發行 接收) 3) WIFI ssid , password const char br...