Python Forum
Regular Expression search to comment lines of code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Regular Expression search to comment lines of code
#1
Hello!

I'm hoping you guys can help me with a thorny issue I'm having.
I'm a beginner, not having touched Python since University 12 years ago :-)

I think this may be extremely easy for you guys, any tips you can provide would help greatly!

At a high level- I have a set of Oracle SQL DDL scripts that are generating errors because they have statements setting fields to be 'Not Null' because they are already not null...

Here's what the error looks like:

Error starting at line : 159 File 'XXX.sql'
In command -
ALTER TABLE "TABLE" MODIFY ("PK" NOT NULL ENABLE)
Error report -
ORA-01442: column to be modified to NOT NULL is already NOT NULL
01442. 00000 - "column to be modified to NOT NULL is already NOT NULL"
*Cause:
*Action:

What I want to do is write a simple script with two parts- one has a regular expression search that takes 'TABLE' and 'PK' from this error log and writes to a separate file using a regular expression search- perhaps using re.split(). Since this is an error log, a regular expression search for the active 'ALTER TABLE' line would suffice.

Then, I want to read this file and add line comments.. '--' to the beginning if each line in the original DDL script (A different file) that adds the erroneous constraints:
ALTER TABLE "TABLE" MODIFY ("PK" NOT NULL ENABLE)
~becomes~
-- ALTER TABLE "TABLE" MODIFY ("PK" NOT NULL ENABLE)

The things I don't understand:
How to load the key terms into variables with the regular expression search
How to add a comment before a line containing a regular expression search using terms parsed from the original file.

Anything that can help would be greatly appreciated.

Thanks Everyone!
Reply


Messages In This Thread
Regular Expression search to comment lines of code - by Gman2233 - Sep-06-2022, 09:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to add multi-line comment section? Winfried 1 210 Mar-24-2024, 04:34 PM
Last Post: deanhystad
  data validation with specific regular expression shaheen07 0 341 Jan-12-2024, 07:56 AM
Last Post: shaheen07
Question remove all comment ? SpongeB0B 7 1,353 Oct-27-2023, 05:40 PM
Last Post: deanhystad
  Is the following code returning a generator expression? quazirfan 8 1,632 Apr-11-2023, 11:44 PM
Last Post: quazirfan
  List Creation and Position of Continue Statement In Regular Expression Code new_coder_231013 3 1,673 Jun-15-2022, 12:00 PM
Last Post: new_coder_231013
  Regex Expression With Code Query In Pandas eddywinch82 8 2,343 Apr-13-2022, 09:12 AM
Last Post: snippsat
  Need help with my code (regular expression) shailc 5 1,940 Apr-04-2022, 07:34 PM
Last Post: shailc
  Regular Expression for matching words xinyulon 1 2,178 Mar-09-2022, 10:34 PM
Last Post: snippsat
  I want to simplify this python code into fewer lines, it's about string mandaxyz 5 2,131 Jan-15-2022, 01:28 PM
Last Post: mandaxyz
  regular expression question Skaperen 4 2,505 Aug-23-2021, 06:01 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020