<commit_before>#!/usr/bin/python

# chmod +x this file for this syntax:
# ./run_sql.py [dbname.db] [sqlfile_n.sql]...
# Otherwise,
# python run_sql.py [dbname.db] [sqlfile_n.sql]...

import sqlite3
import sys
import os

# Hold constant variables
DBS_DIR = 'dbs/'
SQL_DIR = 'sql/'
DEBUG = False

def main():
  # Checks
  checkArgsExist()
  cleanArgs()
  cleanDbs()

  db_path = isDbFile( sys.argv.pop( 0 ), True )

  # SQL Processing
  print '{:-^50}'.format( 'Processing SQL' )
  for sql_file_path in sys.argv:
    if( isSqlFile( sql_file_path ) ):
      processSqlFile( db_path, sql_file_path )

def processSqlFile( db_path, sql_file_path ):
  print '{:^50}'.format(
    'Processing ' +
    SQL_DIR + sql_file_path +
    ' to '  +
    DBS_DIR + db_path )

  qry_file = open( SQL_DIR + sql_file_path, 'r' ).read()
  con = sqlite3.connect( DBS_DIR + db_path )
  c   = con.cursor()
  queries = qry_file.split(';')

  for query in queries:
    try:
      c.execute( query )
    except sqlite3.OperationalError:
      print 'Check if db table exists, or for syntax errors'

  con.commit()
  c.close()
  con.close()<commit_msg>Prevent continued execution after error<commit_after>#!/usr/bin/python

# chmod +x this file for this syntax:
# ./run_sql.py [dbname.db] [sqlfile_n.sql]...
# Otherwise,
# python run_sql.py [dbname.db] [sqlfile_n.sql]...

import sqlite3
import sys
import os

# Hold constant variables
DBS_DIR = 'dbs/'
SQL_DIR = 'sql/'
DEBUG = False

def main():
  # Checks
  checkArgsExist()
  cleanArgs()
  cleanDbs()

  db_path = isDbFile( sys.argv.pop( 0 ), True )

  # SQL Processing
  print '{:-^50}'.format( 'Processing SQL' )
  for sql_file_path in sys.argv:
    if( isSqlFile( sql_file_path ) ):
      processSqlFile( db_path, sql_file_path )

def processSqlFile( db_path, sql_file_path ):
  print '{:^50}'.format(
    'Processing ' +
    SQL_DIR + sql_file_path +
    ' to '  +
    DBS_DIR + db_path )

  qry_file = open( SQL_DIR + sql_file_path, 'r' ).read()
  con = sqlite3.connect( DBS_DIR + db_path )
  c   = con.cursor()
  queries = qry_file.split(';')

  for query in queries:
    try:
      c.execute( query )
    except sqlite3.OperationalError:
      exit('Check if db table exists, or for syntax errors')

  con.commit()
  c.close()
  con.close()
{'fraction_non_alphanumeric': 0.13744493392070484, 'fraction_numerical': 0.007048458149779736, 'mean_word_length': 3.221189591078067, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2671054', 'n_tokens_mistral': 874, 'n_tokens_neox': 849, 'n_words': 214}