def main(argv):
  if len(argv) < 2:
    raise app.UsageError('Please specify a dbspec')

  try:
    histfile = os.path.join(os.environ['HOME'], '.mysql_history')
    readline.read_history_file(histfile)
    atexit.register(readline.write_history_file, histfile)
  except (KeyError, IOError):
    pass

  if sys.stdin.isatty():
    if FLAGS.prompt:
      prompt = '%s> ' % FLAGS.prompt
    else:
      prompt = '%s> ' % argv[1]
    continued_prompt = ' ' * (len(prompt) - 3) + '-> '
  else:
    prompt = continued_prompt = ''

  continued = [False]

  def GetLines():
    while True:
      try:
        display_prompt = continued_prompt if continued[0] else prompt
        continued[0] = True
        yield raw_input(display_prompt).decode(FLAGS.charset)
      except EOFError:
        print
        return

  with db.Connect(argv[1], charset=FLAGS.charset) as dbh:
    for statement in db.XCombineSQL(GetLines()):
      continued[0] = False
      executor = CancellableExecutor(dbh)
      try:
        executor.Execute(statement)
      except KeyboardInterrupt:
        print ('Cancelling current query. '
               'Hitting ^C again will terminate the program.')
        executor.CancelOngoingOperation()
dataset/ETHPy150Open google/mysql-tools/sql.py/main/original