[Mono-list] Problem with ODBC Driver

Alan Tam Tam@SiuLung.com
Wed, 21 May 2003 05:11:46 +0800


The problem you have maybe more chaotic. It happens to be the enum value of
small date time = 0, i.e. same as default value. So if somehow initialization
to the correct value is skipped, it will be treated as a DateTime type ... and
failed to cast ...

Btw, the reason no exception is thrown for types other than int and string is
that those parts are correctly implemented. The only wrong implementation is
that we haven't allocated storage for every datatype. When it is detected to be
an int, do the thing and otherwise assume that it is a string. So the internal
stored copy has a wrong datatype.

I am not too familar with ODBC, but I suspect, when I looked at the code, that
when we need to fetch a value, we need to allocate a buffer and call the
function by reference. When we need to update the value, the same buffer
location is used. This implies that for different datatypes, e.g. Int32, Int64,
... we need a different buffer, if we don't implement the serializations
ourselves. In view of this, a correct implementation need a big switch and
every datatype has a different function call for the respective variable.

Regards,
Alan

----- Original Message ----- 
From: "Olivier Gaumond" <ogaumond@yahoo.com>
To: "Alan Tam" <Tam@SiuLung.com>; <mono-list@lists.ximian.com>
Sent: 2003-05-21 04:33
Subject: Re: [Mono-list] Problem with ODBC Driver


>
> However my table contains only varchar.
>
> But it explains other bugs I had.
>
> I thing it should throw a NotImplementedExcepetion when you call functions
such
> as GetDouble.
>
> Olivier
>
>  --- Alan Tam <Tam@SiuLung.com> a écrit : > It is because the ODBC data
> provider currently only implemented String, Int32
> > and no more other datatypes.
> >
> > Regards,
> > Alan
> >
> > ----- Original Message ----- 
> > From: "Olivier Gaumond" <ogaumond@yahoo.com>
> > To: <mono-list@lists.ximian.com>
> > Sent: 2003-05-21 03:37
> > Subject: [Mono-list] Problem with ODBC Driver
> >
> >
> > > I created the following table in MySQL test database
> > > create table employee (firstname varchar(32), lastname varchar(32));
> > >
> > > I can retrieve data from the database with the Mono.Data.MySql provider
but
> > not
> > > with the ODBC provider.
> > >
> > > I have unixODBC and MyODBC installed and working and I added a DSN to
> > connect
> > > to the database.  I can succesfully test the DSN and connection with
> > unixODBC
> > > DataManager.
> > >
> > > To avoid errors when testing with Mono I had to symlink
> > /usr/local/libodbc32.so
> > > to /usr/local/libodbc.so and export LD_LIBRARY_PATH=/usr/local/lib
> > >
> > > Here are the tests I made in sqlsharp to demonstrate the errors.
> > >
> > > With the Mono.Data.MySql provider
> > >
> > > SQL# \Provider MySql
> > > The default Provider is LOADEXTPROVIDER
> > >           Assembly: Mono.Data.MySql
> > >   Connection Class: Mono.Data.MySql.MySqlConnection
> > >
> > > SQL# \ConnectionString
> > SERVER=localhost;DATABASE=test;UID=test;PASSWORD=test;
> > >
> > > SQL# \Open
> > > Attempt to open connection...
> > > Loading external provider...
> > >
> > > ** (sqlsharp.exe:7934): WARNING **: Failed to load function my_thread_end
> > from
> > > libmySQL
> > >
> > > ** (sqlsharp.exe:7934): WARNING **: Failed to load function my_thread_end
> > from
> > > libmySQL
> > >
> > > ** (sqlsharp.exe:7934): WARNING **: Failed to load function
my_thread_init
> > from
> > > libmySQL
> > >
> > > ** (sqlsharp.exe:7934): WARNING **: Failed to load function
my_thread_init
> > from
> > > libmySQL
> > > External provider loaded.
> > > Open was successfull.
> > >
> > > SQL# SELECT * FROM employee;
> > > Execute SQL: SELECT * FROM employee;
> > > Display any result sets...
> > > Display the result set 1
> > > Fields in Query Result: 2
> > >
> > > firstname lastname
> > > ========= ========
> > >
> > > Joe       Bloe
> > > John      Smith
> > > Scott     Tiger
> > >
> > > Rows retrieved: 3
> > >
> > > ----
> > >
> > > With the ODBC Driver
> > >
> > > SQL# \Provider odbc
> > > The default Provider is ODBC
> > >
> > > SQL# \ConnectionString DSN=test;UID=test;PWD=test;
> > >
> > > SQL# \Open
> > > Attempt to open connection...
> > >
> > > ** (sqlsharp.exe:7934): WARNING **: byref boolean marshalling not
> > inplemented
> > > Open was successfull.
> > >
> > > SQL# SELECT * FROM employee;
> > > Execute SQL: SELECT * FROM employee;
> > > Display any result sets...
> > > Display the result set 1
> > > Fields in Query Result: 2
> > >
> > > firstname           lastname
> > > =================== ===================
> > >
> > > Error: System.InvalidCastException: Cannot cast from source type to
> > destination
> > > type
> > > in <0x0002f> 00 System.Data.Odbc.OdbcDataReader:GetDateTime (int)
> > > in <0x0083e> 00 Mono.Data.SqlSharp.SqlSharpCli:DisplayResult
> > > (System.Data.IDataReader,System.Data.DataTable)
> > > in <0x00028> 00 Mono.Data.SqlSharp.SqlSharpCli:OutputQueryResult
> > > (System.Data.IDataReader,System.Data.DataTable)
> > > in <0x000d7> 00 Mono.Data.SqlSharp.SqlSharpCli:DisplayData
> > > (System.Data.IDataReader)
> > > in <0x00106> 00 Mono.Data.SqlSharp.SqlSharpCli:ExecuteSql (string)
> > >
> > >
> > > The driver seems to always return DateTime from GetFieldType().
> > >
> > > To run the sample from http://www.go-mono.com/odbc.html I had to change
two
> > > lines
> > > string FirstName = reader["firstname"];
> > > string LastName = reader["lastname"];
> > > to
> > > string FirstName = reader.GetString(0);
> > > string LastName = reader.GetString(1);
> > >
> > >
> > > Should I fill a bug report about that?
> > >
> > > Olivier
> > >
> > > __________________________________________________________
> > > Lèche-vitrine ou lèche-écran ?
> > > magasinage.yahoo.ca
> > > _______________________________________________
> > > Mono-list maillist  -  Mono-list@lists.ximian.com
> > > http://lists.ximian.com/mailman/listinfo/mono-list
> > >
> >
> > _______________________________________________
> > Mono-list maillist  -  Mono-list@lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-list
>
> __________________________________________________________
> Lèche-vitrine ou lèche-écran ?
> magasinage.yahoo.ca
>