Bug #21343
closedDatabase Analyser does't undestand comments in sql file
Added by Vladimir Podkovanov about 15 years ago. Updated about 8 years ago.
0%
Description
If .sql file in an extension use any comments (# or /* */ does't matter) it ruins Database Analyser / Compare mode for that file - wrong Add, Changing, Drop fields and tables are proposed then.
Extension manager acts as supposed and there is no wrong suggestion on table updates for sql files with comments.
It affects 4.2 as well 4.2 branches.
(issue imported from #M12319)
Updated by Vladimir Podkovanov about 15 years ago
typo: "It affects 4.2 as well 4.2 branches" -> "It affects 4.2 as well 4.3 branches. "
Updated by Ernesto Baschny about 15 years ago
Start-of-line comments are handled correctly ("#"). Other comments are not really supported, also not after-a-line-comments.
#- no problem with this comment
#
CREATE TABLE user_test (
uid int(11) NOT NULL auto_increment,
pid int(11) DEFAULT '0' NOT NULL, # no problem here too
tstamp int(11) DEFAULT '0' NOT NULL, # this is a problem
)
So extensions having such non-supported stuff in their ext_tables.sql should be corrected, as this has never worked before.
If you think it is worth to make a new feature allowing more flexible comments in the sql file, you could provide a patch?
Updated by Vladimir Podkovanov about 15 years ago
Hmm, so far I isolated bug triggering to this sql definition
CREATE TABLE tx_extkey_table1 (
uid int(11) unsigned NOT NULL auto_increment,
pid int(11) unsigned DEFAULT '0' NOT NULL,
# comment;
PRIMARY KEY (uid),
);
CREATE TABLE tx_extkey_table2 (
uid int(11) unsigned NOT NULL auto_increment,
pid int(11) unsigned DEFAULT '0' NOT NULL,
PRIMARY KEY (uid),
);
Note semicolon in comment - it is important for trigering bug,
also tables should be from real extension - does not work with user_ key, probably it depends on TCA being in place for those tables.
For that definition in Install tool I'm getting this suggestion:
ALTER TABLE tx_extkey_table1 ADD CREATE TABLE tx_extkey_table2 (;
that is obviously incorrect
Updated by Ernesto Baschny about 15 years ago
Ok, I unterstand now.
The parser from the install tool is pretty "dumb" when it comes to comments. It will get handed over an array of "SQL statements", which have been just split by semicolon in the original file: so if you have a semicolon in a comment you indeed have this problem.
So the bug report is justified and should be fixed. But someone needs to provide a patch (scratch the itch...).
Updated by Karsten Dambekalns about 15 years ago
Actually, when coming from SQL the only comment allowed starts with two dashes, so
-- this is a comment in SQL
Just as a note :)
Updated by Vladimir Podkovanov almost 15 years ago
from MySQL manual:
1.7.5.6. '--' as the Start of a Comment
Standard SQL uses the C syntax /* this is a comment */ for comments, and MySQL Server supports this syntax as well. MySQL also support extensions to this syntax that allow MySQL-specific SQL to be embedded in the comment, as described in Section 8.5, “Comment Syntax”.
Standard SQL uses “--” as a start-comment sequence. MySQL Server uses “#” as the start comment character. MySQL Server 3.23.3 and up also supports a variant of the “--” comment style. That is, the “--” start-comment sequence must be followed by a space (or by a control character such as a newline). The space is required to prevent problems with automatically generated SQL queries that use constructs such as the following, where we automatically insert the value of the payment for payment:
UPDATE account SET credit=credit-payment
Consider about what happens if payment has a negative value such as -1:
UPDATE account SET credit=credit--1
credit--1 is a legal expression in SQL, but “--” is interpreted as the start of a comment, part of the expression is discarded. The result is a statement that has a completely different meaning than intended:
UPDATE account SET credit=credit
The statement produces no change in value at all. This illustrates that allowing comments to start with “--” can have serious consequences.
Using our implementation requires a space following the “--” in order for it to be recognized as a start-comment sequence in MySQL Server 3.23.3 and newer. Therefore, credit--1 is safe to use.
Another safe feature is that the mysql command-line client ignores lines that start with “--”.
Updated by Alexander Opitz over 11 years ago
- Status changed from Accepted to Needs Feedback
- Target version deleted (
0)
The issue is very old, does this issue exists in newer versions of TYPO3 CMS (4.5 or 6.1)?
Updated by Alexander Opitz about 11 years ago
- Status changed from Needs Feedback to Closed
- Is Regression set to No
No feedback for over 90 days.
Updated by Ernesto Baschny about 11 years ago
- Category set to Install Tool
- Status changed from Closed to Accepted
No feedback doesn't mean it is fixed. I guess this is still unfixed. Why not leave it open? Maybe someone stumbles over this and "scratches his itch" and want to work on a solution...
Updated by Morton Jonuschat about 8 years ago
- Status changed from Accepted to Closed
- Target version deleted (
8 LTS)
I've tried to support it with the rewrite of the Schema Migrator in TYPO 8.4, IMHO there is no way to support this in a reasonable fashion without major side effects for the time being.
As there haven't been any other reports about this, there is an easy workaround (put the comment on the line above or below, starting with either #* or *-- and it hasn't scratched anybodies itch in the last 7 years I'll close it.