jayralencar / sqlite-sync.js

Node module to sqlite sync and async
MIT License
78 stars 30 forks source link

Params not working in WITH AS queries #29

Open rory1212 opened 3 years ago

rory1212 commented 3 years ago

When you trying to execute WITH AS query with parameters, It's not working.

My solution is:

sqlite.prototype.run = function (sql, options, callback) {
    if (typeof (options) == "function") {
        callback = options;
        options = [];
    }
    var results;
    var type = sql.substring(0, 6);
    type = type.toUpperCase();
    if (type.startsWith('WITH')) {
        type = 'WITH';
    }
    switch (type) {
        case "SELECT":
        case "WITH":
            results = this.pvSELECT(sql, options);
            break;
        case "INSERT":
            results = this.pvINSERT(sql, options);
            break;
        case "UPDATE":
            results = this.pvUPDATE(sql, options);
            break;
        case "DELETE":
            results = this.pvDELETE(sql, options);
            break;
        case "PRAGMA":
            results = this.pvPRAGMA(sql, options);
            break;
        default:
            results = this.runAll(sql)
    }
    if (callback) {
        callback(results);
        return this;
    } else {
        return results;
    }
};