public function Sqloracle::query_format

8.0.x Sqloracle.php public Sqloracle::query_format($query)
7.x Sqloracle.php public Sqloracle::query_format($query)
master Sqloracle.php public Sqloracle::query_format($query)

Overrides SqlBase::query_format

File

lib/Drush/Sql/Sqloracle.php, line 33

Namespace

Drush\Sql

Class

Sqloracle

Code

public function query_format($query) {
  // remove trailing semicolon from query if we have it
  $query = preg_replace('/\;$/', '', $query);

  // some sqlplus settings
  $settings[] = "set TRIM ON";
  $settings[] = "set FEEDBACK OFF";
  $settings[] = "set UNDERLINE OFF";
  $settings[] = "set PAGES 0";
  $settings[] = "set PAGESIZE 50000";

  // are we doing a describe ?
  if (!preg_match('/^ *desc/i', $query)) {
    $settings[] = "set LINESIZE 32767";
  }

  // are we doing a show tables ?
  if (preg_match('/^ *show tables/i', $query)) {
    $settings[] = "set HEADING OFF";
    $query = "select object_name from user_objects where object_type='TABLE' order by object_name asc";
  }

  // create settings string
  $sqlp_settings = implode("\n", $settings) . "\n";

  // important for sqlplus to exit correctly
  return "${sqlp_settings}${query};\nexit;\n";
}