On Fri, 11 Mar 2011, Leon Unger wrote:
recently I tried to read in several series via odbc *including
one dummy* series and I forgot to change its entries from "No"
and "YES" to "0" and "1".
However, SQL retrieved for all series the correct number of
observations.*BUT ALL SERIES* were corrupted. That's why two
thoughts come up:
1) I know from importing STATA files that GRETL changes string
entries to number entries. Does GRETL use information provided
by the STATA file, or does it this job by itself? If yes, would
it be possible to add this functionality to the odbc read in
process?
2) If one has always to provide numerical entries and e.g. one
series is not correcltly specified then actually only this
series should be corrupted.
As I said previously, I agree with Jack Lucchetti's comment that
getting an ODBC import right is really the responsbility of the
gretl user. But I also said that it was gretl's responsibility to
avoid crashing on an incorrect SQL query.
I've now investigated further, and I'm less inclined to think
there's a bug in gretl's handling of this issue.
Gretl can convert string-valued variables from Stata dta files
into numerical values because a dta file contains a clear
specification of the "original" type of each variable.
But things are different with ODBC. One uses the function
SQLBindCol() to tell ODBC what data type one wants from each data
column (and for all actual data columns gretl specifies the type
SQL_C_DOUBLE). It's then ODBC's job to convert whatever type comes
out of the db into what was requested.
As a test, I constructed a dummy db using mysql, with one "real"
numerical data column and one column containing "yes" and "no"
strings. I then used gretl to read in those two variables via
unixODBC. What I got was basically what you'd expect: the
numerical series came in OK, and the "yes"/"no" column came in as
a series of zeros (zero being the default when no numeric
conversion is possible).
If you're getting general data corruption when one of the data
columns contains strings, then (a) it might help if you were to
give us an exact recipe for reproducing the problem, but (b) maybe
your bug report should go to Microsoft Corp?
Allin Cottrell