X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fsql-functions.php;h=9fe8259c59a29929bda8830dbdbe411f687fcabe;hb=ffd85cab81b4d31bbb8e9b52c1d9a84108d14434;hp=671a8667445390d641f61131c58e8ec28ee93023;hpb=88c922353cc353fe148e21c7d27d7c0076d6fdda;p=mailer.git diff --git a/inc/sql-functions.php b/inc/sql-functions.php index 671a866744..9fe8259c59 100644 --- a/inc/sql-functions.php +++ b/inc/sql-functions.php @@ -149,6 +149,9 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e } elseif ('' . bigintval($value, TRUE, FALSE) . '' == '' . $value . '') { // No need for ticks (') $SQL .= '`' . $entry . '`=' . $value . ','; + } elseif ('' . (float) $value . '' == '' . $value . '') { + // Float number detected + $SQL .= '`' . $entry . '`=' . sprintf(getConfig('FLOAT_MASK'), $value) . ','; } else { // Strings need ticks (') around them $SQL .= '`' . $entry . "`='" . SQL_ESCAPE($value) . "',"; @@ -164,6 +167,9 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e } elseif (('' . bigintval($value[$multiDimId], TRUE, FALSE) . '' == '' . $value[$multiDimId] . '')) { // No need for ticks (') $SQL .= '`' . $entry . '`=' . $value[$multiDimId] . ','; + } elseif ('' . (float) $value[$multiDimId] . '' == '' . $value[$multiDimId] . '') { + // Float number detected + $SQL .= '`' . $entry . '`=' . sprintf(getConfig('FLOAT_MASK'), $value[$multiDimId]) . ','; } else { // Strings need ticks (') around them $SQL .= '`' . $entry . "`='" . SQL_ESCAPE($value[$multiDimId]) . "',"; @@ -181,14 +187,10 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e // "Getter" for an "INSERT INTO" SQL query function getInsertSqlFromArray ($array, $tableName) { // Init SQL - $SQL = 'INSERT INTO -`{?_MYSQL_PREFIX?}_' . $tableName . '` -( -`' . implode('`, `', array_keys(postRequestArray())) . '` -) VALUES ('; + $SQL = 'INSERT INTO `{?_MYSQL_PREFIX?}_' . $tableName . '` (`' . implode('`, `', array_keys($array)) . '`) VALUES ('; // Walk through all entries - foreach (postRequestArray() as $key => $value) { + foreach ($array as $key => $value) { // Log debug message //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',key=' . $key . ',value=' . $value); @@ -204,7 +206,7 @@ function getInsertSqlFromArray ($array, $tableName) { $SQL .= bigintval($value) . ','; } elseif ('' . (float) $value . '' == '' . $value . '') { // Float number detected - $SQL .= sprintf('%01.5f', $value); + $SQL .= sprintf(getConfig('FLOAT_MASK'), $value) . ','; } else { // Everything else might be a string, so add ticks around it $SQL .= chr(39) . SQL_ESCAPE($value) . chr(39) . ','; @@ -215,21 +217,32 @@ function getInsertSqlFromArray ($array, $tableName) { $SQL = substr($SQL, 0, -1) . ')'; // Return SQL query + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',sql=' . $SQL); return $SQL; } +// Function to unset __is_sql_link_up +function unsetSqlLinkUp ($F, $L) { + // Unset it + //* DEBUG: */ logDebugMessage($F, $L, __FUNCTION__ . ': Called!'); + SQL_SET_LINK($F, $L, NULL); +} + // Initializes the SQL link by bringing it up if set function initSqlLink () { + // "Unset" the link + unsetSqlLinkUp(__FUNCTION__, __LINE__); + // Do this only if link is down assert(!SQL_IS_LINK_UP()); // Is the configuration data set? if ((!empty($GLOBALS['mysql']['host'])) && (!empty($GLOBALS['mysql']['login'])) && (!empty($GLOBALS['mysql']['dbase']))) { // Remove cache - unset($GLOBALS['is_sql_link_up']); + unsetSqlLinkUp(__FUNCTION__, __LINE__); // Connect to DB - SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__); + SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FUNCTION__, __LINE__); // Is the link valid? if (SQL_IS_LINK_UP()) { @@ -237,7 +250,7 @@ function initSqlLink () { enableExitOnError(); // Is it a valid resource? - if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === TRUE) { + if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FUNCTION__, __LINE__) === TRUE) { // Set database name (required for ext-optimize and ifSqlTableExists()) setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']); @@ -248,15 +261,15 @@ function initSqlLink () { loadIncludeOnce('inc/load_cache.php'); } else { // Wrong database? - reportBug(__FILE__, __LINE__, 'Wrong database selected.'); + reportBug(__FUNCTION__, __LINE__, 'Wrong database selected.'); } } else { // No link to database! - reportBug(__FILE__, __LINE__, 'Database link is not yet up.'); + reportBug(__FUNCTION__, __LINE__, 'Database link is not yet up.'); } } else { // Maybe you forgot to enter your database login? - reportBug(__FILE__, __LINE__, 'Database login is missing.'); + reportBug(__FUNCTION__, __LINE__, 'Database login is missing.'); } } @@ -268,7 +281,7 @@ function importSqlDump ($path, $dumpName, $sqlPool) { // Is the file readable? if (!isFileReadable($FQFN)) { // Not found, which is bad - reportBug(__FILE__, __LINE__, sprintf("SQL dump %s/%s.sql is not readable.", $path, $dumpName)); + reportBug(__FUNCTION__, __LINE__, sprintf("SQL dump %s/%s.sql is not readable.", $path, $dumpName)); } // END - if // Then read it @@ -283,7 +296,7 @@ function SQL_QUERY_ESC ($sqlString, $data, $F, $L, $run = TRUE, $strip = TRUE, $ // Link is there? 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!'); + //* DEBUG: */ logDebugMessage($F, $L, 'SQL_IS_LINK_UP()=' . intval(SQL_IS_LINK_UP()) . ',data[]=' . gettype($data) . ',sqlString=' . $sqlString . ': ABORTING!'); return FALSE; } // END - if @@ -473,43 +486,49 @@ function SQL_GET_LINK () { $link = NULL; // Is it in the globals? - if (isset($GLOBALS['sql_link'])) { + if (isset($GLOBALS['__sql_link'])) { // Then take it - $link = $GLOBALS['sql_link']; + $link = $GLOBALS['__sql_link']; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'link[]=' . gettype($link) . ' - FROM GLOBALS!'); } // END - if // Return it + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'link[]=' . gettype($link) . ' - EXIT!'); return $link; } // Setter for link -function SQL_SET_LINK ($link) { +function SQL_SET_LINK ($F, $L, $link) { + //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'link[]=' . gettype($link) . ' - ENTERED!'); // Is this a resource or null? if ((ifFatalErrorsDetected()) && (isInstallationPhase())) { // This may happen in installation phase + //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, 'Some fatal errors detected in installation phase.'); return; } elseif ((!is_resource($link)) && (!is_null($link))) { // This should never happen! - reportBug(__FUNCTION__, __LINE__, sprintf("Type of link is not resource or null, type=%s", gettype($link))); + reportBug($F . ':' . __FUNCTION__, $L . ':' . __LINE__, sprintf("Type of link is not resource or null, type=%s", gettype($link))); } // END - if // Set it - $GLOBALS['sql_link'] = $link; + $GLOBALS['__sql_link'] = $link; // Re-init cache - $GLOBALS['is_sql_link_up'] = is_resource($link); + $GLOBALS['__is_sql_link_up'] = is_resource($link); + //* DEBUG: */ logDebugMessage($F . ':' . __FUNCTION__, $L . ':' . __LINE__, '__is_sql_link_up=' . intval($GLOBALS['__is_sql_link_up']) . ' - EXIT!'); } // Checks if the link is up function SQL_IS_LINK_UP () { // Is there cached this? - if (!isset($GLOBALS['is_sql_link_up'])) { - // Determine it - $GLOBALS['is_sql_link_up'] = is_resource(SQL_GET_LINK()); + if (!isset($GLOBALS['__is_sql_link_up'])) { + // Something bad went wrong + reportBug(__FUNCTION__, __LINE__, 'Called before SQL_SET_LINK() was called!'); } // END - if // Return the result - return $GLOBALS['is_sql_link_up']; + //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '__is_sql_link_up=' . intval($GLOBALS['__is_sql_link_up']) . ' - EXIT!'); + return $GLOBALS['__is_sql_link_up']; } // Wrapper function to make code more readable @@ -568,7 +587,7 @@ function ifSqlTableExists ($tableName) { if (!isset($GLOBALS[__FUNCTION__][$tableName])) { // Check if the table is there $result = SQL_QUERY_ESC("SHOW TABLES FROM `{?__DB_NAME?}` WHERE `Tables_in_{?__DB_NAME?}`='{?_MYSQL_PREFIX?}_%s'", - array($tableName), __FILE__, __LINE__); + array($tableName), __FUNCTION__, __LINE__); // Is a link there? if (!is_resource($result)) {