]> git.mxchange.org Git - mailer.git/blobdiff - inc/sql-functions.php
Updated propset.sh, fixed all SVN properties
[mailer.git] / inc / sql-functions.php
index 9982711f408a4783d574b449493c67ef4ef11d80..e61f3938041f1fbd57f12cc4327744f1167fe54e 100644 (file)
@@ -137,7 +137,7 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
                        continue;
                } // END - if
 
-               // Do we have a non-string (e.g. number, NULL, SQL function or back-tick at the beginning?
+               // Is there 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)) {
@@ -146,7 +146,7 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
                        } 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 . '')  {
+                       } elseif ('' . bigintval($value, TRUE, FALSE) . '' == '' . $value . '')  {
                                // No need for ticks (')
                                $SQL .= '`' . $entry . '`=' . $value . ',';
                        } else {
@@ -161,7 +161,7 @@ function getUpdateSqlFromArray ($array, $tableName, $whereColumn, $whereData, $e
                        } 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] . ''))  {
+                       } elseif (('' . bigintval($value[$multiDimId], TRUE, FALSE) . '' == '' . $value[$multiDimId] . ''))  {
                                // No need for ticks (')
                                $SQL .= '`' . $entry . '`=' . $value[$multiDimId] . ',';
                        } else {
@@ -184,7 +184,7 @@ function getInsertSqlFromArray ($array, $tableName) {
        $SQL = 'INSERT INTO
 `{?_MYSQL_PREFIX?}_' . $tableName . '`
 (
-`' . implode('`,`', array_keys(postRequestArray())) . '`
+`' . implode('`, `', array_keys(postRequestArray())) . '`
 ) VALUES (';
 
        // Walk through all entries
@@ -199,7 +199,7 @@ function getInsertSqlFromArray ($array, $tableName) {
                } elseif (substr($value, -2, 2) == '()') {
                        // SQL function needs no ticks (')
                        $SQL .= SQL_ESCAPE($value) . ',';
-               } elseif ('' . bigintval($value, true, false) . '' == '' . $value . '') {
+               } elseif ('' . bigintval($value, TRUE, FALSE) . '' == '' . $value . '') {
                        // Number detected, no need for ticks (')
                        $SQL .= bigintval($value) . ',';
                } elseif ('' . (float) $value . '' == '' . $value . '') {
@@ -218,5 +218,65 @@ function getInsertSqlFromArray ($array, $tableName) {
        return $SQL;
 }
 
+// Initializes the SQL link by bringing it up if set
+function initSqlLink () {
+       // 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']);
+
+               // Connect to DB
+               SQL_CONNECT($GLOBALS['mysql']['host'], $GLOBALS['mysql']['login'], $GLOBALS['mysql']['password'], __FILE__, __LINE__);
+
+               // Is the link valid?
+               if (SQL_IS_LINK_UP()) {
+                       // Enable exit on error
+                       enableExitOnError();
+
+                       // Is it a valid resource?
+                       if (SQL_SELECT_DB($GLOBALS['mysql']['dbase'], __FILE__, __LINE__) === TRUE) {
+                               // Set database name (required for ext-optimize and ifSqlTableExists())
+                               setConfigEntry('__DB_NAME', $GLOBALS['mysql']['dbase']);
+
+                               // Remove MySQL array from namespace
+                               unset($GLOBALS['mysql']);
+
+                               // Load cache
+                               loadIncludeOnce('inc/load_cache.php');
+                       } else {
+                               // Wrong database?
+                               reportBug(__FILE__, __LINE__, 'Wrong database selected.');
+                       }
+               } else {
+                       // No link to database!
+                       reportBug(__FILE__, __LINE__, 'Database link is not yet up.');
+               }
+       } else {
+               // Maybe you forgot to enter your database login?
+               reportBug(__FILE__, __LINE__, 'Database login is missing.');
+       }
+}
+
+// Imports given SQL dump from given (relative) path and adds them to $sqlPool
+function importSqlDump ($path, $dumpName, $sqlPool) {
+       // Construct FQFN
+       $FQFN = getPath() . $path . '/' . $dumpName . '.sql';
+
+       // 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));
+       } // END - if
+
+       // Then read it
+       $fileContent = readSqlDump($FQFN);
+
+       // Merge it with existing SQL statements
+       mergeSqls(explode(";\n", $fileContent), $sqlPool);
+}
+
 // [EOF]
 ?>