 |
SoftTree Technologies
Technical Support Forums
|
|
Author |
Message |
gemisigo
Joined: 11 Mar 2010 Posts: 2165
|
|
[11.5.362 Pro] - Formatting VALUES rule |
|
SA seems to have some trouble recognizing what should be considered to be part of the VALUES clause (or at least I have trouble explaining that to SA, that's still open for debate).
Here are the rules:
I separated the INSERT part from the VALUES part because if I joined them into a single rule, having an INSERT INTO ... SELECT statement instead of VALUES produced some weird results. Here is the one for the INSERT part.
 |
 |
INSERT ...(..., ...)
|
And VALUES has the following:
 |
 |
VALUES (..., ...)
,(..., ...);
|
Notice that the VALUES keyword is already indented so formatting the code below would produce the desired indentation of the VALUES keyword regarding the INSERT keyword
And here is the code to be formatted:
 |
 |
INSERT
IGNORE INTO `temp_article`(`code`, `article_id`, `name`)
VALUES ('F', '599908010012', 'this') ,('11', '599908010014', 'that') ,('12', '599908010018', 'whatever');
|
This would be the goal:
 |
 |
INSERT IGNORE INTO `temp_article`(`code`, `article_id`, `name`)
VALUES ('F', '599908010012', 'this')
,('11', '599908010014', 'that')
,('12','599908010018', 'whatever');
|
Instead, I get this:
 |
 |
INSERT IGNORE INTO `temp_article`(`code`, `article_id`, `name`)
VALUES ('F', '599908010012', 'this')
,('11'
,'599908010014'
,'that')
,('12'
,'599908010018'
,'whatever');
|
The first item in the row of values is formatting as expected but all the rest are just broken into separate lines at the first possible comma. At first, I thought that there was some interference, probably by the rule for parenthesis, but as it is set to this below, my "educated guess" was that really shouldn't matter. If anything at all, it should make the result more likely to resemble the expected goal. To err on the safe side I disabled that rule. It turned out my guess was right. It did not matter. Anyway, following the rule (disabled) for parenthesis:
 |
 |
(..., ... AND ... OR ...)
|
Now, if I only select/format the code with the parentheses, the result is what I wanted (well, except for the missing VALUES keyword). Check this short video here.
|
|
Fri Aug 13, 2021 1:28 pm |
|
 |
SysOp
Site Admin
Joined: 26 Nov 2006 Posts: 7948
|
|
|
|
I'm afraid you are stretching the limits of the pattern based matching and code formatting
The values referenced in the INSERT are like "('F', '599908010012', 'this')" which isn't like pairs of values below
 |
 |
VALUES (..., ...)
,(..., ...); |
Then there is also comma specific rule requiring leading commas in every line with everything else wrapped at the next comma occurrence. I bet that overwhelms the formatter causing it to chose something unexpected.
|
|
Fri Aug 13, 2021 3:43 pm |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|