无法执行sqlite查询(本机反应)

时间:2018-10-28 10:44:07

标签: sqlite react-native react-native-android

我想执行此查询,并通过service_id返回service_name

我不知道查询的语法是否正确,因为它不会更改service_name的值

这是我的代码:

    getServiceNameById = (service_id) => {

       var service_name = 'passport';
       db.transaction((tx) => {
        var query = 'select * from service_details where service_id ='+service_id;

        tx.executeSql(query, [], (tx, results) => {
            var len = results.rows.length;
            if (len > 0) {
                for (let i = 0; i < len; i++) {
                    let row = results.rows.item(i);
                    service_name = row.service_name;
                }

            }

            console.log(service_name);  // -> it show in console  the initial value of service_name : passport 
            return(service_name); 


        });
    });


        } 

请帮忙

0 个答案:

没有答案