Menu

Executing multiple commands in execute()?

Help
2002-04-03
2012-09-19
  • Bill Eldridge

    Bill Eldridge - 2002-04-03

    I was interested in taking some
    raw SQL files and executing them,
    something like:

    db=MySQL.connect(...)
    c=db.cursor()
    c.execute("""use mydb; select * from mytable;""")

    (which could easily be:

    commands= open("rawsql","r").read()
    c.execute(commands)

    if it would work).

     
    • Marco Wesselgren

      Why not something like:
      fh = open(myfile,"r")
      db = MySQL.connect(foo)
      c=db.cursor()
      while 1:
          if not line():
              imdone()
          else:
          try:
          c.execute(fh.readline())
          except MySQLError:
              someerrorhandling()

      Maybe this isn't what you are after?       

       
    • Marco Wesselgren

      A bit tired, it should of course be:

      ...
      ...
      c=db.cursor()
      while 1:
          line = fh.readline()
          if not line:
              imdone()
          else:
              try:
              c.execute(line)
              except MySQLError:
              someerrorhandling()

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.