Sqloracle.php

  1. 8.0.x lib/Drush/Sql/Sqloracle.php
  2. 7.x lib/Drush/Sql/Sqloracle.php
  3. master lib/Drush/Sql/Sqloracle.php

Namespace

Drush\Sql

Classes

Namesort descending Description
Sqloracle

File

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