]> git.mxchange.org Git - mailer.git/blobdiff - inc/db/lib-mysql3.php
Added more wrapper, commented out another noisy debug line
[mailer.git] / inc / db / lib-mysql3.php
index 17caef397c5f9ee472bf9242c8ddf84df30fb0da..2f1c1b4fe1bfa93295d677caf688c1d40e7553ab 100644 (file)
@@ -73,7 +73,7 @@ function SQL_QUERY ($sqlString, $F, $L, $enableCodes = true) {
 
                // Cache it and remember as last SQL query
                $GLOBALS[__FUNCTION__][$sqlString] = $sqlStringModified;
-               $GLOBALS['last_sql'] = $sqlStringModified;
+               $GLOBALS['last_sql']               = $sqlStringModified;
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Stored cache: ' . $sqlStringModified);
        }  else {
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cache used: ' . $sqlString);
@@ -269,10 +269,18 @@ function SQL_FREERESULT ($resource) {
 // SQL string escaping
 function SQL_QUERY_ESC ($sqlString, $data, $F, $L, $run = true, $strip = true, $secure = true) {
        // Link is there?
-       if ((!SQL_IS_LINK_UP()) || (!is_array($data))) return false;
+       if ((!SQL_IS_LINK_UP()) || (!is_array($data))) {
+               // Link is down or data is not an array
+               /* DEBUG: */ logDebugMessage($F, $L, 'SQL_IS_LINK_UP()=' . intval(SQL_IS_LINK_UP()) . ',data[]=' . gettype($data) . ',sqlString=' . $sqlString . ': ABORTING!');
+               return false;
+       } // END - if
+
+       // Init array for escaped data with SQL string
+       $dataSecured = array(
+               '__sql_string' => $sqlString
+       );
 
        // Escape all data
-       $dataSecured['__sql_string'] = $sqlString;
        foreach ($data as $key => $value) {
                $dataSecured[$key] = SQL_ESCAPE($value, $secure, $strip);
        } // END - foreach
@@ -413,32 +421,32 @@ function SQL_ALTER_TABLE ($sql, $F, $L, $enableCodes = true) {
                        $columnName = $tableArray[$idx];
 
                        // Debug log
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(isSqlTableColumnFound($tableName, $columnName)));
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'columnName=' . $columnName . ',idx=' . $idx . ',sql=' . $sql . ',hasZeroNums=' . intval(ifSqlColumnExists($tableName, $columnName)));
 
                        // Do we have no entry on ADD or an entry on DROP/CHANGE?
-                       if (((!isSqlTableColumnFound($tableName, $columnName)) && (isInString('ADD', $sql))) || ((isSqlTableColumnFound($tableName, $columnName)) && ((isInString('DROP', $sql)) || ((isInString('CHANGE', $sql)) && ($idx == 4) && ((!isSqlTableColumnFound($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) {
+                       if (((!ifSqlColumnExists($tableName, $columnName)) && (isInString('ADD', $sql))) || ((ifSqlColumnExists($tableName, $columnName)) && ((isInString('DROP', $sql)) || ((isInString('CHANGE', $sql)) && ($idx == 4) && ((!ifSqlColumnExists($tableName, $tableArray[5])) || ($columnName == $tableArray[5])))))) {
                                // Do the query
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Executing: ' . $sql);
                                $result = SQL_QUERY($sql, $F, $L, false);
 
                                // Skip further attempt(s)
                                break;
-                       } elseif ((((isSqlTableColumnFound($tableName, $columnName)) && (isInString('ADD', $sql))) || ((!isSqlTableColumnFound($tableName, $columnName)) && ((isInString('DROP', $sql))) || (isInString('CHANGE', $sql)))) && ($columnName != 'KEY')) {
+                       } elseif ((((ifSqlColumnExists($tableName, $columnName)) && (isInString('ADD', $sql))) || ((!ifSqlColumnExists($tableName, $columnName)) && ((isInString('DROP', $sql))) || (isInString('CHANGE', $sql)))) && ($columnName != 'KEY')) {
                                // Abort here because it is alreay there
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Skipped: sql=' . $sql . ',columnName=' . $columnName . ',idx=' . $idx);
                                break;
-                       } elseif ((!isSqlTableColumnFound($tableName, $columnName)) && (isInString('DROP', $sql))) {
+                       } elseif ((!ifSqlColumnExists($tableName, $columnName)) && (isInString('DROP', $sql))) {
                                // Abort here because we tried to drop a column which is not there (never created maybe)
                                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'No drop: ' . $sql);
                                break;
                        } elseif ($columnName != 'KEY') {
                                // Something didn't fit, we better log it
-                               logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(isSqlTableColumnFound($tableName, $columnName)) . '');
+                               logDebugMessage(__FUNCTION__, __LINE__, 'Possible problem: ' . $sql . ',hasZeroNums=' . intval(ifSqlColumnExists($tableName, $columnName)) . '');
                        }
                } // END - foreach
        } elseif ((getTableType() == 'InnoDB') && (isInString('FULLTEXT', $sql))) {
                // Skip this query silently because InnoDB does not understand fulltext indexes
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,tableName=%s,hasZeroNums=%d,file=%s,line=%s", $sql, $tableName, intval((is_bool($result)) ? 0 : isSqlTableColumnFound($columnName)), $F, $L));
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Skipped FULLTEXT: sql=%s,tableName=%s,hasZeroNums=%d,file=%s,line=%s", $sql, $tableName, intval((is_bool($result)) ? 0 : ifSqlColumnExists($columnName)), $F, $L));
        } elseif ($isAlterIndex === true) {
                // And column name as well without backticks
                $keyName = str_replace('`', '', $tableArray[5]);
@@ -603,7 +611,7 @@ function ifSqlTableExists ($tableName) {
 }
 
 // Is a table column there?
-function isSqlTableColumnFound ($tableName, $columnName) {
+function ifSqlColumnExists ($tableName, $columnName) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',columnName=' . $columnName . ' - ENTERED!');
        // Do we have cache?
        if (!isset($GLOBALS[__FUNCTION__][$tableName][$columnName])) {
@@ -612,7 +620,10 @@ function isSqlTableColumnFound ($tableName, $columnName) {
 
                // Get column information
                $result = SQL_QUERY_ESC("SHOW COLUMNS FROM `%s` LIKE '%s'",
-                       array($tableName, $columnName), __FUNCTION__, __LINE__);
+                       array(
+                               $tableName,
+                               $columnName
+                       ), __FUNCTION__, __LINE__);
 
                // Determine it
                $GLOBALS[__FUNCTION__][$tableName][$columnName] = (!SQL_HASZERONUMS($result));