sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000',"[42000] [Microsoft][ODBC SQL Server Dr

Discussion in 'Python' started by nepaul, Aug 17, 2012.

  1. nepaul

    nepaul Guest

    =======================case1==============================:
    import sqlalchemy
    test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a"
    cmdTest1 = "select * from analyseresult where uid = " + test1
    engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    c = engine.execute(cmdTest1)
    ======================case2===============================:
    import sqlalchemy
    test2 = "123"
    cmdTest2 = "select * from analyseresult where uid = " + test2
    engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    c = engine.execute(cmdTest1)


    !!!!!
    case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68') case2:work!
    nepaul, Aug 17, 2012
    #1
    1. Advertising

  2. Re: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68'

    nepaul <> writes:

    > =======================case1==============================:
    > import sqlalchemy
    > test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a"
    > cmdTest1 = "select * from analyseresult where uid = " + test1
    > engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    > c = engine.execute(cmdTest1)
    > ======================case2===============================:
    > import sqlalchemy
    > test2 = "123"
    > cmdTest2 = "select * from analyseresult where uid = " + test2
    > engine = sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    > c = engine.execute(cmdTest1)
    >
    >
    > !!!!!
    > case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68') case2:work!


    Print both cmdTest1 and cmdTest2. Look at them. Are they valid SQL
    queries?

    -- Alain.
    Alain Ketterlin, Aug 17, 2012
    #2
    1. Advertising

  3. nepaul

    Peter Otten Guest

    nepaul wrote:

    > =======================case1==============================:
    > import sqlalchemy
    > test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a"
    > cmdTest1 = "select * from analyseresult where uid = " + test1
    > engine =
    >

    sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    > c = engine.execute(cmdTest1)
    > ======================case2===============================: import
    > sqlalchemy test2 = "123"
    > cmdTest2 = "select * from analyseresult where uid = " + test2
    > engine =
    >

    sqlalchemy.create_engine("mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    > c = engine.execute(cmdTest1)
    >
    >
    > !!!!!
    > case1 :wrong,(sqlalchemy.exc.ProgrammingError: (ProgrammingError)
    > ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68')
    > case2:work!


    I'd guess the uuid needs to be quoted. Don't do that yourself -- your code
    will become vulnerable to sql injection attacks -- use the dbapi instead:

    # Again just guessing; I'm not an sqlalchemy user.
    import sqlalchemy
    test1 = "631f2f68-8731-4561-889b-88ab1ae7c95a"
    cmdTest1 = "select * from analyseresult where uid = %s"
    engine = sqlalchemy.create_engine(
    "mssql+pyodbc://DumpResult:123456@localhost/DumpResult")
    c = engine.execute(cmdTest1, test1)

    Note that I'm not using Python's string formatting. The two arguments are
    passed as is and mysql builds the resulting query.
    Peter Otten, Aug 17, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. iwl
    Replies:
    1
    Views:
    301
    Karl H.
    Dec 14, 2006
  2. sathya

    K&r chapter-1; exc-17

    sathya, Nov 26, 2004, in forum: C Programming
    Replies:
    35
    Views:
    926
    Merrill & Michele
    Nov 30, 2004
  3. Klaus Ahrens
    Replies:
    6
    Views:
    368
    Alf P. Steinbach
    Nov 29, 2005
  4. ½­ÎÄ
    Replies:
    0
    Views:
    159
    ½­ÎÄ
    Mar 10, 2013
  5. Jai
    Replies:
    7
    Views:
    94
Loading...

Share This Page