pastebin - collaborative debugging tool
nrubsig.kpaste.net RSS


mysql test generator
Posted by Anonymous on Mon 21st Jul 2025 19:21
raw | new post
modification of post by Anonymous (view diff)

  1. # mysql test generator
  2.  
  3. integer line_num=0
  4. typeset line
  5. typeset escaped_line
  6.  
  7. cat <<EOF
  8. SELECT VERSION();
  9.  
  10. DROP DATABASE alphabet_test4;
  11. CREATE DATABASE alphabet_test4;
  12. USE alphabet_test4;
  13.  
  14. CREATE TABLE file_data (
  15.     line_number INT PRIMARY KEY,
  16.     line_text TEXT
  17. ) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
  18. EOF
  19.  
  20. while IFS= read -r line ; do
  21.     (( line_num++ ))
  22.     # Escape single quotes in the line to prevent SQL injection issues
  23.     # This is a basic escape, for more complex data, consider prepared statements
  24.     escaped_line="${line//\'/\'\'}"
  25.  
  26.     # Insert the line number and text into the table
  27.     printf $'INSERT INTO file_data (line_number, line_text) VALUES (%d, \'%s\');\n' line_num "$escaped_line"
  28. done
  29.  
  30. # force rebuild, including punching holes
  31. printf 'OPTIMIZE TABLE file_data;'
  32.  
  33. print -u2 '#Done;\n#Verify with\nUSE alphabet_test4; SELECT * FROM file_data ORDER BY line_number;\n'
  34. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at