components_node/functions-db.js
/**
     * Function do return results from any field in table.
     * @static
     * @async
     * @param {integer} idRecord 
     * @param {string} strTable categories
     * @param {string} fieldName 
     * @returns {string}
     */
Function do return results from any field in table.
Function do return results from any field in table .
static async genericFieldGet01(idRecord, strTable, fieldName)
    {
        let strReturn = "";
        let objResultGenericField;
        let strSQLGenericFieldSelect = "";
        let strSQLGenericFieldSelectParams = [];
        if(strTable)
        {
            strSQLGenericFieldSelect += "SELECT ";
            strSQLGenericFieldSelect += "id, ";
            strSQLGenericFieldSelect += "title ";
            strSQLGenericFieldSelect += "FROM " + process.env.CONFIG_SYSTEM_DB_TABLE_PREFIX + FunctionsGeneric.contentMaskWrite(strTable, "db_sanitize") + " ";
            strSQLGenericFieldSelect += "WHERE id <> 0";
            if(idRecord)
            {
                strSQLGenericFieldSelect += " AND id = ?";
                strSQLGenericFieldSelectParams.push(idRecord);
            }
            objResultGenericField = await new Promise((resolve, reject) => {
                dbSystemConPool.getConnection(function(dbSystemPoolError, dbSystemConPoolGetConnection) {
                    if(dbSystemPoolError)
                    {
                        if(gSystemConfig.configDebug === true)
                        {
                            console.log(FunctionsGeneric.appLabelsGet(gSystemConfig.configLanguageBackend.appLabels, "statusMessageError50"));
                        }
                        throw dbSystemPoolError;
                    }else{
                        dbSystemConPoolGetConnection.query(strSQLGenericFieldSelect, strSQLGenericFieldSelectParams, (dbSystemError, resultsSQLCounterRows) => {
                            dbSystemConPoolGetConnection.release();
                            if(dbSystemError)
                            {
                                if(gSystemConfig.configDebug === true)
                                {
                                    console.log(FunctionsGeneric.appLabelsGet(gSystemConfig.configLanguageBackend.appLabels, "statusMessageError50"));
                                }
                                throw dbSystemError;
                            }else{
                                if(resultsSQLCounterRows === undefined)
                                {
                                    if(gSystemConfig.configDebug === true)
                                    {
                                        console.log(FunctionsGeneric.appLabelsGet(gSystemConfig.configLanguageBackend.appLabels, "statusMessage9"));
                                    }
                                    reject(new Error(FunctionsGeneric.appLabelsGet(gSystemConfig.configLanguageBackend.appLabels, "statusMessage9")));
                                }else{
                                    resolve(resultsSQLCounterRows);
                                }
                            }
                        });
                    }
                });  
            });
            strReturn = objResultGenericField[0][fieldName];
        }else{
            strReturn = "";
        }
        /*
        return new Promise((resolve, reject) => {
            dbSystemCon.query(strSQLCounterSelect, strSQLCounterParams, (dbSystemError, resultsSQLCounterRows) => {
                if(dbSystemError)
                {
                    throw dbSystemError;
                }else{
                    nCounter = resultsSQLCounterRows[0].counter_global;
                    if(nCounter === undefined)
                    {
                        reject(new Error("nCounter is undefined."));
                    }else{
                        resolve(nCounter);
                    }
                    //Debug.
                    //resolve(resultsSQLCounterRows);
                    //resolve(nCounter);
                    //resolve(json(resultsSQLCounterRows));//working: returns [ RowDataPacket { id: 1, counter_global: 123, description: 'Node database test' } ]
                }
            });
        });   
        */     
        return strReturn;
    }
static async genericFieldGet01 ( idRecord , strTable , fieldName ) { let strReturn = "" ; let objResultGenericField ; let strSQLGenericFieldSelect = "" ; let strSQLGenericFieldSelectParams = [ ] ; if ( strTable ) { strSQLGenericFieldSelect += "SELECT " ; strSQLGenericFieldSelect += "id, " ; strSQLGenericFieldSelect += "title " ; strSQLGenericFieldSelect += "FROM " + process . env . CONFIG_SYSTEM_DB_TABLE_PREFIX + FunctionsGeneric . contentMaskWrite ( strTable , "db_sanitize" ) + " " ; strSQLGenericFieldSelect += "WHERE id <> 0" ; if ( idRecord ) { strSQLGenericFieldSelect += " AND id = ?" ; strSQLGenericFieldSelectParams . push ( idRecord ) ; } objResultGenericField = await new Promise ( ( resolve , reject ) => { dbSystemConPool . getConnection ( function ( dbSystemPoolError , dbSystemConPoolGetConnection ) { if ( dbSystemPoolError ) { if ( gSystemConfig . configDebug === true ) { console . log ( FunctionsGeneric . appLabelsGet ( gSystemConfig . configLanguageBackend . appLabels , "statusMessageError50" ) ) ; } throw dbSystemPoolError ; } else { dbSystemConPoolGetConnection . query ( strSQLGenericFieldSelect , strSQLGenericFieldSelectParams , ( dbSystemError , resultsSQLCounterRows ) => { dbSystemConPoolGetConnection . release ( ) ; if ( dbSystemError ) { if ( gSystemConfig . configDebug === true ) { console . log ( FunctionsGeneric . appLabelsGet ( gSystemConfig . configLanguageBackend . appLabels , "statusMessageError50" ) ) ; } throw dbSystemError ; } else { if ( resultsSQLCounterRows === undefined ) { if ( gSystemConfig . configDebug === true ) { console . log ( FunctionsGeneric . appLabelsGet ( gSystemConfig . configLanguageBackend . appLabels , "statusMessage9" ) ) ; } reject ( new Error ( FunctionsGeneric . appLabelsGet ( gSystemConfig . configLanguageBackend . appLabels , "statusMessage9" ) ) ) ; } else { resolve ( resultsSQLCounterRows ) ; } } } ) ; } } ) ; } ) ; strReturn = objResultGenericField [ 0 ] [ fieldName ] ; } else { strReturn = "" ; } return strReturn ; }
Function do return results from any field in table.
Function do return results from any field in table .
//Variables. //---------------------- //---------------------- //Query. //---------------------- //---------------------- //Parameters. //---------------------- //if(idRecord != null && idRecord != "" && (typeof idRecord !== 'undefined')) //strSQLGenericFieldSelect += " AND " + mysql.escape("id") + " = ?";//not workig, because it wraps in single quotes. //---------------------- //Execute query. //---------------------- //dbSystemCon.query(strSQLGenericFieldSelect, strSQLGenericFieldSelectParams, (dbSystemError, resultsSQLCounterRows) => { //Error. //return reject(dbSystemError); //Select the counter number. //nCounter = resultsSQLCounterRows[0][fieldName]; //objResultGenericField = resultsSQLCounterRows[0][fieldName]; //if(nCounter === undefined) //Error. //reject(new Error("nCounter is undefined.")); //Success. //Return data treatment. //---------------------- //strReturn = nCounter; //---------------------- //strReturn = false; /*
        return new Promise((resolve, reject) => {
            dbSystemCon.query(strSQLCounterSelect, strSQLCounterParams, (dbSystemError, resultsSQLCounterRows) => {
                if(dbSystemError)
                {
                    throw dbSystemError;

                    //return reject(dbSystemError);
                }else{
                    //Select the counter number.
                    nCounter = resultsSQLCounterRows[0].counter_global;

                    if(nCounter === undefined)
                    {
                        reject(new Error("nCounter is undefined."));
                    }else{
                        resolve(nCounter);
                    }
                        

                    //Debug.
                    //resolve(resultsSQLCounterRows);
                    //resolve(nCounter);
                    //resolve(json(resultsSQLCounterRows));//working: returns [ RowDataPacket { id: 1, counter_global: 123, description: 'Node database test' } ]
                }
            });
        });   
        */ //---------------------- //Usage. //---------------------- //${ await SyncSystemNS.FunctionsDB.genericFieldGet01(790, gSystemConfig.configSystemDBTableCategories, "title")/**/ + '' } //----------------------