You are here

protected function GdprDumpGdprSqlDump::createCloneQueryString in General Data Protection Regulation 7

Creates a query string for cloning.

1 call to GdprDumpGdprSqlDump::createCloneQueryString()
GdprDumpGdprSqlDump::createTableClones in modules/gdpr_dump/inc/GdprDumpGdprSqlDump.inc
Creates table clones according to the config.

File

modules/gdpr_dump/inc/GdprDumpGdprSqlDump.inc, line 117

Class

GdprDumpGdprSqlDump
Class GdprDumpGdprSqlDump.

Code

protected function createCloneQueryString($originalTable) {
  if (\array_key_exists($originalTable, $this->skipTables)) {

    // No need to clone tables that are excluded.
    return NULL;
  }
  $clonedTable = self::GDPR_TABLE_PREFIX . $originalTable;
  switch ($this->driver) {
    case 'mysql':
      return "CREATE TABLE IF NOT EXISTS `{$clonedTable}` LIKE `{$originalTable}`;";

    /* @todo
     * - These seem to be the same.
     * - Test both.
     */
    case 'pgsql':
    case 'sqlite':

      // Maybe get the original SQL of the table and apply that:
      // SELECT sql FROM sqlite_master WHERE type='table' AND name='mytable'.
      return "CREATE TABLE IF NOT EXISTS `{$clonedTable}` AS SELECT * FROM `{$originalTable}` WHERE 1=2;";

    // These require a contrib module.
    case 'oracle':

      // @see: https://www.drupal.org/project/oracle
      break;
    case 'sqlsrv':

      // @see: https://www.drupal.org/project/sqlsrv
      break;
  }
  throw new SqlException("Unsupported database driver detected, can't clone table {$originalTable} for GDPR.");
}