Пример #1
0
 /**
  * @param string $type
  *   'BASE TABLE' or 'VIEW'.
  * @return array
  */
 public function getTables($type)
 {
     $pdo = \Civi\Test::pdo();
     // only consider real tables and not views
     $query = sprintf("SELECT table_name FROM INFORMATION_SCHEMA.TABLES\n        WHERE TABLE_SCHEMA = %s AND TABLE_TYPE = %s", $pdo->quote(\Civi\Test::dsn('database')), $pdo->quote($type));
     $tables = $pdo->query($query);
     $result = array();
     foreach ($tables as $table) {
         $result[] = $table['table_name'];
     }
     return $result;
 }
Пример #2
0
 /**
  * @param $newSignature
  */
 protected function setSavedSignature($newSignature)
 {
     $pdo = \Civi\Test::pdo();
     $query = sprintf('INSERT INTO %s.civitest_revs (name,rev) VALUES (%s,%s) ' . 'ON DUPLICATE KEY UPDATE rev = %s;', \Civi\Test::dsn('database'), $pdo->quote($this->name), $pdo->quote($newSignature), $pdo->quote($newSignature));
     if (\Civi\Test::execute($query) === FALSE) {
         throw new RuntimeException("Failed to flag schema version: {$query}");
     }
 }
Пример #3
0
 /**
  * Prepare and execute a batch of SQL statements.
  *
  * @param string $query
  * @return bool
  */
 public static function execute($query)
 {
     $pdo = \Civi\Test::pdo();
     $string = preg_replace("/^#[^\n]*\$/m", "\n", $query);
     $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
     $queries = preg_split('/;\\s*$/m', $string);
     foreach ($queries as $query) {
         $query = trim($query);
         if (!empty($query)) {
             $result = $pdo->query($query);
             if ($pdo->errorCode() == 0) {
                 continue;
             } else {
                 var_dump($result);
                 var_dump($pdo->errorInfo());
                 // die( "Cannot execute $query: " . $pdo->errorInfo() );
             }
         }
     }
     return TRUE;
 }