Code Monkey home page Code Monkey logo

sql-file-splitter's Introduction

SQL File Splitter Script

This script is designed to process large SQL files, extracting SQL commands, counting their occurrences, and writing them into separate files based on their types.

Prerequisites

  • Python 3.x installed on your system.

Usage

  1. Download the script:
  • Download the sql_file_splitter.py script from the repository.
  1. Prepare your SQL file:
  • Ensure you have a large SQL file that you want to process. The file should be in UTF-8 encoding.
  1. Modify script variables:
  • Modify the filePath variable in the script to specify the path to your input SQL file.
  • Modify the outputFolder variable to specify the path to the output folder where the generated SQL files will be saved.
  • If your input file is not encoded in UTF-8, you can change the encoding in the _extract_sql_file() method of the LargeFile class accordingly.
  1. Run the script:
  • Open a terminal or command prompt, navigate to the directory containing the script, and execute the following command:

    python sql_file_splitter.py
  1. Wait for processing to complete:
  • The script will begin processing the SQL file, extracting commands, counting their occurrences, and writing them into separate files. The processing time may vary depending on the size of the input file.
  1. Check output files:
  • Once the processing is complete, check the specified output directory (default: output_sql_files) for the generated SQL files.

Example

# Specify the path to your SQL file
filePath = 'input/export_clean.sql'

# Initialize LargeFile object
large_file = LargeFile(filePath)

# Measure execution time
start_time = time.time()

# Write SQL files based on command types
outputFolder = 'output_sql_files'
large_file.write_sql_file(outputFolder)

# Measure execution time
end_time = time.time()
print(f'Time taken: {end_time - start_time} seconds')

Note

  • Ensure that you have sufficient disk space available in the output directory, as the generated files may be large, especially for large input SQL files.
  • If your input file is not encoded in UTF-8, you can change the encoding in the _extract_sql_file() method of the LargeFile class by modifying the encoding parameter in the open() function call.
  • It's important to choose the correct encoding to accurately read the file content.
  • Additionally, the code can be modified to execute SQL commands directly on connected servers like MySQL or SQL Server. This would involve replacing or modifying the write_sql_file() method to execute the commands using appropriate database drivers or libraries.

sql-file-splitter's People

Contributors

dennx2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.