如何检查数据库条目(表行)是否已经存在

7lrncoxx  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(216)

我试图检查数据库中是否存在表条目,但到目前为止,即使没有条目,我得到的结果也总是返回true。我做错什么了?
谢谢大家。
这将永远 console.log >>>>是的

let myPersLocalEntityExistsPromise = function (localEntityGUID) {
    return new Promise(function (resolve, reject) {

        let myEntityExists = true;

        const client = myDb.mySQLDbLocalConnection();

        let stmt = "SELECT EXISTS(SELECT 1 FROM MY_ENTITY_TABLE WHERE LOCAL_MY_ENTITY_GUID = ?)";

        let todo = [
        localEntityGUID
        ];

        client.query(stmt, todo, function (err, row) {
            if (err) {
                return ("myPersLocalEntityExists: " + err.message);
            } else {
                if (row && row.length) {
                    console.log(localEntityGUID + ' Case row was found!');
                } else {
                    myEntityExists = false;
                    console.log(localEntityGUID + ' Case row was NOT found!');
                }
            }
        });

        client.end(function (err) {
            if (err) {
                console.log('ERRR');
            }
        });

        if (myEntityExists) {
            resolve(myEntityExists);
        } else {
            reject(myEntityExists);
        }
    })
}

function myPersLocalEntityExists(localEntityGUID, callback) {
    let responsePromises = []
    responsePromises.push(myPersLocalEntityExistsPromise(localEntityGUID))

    Promise.all(responsePromises).then(fromResolve => {
        console.log(">>>> " + fromResolve);
        return fromResolve;
    }).catch(fromReject => {
        console.log(">>>> " + fromReject);
        return fromReject;
    });
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题