Menu

Strange Syntax error

Help
2005-03-23
2012-09-19
  • Tom McCarthy

    Tom McCarthy - 2005-03-23

    Greetings,

    If I enter the following string into the standard mysql client:

    create database python_testing;use python_testing;create table test (test char(60) binary not null default '');

    It runs fine. If I try to run it using MySQLdb, I get the following error:

    (1064, "You have an error in your SQL syntax near ';use python_testing;create table test (test char(60) binary not null default '')' at line 1")

    Here is my code (I have replaced sensitive info with 'xx'):

    import MySQLdb
    create_sql = """create database python_testing;use python_testing;create table test (test char(60) binary not null default '');"""

    conn = MySQLdb.connect(host="xx.xx.xx.xx",user="xxx",passwd="xxx")
    cursor = conn.cursor()
    cursor.execute(create_sql)

    help?

     
    • Andy Dustman

      Andy Dustman - 2005-03-23

      You cannot issue multiple queries at once. Break it into multiple queries and remove the ';'.

      (There IS a way to do it IF you have MySQL-4.1 and you set MySQLdb.constants.CLIENT.MULTI_STATEMENTS, but you should not normally do this.)

       
    • Tom McCarthy

      Tom McCarthy - 2005-03-24

      Ah. Thanks very much for your reply. Multiple queries it is.

      thanks again :)

       

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.