Blackberry Webworks 웹 응용 프로그램이 BB5에서 실행되며 SQLite 데이터베이스를 사용하여 데이터를 로컬에 저장합니다. 데이터베이스에는 이벤트 및 항공편이라는 두 개의 테이블이 있으며, 하나의 이벤트에 여러 개의 항공편이 연결될 수 있습니다.Blackberry Webworks에서 SQLite를 사용하여 관련 데이터 삽입
데이터 배열에서 두 테이블을 채우는 방법을 찾기가 어렵습니다. 내 문제는 BB의 SQLite 구현이 비동기 방식으로 작동하기 때문에 외래 키를 flight 테이블에 삽입하는 것입니다.
db.transaction(function(tx) {
for(var i = 0; i < eventsArray.length; i++) {
var insertId = 0;
tx.executeSql("INSERT INTO event(id,eventName,venueName) VALUES (?,?,?)",
[null,
eventsArray[i].eventName,
eventsArray[i].venueName],
function(tx,result) { //success callback
insertId = result.insertId;
//If I try inserting flights here, eventsArray[i] always returns
//the last item in the array, the for loop has kept running
}
);
//If I try inserting here, I don't have the insertId
//to populate the foreign key (still set to 0 as the
//callbacks haven't fired yet)
}
비행 물에 대한 삽입 쿼리를 수행하려고 시도 할 때마다 데이터 조각이 누락되었습니다. 인서트 ID 또는 삽입해야하는 항공편이 포함 된 실제 이벤트 객체입니다.
더 좋은 방법이 있나요?