open768 / spaceinc

chicken katsu useful space routines
0 stars 0 forks source link

replace single character SQLLite sql params with meaningful names #5

Closed open768 closed 3 months ago

open768 commented 3 months ago

im using :s,:p:i which makes sense, but causes problems when using str_replace and there are params that start with the same letter. best to use descriptive names, and bind params by name nut number:

should look like this

        $sSQL = "SELECT :m_col,:s_col,:i_col,:p_col from ':table' WHERE :m_col=:name AND  :i_col like :pattern  order by RANDOM() limit 1";
        $sSQL = str_replace(":table", self::MANIFEST_TABLE, $sSQL);
        $sSQL = str_replace(":m_col", self::COL_MISSION, $sSQL);
        $sSQL = str_replace(":s_col", self::COL_SOL, $sSQL);
        $sSQL = str_replace(":i_col", self::COL_INSTR, $sSQL);
        $sSQL = str_replace(":p_col", self::COL_PRODUCT, $sSQL);

        $oSqlDB = self::$oSQLDB;
        $oStmt = $oSqlDB->prepare($sSQL);
        $oStmt->bindValue(":name", cSpaceMissions::CURIOSITY);
        $oStmt->bindValue(":pattern", "MAST_%");
        $sSQL = $oStmt->getSQL(true);
        cDebug::extra_debug("SQL: $sSQL");