Project

General

Profile

Actions

Bug #97844

closed

SqlReader-Class does not recognize multi line comments in a sql file

Added by Peter Linzenkirchner over 2 years ago. Updated 5 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2022-07-02
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Try the following:

It works when the file contains only the following comment styles:

# single line comment
-- single line comment

It does not work with comment styles like this:

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

/*!40000 ALTER TABLE `tx_mytable` DISABLE KEYS */;

In this case every line after the first appearence of /* is dropped. The reason lies in these code:

sysext/core/Classes/Database/Schema/SqlReader.php, line 99 - 112:

  // recognizes the beginning of a multiline comment
  if (strpos($lineContent, '/*') === 0 && substr($lineContent, -2) !== '*/') {
    $isInMultilineComment = true;
  }
  // should recognize the ending of a mulitline comment but doesn't because 
  // the */ is not on expected position -2. Perhaps it would be sufficent to ask
  // if */ is anywhere in the line: strpos($lineContent, '*/') !== 0
  if (substr($lineContent, -2) === '*/') {
    $isInMultilineComment = false;
  }

In my tries it was sufficient to change the line

(substr($lineContent, -2) === '*/') {

to

(strpos($lineContent, '*/') !== 0) {
Actions

Also available in: Atom PDF