Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000',"[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68' (http://www.velocityreviews.com/forums/t950949-sqlalchemy-exc-programmingerror-programmingerror-42000-42000-microsoft-odbc-sql-server-driver-sql-server-f2f68.html)

nepaul 08-17-2012 09:56 AM

sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000',"[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68'
 
=======================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!

Alain Ketterlin 08-17-2012 10:54 AM

Re: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68'
 
nepaul <xs.nepaul@gmail.com> 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.

Peter Otten 08-17-2012 11:04 AM

Re: sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000',"[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]'f2f68'
 
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.



All times are GMT. The time now is 01:58 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57