You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Return rows with column names as HashMap Text Value #5
Be aware that T.useAsPtr, used here, frees the allocated memory after it's finished, so you'll want to do the T.fromPtr (which copies) inside that call.
After that, I think it's fine if we make a breaking API change: fetchIterator, fetchStatementRows, query and stream all produce rows of HashMap Text Value instead of [Maybe Value]. The fromRow class in Conversion will have to change. Perhaps you can rename fromRow to fromRowList and add another method fromRowMap :: HashMap Text Value -> Either String r, and have fromRowMap implemented in terms of the already existing method, fromRowMap = fromRowList . M.elems. And then you just add an instance for FromValue v => FromRow (HashMap Text v). The *.SQLServer module need not change.
namelen comes from here, so it should be 2000. Instead, you want to use the length given by the ODBC driver, which is put into namelenp. You can peek that pointer to get the actual length of the column.
For my case I simply cloned query and fetchStatementRows into queryMaps and fetchStatementMaps
Perhaps as the next step I could tackle unifying them all as you suggested.
Also if we are open to API redesign at this early stage what do you think about dropping your Value and adopting SqlValue from HDBC package?
Otherwise I have to create a compatibility layer converting from Value to SqlValue in order to make this a drop in replacement for hdbc-odbc.
Value and SqlValue have almost the same structure. SqlValue has SqlNull that allows to drop Maybe and has automatic way to convert to maybes if needed.
OK, good, then we can deal with Value in a separate discussion. So we just have the HashMap part. I won't be able to work on this today, but perhaps tomorrow.
Yeah, HDBC still uses String instead of Text in SqlValue.
Perhaps I should raise the issue with them, but I doubt this will be fixed. Probably too much legacy code everywhere.
Activity
chrisdone commentedon Mar 31, 2018
This is doable with the current interface. 👍
vagifverdi commentedon Mar 31, 2018
I'm trying to do it myself. But I'm stumped with C to haskell string conversions.
I added columnName to Column record:
In describeColumn i'm trying to get the name of the column:
But that gives me SQLWCHAR. How do i convert it to haskell Text or String?
chrisdone commentedon Mar 31, 2018
T.fromPtrcan be used like this to give you aTextfrom awchar_t*(SQLWCHAR).chrisdone commentedon Mar 31, 2018
Be aware that
T.useAsPtr, used here, frees the allocated memory after it's finished, so you'll want to do theT.fromPtr(which copies) inside that call.vagifverdi commentedon Mar 31, 2018
ok, a little progress. I tried
colname <- T.fromPtr namep (fromIntegral (div namelen 2))And it produced a string that starts with a field name bu then continues with a large string of prefilled zeroes like this:
"min_time\NUL00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
Notice that there's a null terminator there.
How would I deal with tat?
chrisdone commentedon Mar 31, 2018
After that, I think it's fine if we make a breaking API change:
fetchIterator,fetchStatementRows,queryandstreamall produce rows ofHashMap Text Valueinstead of[Maybe Value]. ThefromRowclass inConversionwill have to change. Perhaps you can renamefromRowtofromRowListand add another methodfromRowMap :: HashMap Text Value -> Either String r, and havefromRowMapimplemented in terms of the already existing method,fromRowMap = fromRowList . M.elems. And then you just add an instance forFromValue v => FromRow (HashMap Text v). The*.SQLServermodule need not change.HashMapis much more memory efficient thanMap: https://github.com/haskell-perf/dictionaries#pure-maps-fromlist-space-use (And faster lookup: https://github.com/haskell-perf/dictionaries#lookupbytestring-monotonic)chrisdone commentedon Mar 31, 2018
namelencomes from here, so it should be2000. Instead, you want to use the length given by the ODBC driver, which is put into namelenp. You can peek that pointer to get the actual length of the column.vagifverdi commentedon Mar 31, 2018
Success! Thank you very much for helping me.
For my case I simply cloned query and fetchStatementRows into queryMaps and fetchStatementMaps
Perhaps as the next step I could tackle unifying them all as you suggested.
Also if we are open to API redesign at this early stage what do you think about dropping your Value and adopting SqlValue from HDBC package?
Otherwise I have to create a compatibility layer converting from Value to SqlValue in order to make this a drop in replacement for hdbc-odbc.
chrisdone commentedon Mar 31, 2018
👍
I'm not attached to
Value, it's just shorter.SqlValueis fine.What about the constructors of
Value- are they largely the same? Is that important?vagifverdi commentedon Mar 31, 2018
Value and SqlValue have almost the same structure. SqlValue has SqlNull that allows to drop Maybe and has automatic way to convert to maybes if needed.
https://hackage.haskell.org/package/HDBC-2.4.0.2/docs/Database-HDBC-SqlValue.html
But yes, there are more constructors for SqlValue than what you have.
vagifverdi commentedon Mar 31, 2018
Also Value clashes with Aeson.
vagifverdi commentedon Mar 31, 2018
Hmm, we do not need to provide an implementation for every Constructor in the SqlValue. Only the ones that we are interested in.
chrisdone commentedon Mar 31, 2018
OK, good, then we can deal with
Valuein a separate discussion. So we just have theHashMappart. I won't be able to work on this today, but perhaps tomorrow.vagifverdi commentedon Mar 31, 2018
Yeah, HDBC still uses String instead of Text in SqlValue.
Perhaps I should raise the issue with them, but I doubt this will be fixed. Probably too much legacy code everywhere.
[-]Column names are lost[/-][+]Return rows with column names as HashMap Text Value[/+]