PDA

View Full Version : maya Python with ODBC issue


NoFlame
02-02-2012, 07:46 AM
Hi guys, i've try use maya python to get data from our database(SQL-Server) via ODBC.
We have a table,named user, which has tree columns, id(int), name(varchar), login_time(dataTime).

the follow query work well

SELECT id, name FROM user #work well
SELECT id, login_time FROM user #work well
SELECT login_time FROM user #work well


but when i query this, things go wrong

SELECT name, login_time FROM user

It return "internalError: [Microsoft][ODBC SQL Server Driver]無效的敘述元索引 in SQLGetData"
Sorry for the Chinese word, it means "Index invalid element narrative" (google translate...)

if you use convert, it works

SELECT convert(varchar, name), convert(varchar, login_time) FROM user


Does anyone know the reason of the problem ?

uiron
02-02-2012, 08:24 AM
would it change anything if you use escaped column names? don't know how that's done on sql server, try


SELECT "name", "login_time" FROM user

or

SELECT [name], [login_time] FROM user


or even


SELECT u.[name], u.[login_time] FROM user u

NoFlame
02-02-2012, 09:03 AM
After googling, some people say this is cause by the query order and column create order are not the same ,
but after my test, just a simple rule...
The rule is "Always but the varchar type column in the last." like:

SELECT last_login, name FROM user #work!!
SELECT name, last_login FROM user #not work!!

SELECT id, name FROM user #work!!
SELECT name, id FROM user #not work!!


Hope this help. (it talk me almost two day to get this solution :banghead: )

CGTalk Moderation
02-02-2012, 09:03 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.