Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / vendor / drush / drush / src / Sql / SqlOracle.php
1 <?php
2
3 namespace Drush\Sql;
4
5 use Drush\Log\LogLevel;
6
7 class SqlOracle extends SqlBase
8 {
9
10     // The way you pass a sql file when issueing a query.
11     public $queryFile = '@';
12
13     public function command()
14     {
15         // use rlwrap if available for readline support
16         if ($handle = popen('rlwrap -v', 'r')) {
17             $command = 'rlwrap sqlplus';
18             pclose($handle);
19         } else {
20             $command = 'sqlplus';
21         }
22         return $command;
23     }
24
25     public function creds($hide_password = true)
26     {
27         return ' ' . $this->dbSpec['username'] . '/' . $this->dbSpec['password'] . ($this->dbSpec['host'] == 'USETNS' ? '@' . $this->dbSpec['database'] : '@//' . $this->dbSpec['host'] . ':' . ($db_spec['port'] ? $db_spec['port'] : '1521') . '/' . $this->dbSpec['database']);
28     }
29
30     public function createdbSql($dbname)
31     {
32         return drush_log("Unable to generate CREATE DATABASE sql for $dbname", LogLevel::ERROR);
33     }
34
35     // @todo $suffix = '.sql';
36     public function queryFormat($query)
37     {
38         // remove trailing semicolon from query if we have it
39         $query = preg_replace('/\;$/', '', $query);
40
41         // some sqlplus settings
42         $settings[] = "set TRIM ON";
43         $settings[] = "set FEEDBACK OFF";
44         $settings[] = "set UNDERLINE OFF";
45         $settings[] = "set PAGES 0";
46         $settings[] = "set PAGESIZE 50000";
47
48         // are we doing a describe ?
49         if (!preg_match('/^ *desc/i', $query)) {
50             $settings[] = "set LINESIZE 32767";
51         }
52
53         // are we doing a show tables ?
54         if (preg_match('/^ *show tables/i', $query)) {
55             $settings[] = "set HEADING OFF";
56             $query = "select object_name from user_objects where object_type='TABLE' order by object_name asc";
57         }
58
59         // create settings string
60         $sqlp_settings = implode("\n", $settings) . "\n";
61
62         // important for sqlplus to exit correctly
63         return "${sqlp_settings}${query};\nexit;\n";
64     }
65
66     public function listTables()
67     {
68         $return = $this->alwaysQuery("SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME NOT IN ('BLOBS','LONG_IDENTIFIERS')");
69         $tables = drush_shell_exec_output();
70         if (!empty($tables)) {
71             // Shift off the header of the column of data returned.
72             array_shift($tables);
73             return $tables;
74         }
75     }
76
77       // @todo $file is no longer provided. We are supposed to return bash that can be piped to gzip.
78       // Probably Oracle needs to override dump() entirely - http://stackoverflow.com/questions/2236615/oracle-can-imp-exp-go-to-stdin-stdout.
79     public function dumpCmd($table_selection)
80     {
81         $create_db = $this->getOption('create-db');
82         $exec = 'exp ' . $this->creds();
83         // Change variable '$file' by reference in order to get drush_log() to report.
84         if (!$file) {
85             $file = $this->dbSpec['username'] . '.dmp';
86         }
87         $exec .= ' file=' . $file;
88
89         if (!empty($tables)) {
90             $exec .= ' tables="(' . implode(',', $tables) . ')"';
91         }
92         $exec .= ' owner=' . $this->dbSpec['username'];
93         if ($option = $this->getOption('extra-dump', $this->queryExtra)) {
94             $exec .= " $option";
95         }
96         return [$exec, $file];
97     }
98 }