2.8 Database 실시간 작업

Document

2.8 Database 실시간 작업

​↑↑↑ For more details, please download the attached! 



a6b815b7fa0d80c8166d9718d1b2c1b8_1681095786_9216.png 



사용된 스크립트 샘플


 function page_OnLoad(event) { //페이지가 로드되면서 실행

$XT("Database2.analog_1").addEventListener("change", DataAChange);

$XT("Database2.analog_2").addEventListener("change", DataBChange);

console.log("page_OnLoad Execution");

}

function DataAChange(){ //Database2.analog_1 태그 값이 변경되면 실행

$XD("sqlite_2").execute("insert_data", null , OnsuccessInsert, onInsertError);

console.log("DataAChange Execution");

}

function DataBChange(){ //Database2.analog_2 태그 값이 변경되면 실행

$XD("sqlite_2").execute("insert_data", null , OnsuccessInsert, onInsertError);

console.log("DataBChange Execution");

}

function OnsuccessInsert(data) { //sqlite_2 데이터소스에 select_all 실행

$XD("sqlite_2").execute("select_all", null, OnsuccessListView, null);

console.log("OnsuccessInsert Execution");

}

function onInsertError(msg) { //sqlite_2 데이터소스에 select_all 실행

alert(msg);

}

function OnsuccessListView(data) { //OnsuccessInsert(data) 실행

$XV("listview_1").items.clear();

$XV("listview_1").items.addAll(data);

console.log("OnsuccessListView Execution");

}

function delete_OnClick(event) { //sqlite_2 데이터소스에 delete_all 실행

$XD("sqlite_2").execute("delete_all", null, OnsuccessListView, null);

console.log("delete_OnClick Execution");

}




사용된 SQL 샘플


[select_all]

select no, data1, data2, strftime('%Y-%m-%d %H:%M:%f', otime) as otime from tb1 order by no desc;


[delete_all]

delete from tb1;

update sqlite_sequence set seq=0 where name = "tb1";


[insert_data]

insert into tb1(data1, data2, otime) values(#{Database2.analog_1}, #{Database2.analog_2}, strftime('%Y-%m-%d %H:%M:%f', 'now'));

0 Reply Comment
Title