Exemplo n.º 1
0
 function rss_query($query, $dieOnError = true, $preventRecursion = false)
 {
     $ret = $this->_db->query($query);
     if ($error = $this->rss_sql_error()) {
         $errorString = $this->rss_sql_error_message();
     }
     // if we got a missing table error, look for missing tables in the schema
     // and try to create them
     if ($error == 1146 && !$preventRecursion && $dieOnError) {
         require_once dirname(__FILE__) . '/../../init.php';
         rss_require('schema.php');
         checkSchema();
         return $this->rss_query($query, $dieOnError, true);
     } elseif ($error == 1054 && !$preventRecursion && $dieOnError) {
         if (preg_match("/^[^']+'([^']+)'.*\$/", $errorString, $matches)) {
             require_once dirname(__FILE__) . '/../../init.php';
             rss_require('schema.php');
             checkSchemaColumns($matches[1]);
             return $this->rss_query($query, $dieOnError, true);
         }
     }
     if ($error && $dieOnError) {
         die("<p>Failed to execute the SQL query <pre>{$query}</pre> </p>" . "<p>Error {$error}: {$errorString}</p>");
     }
     return $ret;
 }
Exemplo n.º 2
0
 function rss_query($query, $dieOnError = true, $preventRecursion = false)
 {
     //we use a wrapper to convert MySQL specific instruction to sqlite
     $result = false;
     $GLOBALS["sqlite_extented_error"] = "";
     $errorString = " (none) ";
     $this->debugLog("SQL BEFORE: {$query}");
     $query = $this->mysql2sqlite($query);
     if (is_array($query)) {
         $this->debugLog("SQL AFTER: " . implode("\n", $query));
     } else {
         $this->debugLog("SQL AFTER: {$query}");
     }
     if (is_string($query) && preg_match("/^alter table/is", $query)) {
         $queryparts = preg_split("/[\\s]+/", $query, 4, PREG_SPLIT_NO_EMPTY);
         $tablename = $queryparts[2];
         $alterdefs = $queryparts[3];
         if (strtolower($queryparts[1]) != 'table' || $queryparts[2] == '') {
             $error = 1;
             $errorString = 'near "' . $queryparts[0] . '": syntax error';
         } else {
             set_error_handler(array(&$this, 'rss_catch_error_handler'));
             $result = $this->alter_table($tablename, $alterdefs);
             restore_error_handler();
         }
     } else {
         if (is_array($query)) {
             //means that it's a SCHEMA creation so we process each query
             foreach ($query as $sql_query) {
                 set_error_handler(array(&$this, 'rss_catch_error_handler'));
                 $result = sqlite_query($this->db, $sql_query);
                 restore_error_handler();
                 if ($error = $this->rss_sql_error()) {
                     if ($error == 1 && preg_match("/DROP TABLE/is", $sql_query)) {
                         //not a real error to drop a table which do not exists
                         $error = 0;
                         continue;
                     }
                     break;
                 }
             }
         } else {
             set_error_handler(array(&$this, 'rss_catch_error_handler'));
             $result = sqlite_query($this->db, $query);
             restore_error_handler();
         }
         if ($error = $this->rss_sql_error()) {
             if ($error == 1 && is_string($query) && preg_match("/^\\s*DROP TABLE/is", $query)) {
                 //not a real error to drop a table which do not exists
                 $error = 0;
             } else {
                 $errorString = $this->rss_sql_error_message();
             }
         }
     }
     if ($error) {
         $this->debugLog("SQL EXEC ERR: {$error} - {$errorString}");
     } else {
         $this->debugLog("SQL EXEC OK");
     }
     if ($error == 1 && $dieOnError && !$preventRecursion) {
         if (preg_match("/no\\s+such\\s+table/is", $errorString)) {
             ob_start();
             require_once dirname(__FILE__) . '/../../init.php';
             require_once dirname(__FILE__) . '/../../schema.php';
             checkSchema();
             ob_clean();
             return $this->rss_query($query, $dieOnError, true);
         } else {
             if (preg_match("/(no\\s+such\\s+column\\s*:\\s*|no\\s+column\\s+named\\s+)(.+)/is", $errorString, $matches)) {
                 ob_start();
                 require_once dirname(__FILE__) . '/../../init.php';
                 require_once dirname(__FILE__) . '/../../schema.php';
                 checkSchemaColumns(trim($matches[2]));
                 ob_clean();
                 return $this->rss_query($query, $dieOnError, true);
             }
         }
     }
     if ($error && $dieOnError) {
         die("<p>Failed to execute the SQL query <pre>{$query}</pre> </p>" . "<p>Error {$error}: {$errorString}</p>");
     }
     return $result;
 }