Hi,
I have two tables in a mysql database whose schema are basically identical (see schema at the end). When I attempt to query the first one using ODBC.jl, there is no problem, and data is returned as expected. However, when I try a similar query on the second, it throws an error:
The query with the error:
Query: SELECT * FROM `AUROPHARM` WHERE CTYPE="FUT" AND DATE(DTTM)="2016-07-01" AND RES="30 secs" AND QTYPE="BID" AND EXPIRY="2016-07-28" ORDER BY DTTM ASC
In fetch: types = DataType[WeakRefString{Int32},WeakRefString{Int32},Float32,ODBC.API.SQLDate,ODBC.API.SQLTimestamp,WeakRefString{Int32},WeakRefString{Int32},Float32,Float32,Float32,Float32,Float32,Int32,Int32,Float32]
ERROR: LoadError: MethodError: no method matching bytes2codeunits(::Type{Int32}, ::Int64)
Closest candidates are:
bytes2codeunits(!Matched::Type{UInt8}, ::Any) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:248
bytes2codeunits(!Matched::Type{UInt16}, ::Any) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:249
bytes2codeunits(!Matched::Type{UInt32}, ::Any) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:250
in cast!(::Type{WeakRefString{Int32}}, ::ODBC.Source, ::Int64) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:264
in fetch!(::ODBC.Source) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:177
in #Source#4(::Bool, ::Type{T}, ::ODBC.DSN, ::String) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:161
in #query#12 at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:334 [inlined]
in query(::ODBC.DSN, ::String, ::Type{DataFrames.DataFrame}) at /Users/msravi/.julia/v0.5/ODBC/src/Source.jl:334
The query without the error:
Query: SELECT * FROM `TATAMOTOR` WHERE CTYPE="FUT" AND DATE(DTTM)="2016-01-04" AND RES="30 secs" AND QTYPE="BID" AND EXPIRY="2016-01-28" ORDER BY DTTM ASC
In fetch: types = DataType[WeakRefString{UInt8},WeakRefString{UInt8},Float32,ODBC.API.SQLDate,ODBC.API.SQLTimestamp,WeakRefString{UInt8},WeakRefString{UInt8},Float32,Float32,Float32,Float32,Float32,Int32,Int32,Float32]
Got (750,9) elements for TATAMOTOR:2016-01-04:FUT:NA:0.0:20160128:BID
Both queries return valid data when queried using the mysql client.
Digging into Source.jl in the ODBC source, it appears that the type returned for a char string is WeakRefString{Int32} instead of WeakRefString{UInt8}. The bytes2codeunits has no method with a WeakRefString{Int32} type which causes the error. I’m unable to fathom why the type returned is WeakRefString{Int32} for one case and WeakRefString{UInt8} for another, given the same schema. Any pointers will be appreciated.
Thanks,
Ravi
Julia version: Version 0.5.1-pre+31 (2016-11-17 17:50 UTC)
ODBC.jl last git commit: e12d9edecfafb9f16d2e8ed144b128982a4980d3
The schemas:
mysql> describe TATAMOTOR;
+---------+--------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+------------+-------+
| CTYPE | char(3) | NO | PRI | NULL | |
| PUTCALL | varchar(8) | NO | PRI | NA | |
| STRIKE | float | NO | PRI | 0 | |
| EXPIRY | date | NO | PRI | 0000-00-00 | |
| DTTM | datetime | NO | PRI | NULL | |
| RES | varchar(7) | NO | PRI | NULL | |
| QTYPE | varchar(25) | NO | PRI | NULL | |
| OPEN | float | YES | | NULL | |
| HIGH | float | YES | | NULL | |
| LOW | float | YES | | NULL | |
| LAST | float | YES | | NULL | |
| CLOSE | float | YES | | NULL | |
| VOLUME | mediumint(9) | YES | | NULL | |
| COUNT | mediumint(9) | YES | | NULL | |
| VWAP | float | YES | | NULL | |
+---------+--------------+------+-----+------------+-------+
15 rows in set (0.04 sec)
mysql> describe AUROPHARM;
+---------+--------------+------+-----+------------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+------------+-------+
| CTYPE | char(3) | NO | PRI | NULL | |
| PUTCALL | varchar(8) | NO | PRI | NA | |
| STRIKE | float | NO | PRI | 0 | |
| EXPIRY | date | NO | PRI | 0000-00-00 | |
| DTTM | datetime | NO | PRI | NULL | |
| RES | varchar(7) | NO | PRI | NULL | |
| QTYPE | varchar(25) | NO | PRI | NULL | |
| OPEN | float | YES | | NULL | |
| HIGH | float | YES | | NULL | |
| LOW | float | YES | | NULL | |
| LAST | float | YES | | NULL | |
| CLOSE | float | YES | | NULL | |
| VOLUME | mediumint(9) | YES | | NULL | |
| COUNT | mediumint(9) | YES | | NULL | |
| VWAP | float | YES | | NULL | |
+---------+--------------+------+-----+------------+-------+