I was on 16.00.0.1032 when I read Not found search string of a replace exits macro with UE 16.00.0.1038, fixed with 16.00.0.1040.
I was having problems with a macro skipping commands if a Find/Replace found no entries. I upgraded to 16.00.0.1040 but still see the same behavior.
I'm using Perl Regexp and have the following construct in a SQL formatting macro.
I wrote the macro originally against a SQL file that contained the "ON dbo." and "WITH FILLFACTOR" clauses. In that file, all three replaces work just fine.
I then ran it against a file without the fillfactor clause, and the third find/replace ("SET NOCOUNT") did not occur.
If I alter the file so that the "ON dbo." fails to find a match, the fillfactor Find/Replace no longer works but the "SET NOCOUNT" replace now works.
Even better, if I modify the file such that the "dbo" and "FILLFACTOR" replaces do not find a match, the "NOCOUNT" replace works.
In all of this, macro commands that follow the above commands DO execute, so I know that the macro continues after any of the finds fail.
Near as I can tell, a failed Find/Replace is corrupting something inside of UE. Another Find or Find/Replace resets this "something", at the cost of its own functionality. To test this, as a work-around I modified the code as shown below:
The extra Finds are always successful, since they look for any character starting at the top of the file. Since they work, they reset the internal problem and allow the other finds to properly succeed or fail based on the file contents.
I was having problems with a macro skipping commands if a Find/Replace found no entries. I upgraded to 16.00.0.1040 but still see the same behavior.
I'm using Perl Regexp and have the following construct in a SQL formatting macro.
Code: Select all
InsertMode
ColumnModeOff
HexOff
PerlReOn
(other commands here)
Top
Find RegExp " ON dbo\."
Replace "\r\n ON dbo."
Top
Find RegExp " WITH FILLFACTOR"
Replace "\r\n WITH FILLFACTOR"
Top
Find RegExp "(CREATE.*INDEX )"
Replace "SET NOCOUNT ON;\r\nIF (SELECT INDEXPROPERTY(OBJECT_ID('~1'), '~2', 'IndexID') IS NULL)\r\n $1"
(other commands here)
Code: Select all
-- The macro always works on this line...
CREATE INDEX ix_name ON dbo.tablename (field1, field2) WITH FILLFACTOR = 100;
-- ... turning it into this code block (this is what it should look like).
SET NOCOUNT ON;
IF (SELECT INDEXPROPERTY(OBJECT_ID('~1'), '~2', 'IndexID') IS NULL)
CREATE INDEX ix_name
ON dbo.tablename (field1, field2)
WITH FILLFACTOR = 100;
Code: Select all
-- This line...
CREATE INDEX ix_name ON dbo.tablename (field1, field2);
-- ... becomes this code block (note the missing SET NOCOUNT - it should be there!).
CREATE INDEX ix_name
ON dbo.tablename (field1, field2);
Code: Select all
-- This line...
CREATE INDEX ix_name ON tablename (field1, field2) WITH FILLFACTOR = 100;
-- ... becomes this code block (note that the WITH FILLFACTOR is not on its own line).
SET NOCOUNT ON;
IF (SELECT INDEXPROPERTY(OBJECT_ID('~1'), '~2', 'IndexID') IS NULL)
CREATE INDEX ix_name ON tablename (field1, field2) WITH FILLFACTOR = 100;
Code: Select all
-- This line...
CREATE INDEX ix_name ON tablename (field1, field2);
-- ... becomes this code block (technically correct, but why does it work now when it didn't above?).
SET NOCOUNT ON;
IF (SELECT INDEXPROPERTY(OBJECT_ID('~1'), '~2', 'IndexID') IS NULL)
CREATE INDEX ix_name ON tablename (field1, field2);
Near as I can tell, a failed Find/Replace is corrupting something inside of UE. Another Find or Find/Replace resets this "something", at the cost of its own functionality. To test this, as a work-around I modified the code as shown below:
Code: Select all
Top
Find RegExp "."
Top
Find RegExp " ON dbo\."
Replace "\r\n ON dbo."
Top
Find RegExp "."
Top
Find RegExp " WITH FILLFACTOR"
Replace "\r\n WITH FILLFACTOR"
Top
Find RegExp "."
Top
Find RegExp "(CREATE.*INDEX )"
Replace "SET NOCOUNT ON;\r\nIF (SELECT INDEXPROPERTY(OBJECT_ID('~1'), '~2', 'IndexID') IS NULL)\r\n $1"