#1 2012-09-13 14:22:52

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

[ODBC Driver Manager] Invalid descriptor index when creating table

When trying to run my Unittests against a MS SQL database using trhe ODBC connection, I got an "Invalid Descritor Index" error every time the external table was created by the test.
It turns out that you have to read columns in order after running a statement!


So I made the following correction to SynDBODBC.pas:
On lines 1561 and following, I orders lines so that the the ColumnUTF(x) calls were orders according to the column they were referencing, resulting in:

      while Step do begin
        F.ColumnName := ColumnUTF8(3);
        F.ColumnType:= ODBCColumnToFieldType(ColumnInt(4),F.ColumnPrecision,F.ColumnScale);
        F.ColumnTypeNative := ColumnUTF8(5);
        F.ColumnLength := ColumnInt(6);
        F.ColumnScale := ColumnInt(8);
        F.ColumnPrecision := ColumnInt(9);
        FA.Add(F);

Offline

#2 2012-09-13 14:51:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: [ODBC Driver Manager] Invalid descriptor index when creating table

This is a very strange issue.
I did not have it with the ODBC driver for Oracle for instance!
sad

User code may have problem with such expectations!
I hope this is only about "special statements" like the SQLColumn() pattern.

By the way, your above code is incorrect: you call ODBCColumnToFieldType() with F.ColumnPrecision,F.ColumnScale not already retrieved.
Correct code could be:

      while Step do begin
        F.ColumnName := ColumnUTF8(3);
        DataType := ColumnInt(4);
        F.ColumnTypeNative := ColumnUTF8(5);
        F.ColumnLength := ColumnInt(6);
        F.ColumnScale := ColumnInt(8);
        F.ColumnPrecision := ColumnInt(9);
        F.ColumnType:= ODBCColumnToFieldType(DataType,F.ColumnPrecision,F.ColumnScale);
        FA.Add(F);
      end;

Offline

#3 2012-09-13 14:57:59

Bascy
Member
From: The Netherlands
Registered: 2012-06-22
Posts: 108

Re: [ODBC Driver Manager] Invalid descriptor index when creating table

Ha, i hadn't noticed the dependency ... your correct of course

[edit]
As stated in another thread, it now turn out I was using MS SQL 2000 with these tests, and not 2005 as I was thinking.

Last edited by Bascy (2012-09-13 15:09:23)

Offline

Board footer

Powered by FluxBB