Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

splitsql.py

From Randomness wiki
Revision as of 07:26, 17 September 2024 by Derg (talk | contribs) (Created page with " <syntaxhighlight lang="python"> cur = 'beginning' fi = open(cur + '.sql', 'wb') starts = b'CREATE DATABASE →‎!32312 IF NOT EXISTS: `' ends = b'` →‎!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci: ;' with open('beforereinstallalldbs.sql', 'rb') as f: for l in f: l = l.strip() if l.startswith(starts) and l.endswith(ends): cur = l[len(starts):-len(ends)].decode('utf-8') print(cur) fi.close() fi = open(cur + '.sql', 'wb')...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
cur = 'beginning'
fi = open(cur + '.sql', 'wb')
starts = b'CREATE DATABASE /*!32312 IF NOT EXISTS*/ `'
ends = b'` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */;'

with open('beforereinstallalldbs.sql', 'rb') as f:
  for l in f:
    l = l.strip()
    if l.startswith(starts) and l.endswith(ends):
      cur = l[len(starts):-len(ends)].decode('utf-8')
      print(cur)
      fi.close()
      fi = open(cur + '.sql', 'wb')
      with open('beginning.sql', 'rb') as fb:
        fi.write(fb.read())
        fi.write(b'\n')
    fi.write(l + b'\n')