]> git.mxchange.org Git - mailer.git/blobdiff - inc/sql-functions.php
mailer project continued:
[mailer.git] / inc / sql-functions.php
index a4bf3ee88d49b78264ad0eb70f6d571e24bb47d2..9982711f408a4783d574b449493c67ef4ef11d80 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -42,10 +42,11 @@ if (!defined('__SECURITY')) {
 
 // Init SQLs array
 function initSqls () {
-       setSqlsArray(array());
+       // Init generic array
+       setSqlsArray(array('generic' => array()));
 }
 
-// Checks wether the sqls array is initialized
+// Checks whether the sqls array is initialized
 function isSqlsInitialized () {
        return ((isset($GLOBALS['sqls'])) && (is_array($GLOBALS['sqls'])));
 }
@@ -69,7 +70,7 @@ function getSqls () {
 // Add an SQL to the list
 function addSql ($sql) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("sql=%s, count=%d", $sql, countSqls()));
-       $GLOBALS['sqls']['generic'][] = (string) $sql;
+       array_push($GLOBALS['sqls']['generic'], $sql);
 }
 
 // Merge SQLs together
@@ -112,7 +113,7 @@ function countSqls () {
        return $count;
 }
 
-// Checks wether the SQLs array is filled
+// Checks whether the SQLs array is filled
 function isSqlsValid () {
        //* DEBUG: */ debugOutput(__FUNCTION__ . ':' . intval(isSqlsInitialized()) . '/' . countSqls() . '/' . getCurrentExtensionName());
        return (
@@ -136,13 +137,16 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
                        continue;
                } // END - if
 
-               // Do we have a non-string (e.g. number, NULL, NOW() or back-tick at the beginning?
+               // Do we have a non-string (e.g. number, NULL, SQL function or back-tick at the beginning?
                if (is_null($multiDimId)) {
                        // Handle one-dimensional data
                        if (is_null($value)) {
                                // NULL detected
                                $SQL .= '`' . $entry . '`=NULL,';
-                       } elseif (('' . bigintval($value, true, false) . '' == '' . $value . '') || ($value == 'NOW()') || (substr($value, 0, 1) == '`'))  {
+                       } elseif ((substr($value, -2, 2) == '()') || (substr($value, 0, 1) == '`')) {
+                               // SQL function needs no ticks (')
+                               $SQL .= '`' . $entry . '`=' . SQL_ESCAPE($value) . ',';
+                       } elseif ('' . bigintval($value, true, false) . '' == '' . $value . '')  {
                                // No need for ticks (')
                                $SQL .= '`' . $entry . '`=' . $value . ',';
                        } else {
@@ -154,7 +158,10 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
                        if (is_null($value[$multiDimId])) {
                                // NULL detected
                                $SQL .= '`' . $entry . '`=NULL,';
-                       } elseif (('' . bigintval($value[$multiDimId], true, false) . '' == '' . $value[$multiDimId] . '') || ($value[$multiDimId] == 'NOW()') || (substr($value[$multiDimId], 0, 1) == '`'))  {
+                       } elseif ((substr($value[$multiDimId], -2, 2) == '()') || (substr($value[$multiDimId], 0, 1) == '`')) {
+                               // SQL function needs no ticks (')
+                               $SQL .= '`' . $entry . '`=' . SQL_ESCAPE($value[$multiDimId]) . ',';
+                       } elseif (('' . bigintval($value[$multiDimId], true, false) . '' == '' . $value[$multiDimId] . ''))  {
                                // No need for ticks (')
                                $SQL .= '`' . $entry . '`=' . $value[$multiDimId] . ',';
                        } else {
@@ -183,12 +190,15 @@ function getInsertSqlFromArray ($array, $tableName) {
        // Walk through all entries
        foreach (postRequestArray() as $key => $value) {
                // Log debug message
-               /DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',key=' . $key . ',value=' . $value);
+               //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'tableName=' . $tableName . ',key=' . $key . ',value=' . $value);
 
                // Add all entries
                if (is_null($value)) {
                        // Add NULL
                        $SQL .= 'NULL,';
+               } elseif (substr($value, -2, 2) == '()') {
+                       // SQL function needs no ticks (')
+                       $SQL .= SQL_ESCAPE($value) . ',';
                } elseif ('' . bigintval($value, true, false) . '' == '' . $value . '') {
                        // Number detected, no need for ticks (')
                        $SQL .= bigintval($value) . ',';
@@ -197,7 +207,7 @@ function getInsertSqlFromArray ($array, $tableName) {
                        $SQL .= sprintf('%01.5f', $value);
                } else {
                        // Everything else might be a string, so add ticks around it
-                       $SQL .= "'" . SQL_ESCAPE($value) . "',";
+                       $SQL .= chr(39) . SQL_ESCAPE($value) . chr(39) . ',';
                }
        } // END - foreach