BUG: ODBCConnection >> DBField >> numberFromNumeric

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

BUG: ODBCConnection >> DBField >> numberFromNumeric

Dmitry Zamotkin-2
DBField >> numberFromNumeric
 "Private - Answer the receiver's contents converted from a
 string NUMERIC to a <ScaledDecimal> (ODBC converts NUMERIC
 fields to strings by default, but NUMERIC is a decimal type)."

         | integerPart number fractionPart scale char isNegative stream |
 stream := ReadStream on: buffer from: 1 to: self length.
 integerPart := 0.
 scale := 0.

 " ------------------------------ current code is:"
 isNegative := stream peekFor: $-.

"--------------------------------should be
 isNegative := stream peekFor: ##($- codePoint).
------------------------------
otherwise no string is treated as negative
"

 [stream atEnd or: [(char := stream next) == ##($. codePoint)]] whileFalse:
[
  integerPart := integerPart * 10 + (char - ##($0 codePoint))].
 fractionPart := 0.
 [stream atEnd] whileFalse: [
  char := stream next.
  fractionPart := fractionPart * 10 + (char - ##($0 codePoint)).
  scale := scale + 1].
 number := (fractionPart / (10 raisedToInteger: scale)) + integerPart.
         isNegative ifTrue: [number := number negated].
         ^ScaledDecimal
  newFromNumber: number
  scale: scale


Reply | Threaded
Open this post in threaded view
|

Re: ODBCConnection >> DBAbstractStatement >> describeCols: (was DBField >> numberFromNumeric)

John Aspinall
Dmitry Zamotkin:
> DBField >> numberFromNumeric
>  "Private - Answer the receiver's contents converted from a
>  string NUMERIC to a <ScaledDecimal> (ODBC converts NUMERIC
>  fields to strings by default, but NUMERIC is a decimal type)."
>

I'll add the following that I discovered recently:

I'm developing a RDBMS interface layer which in some cases automatically
aliases column names to ensure uniqueness. I recently started experiencing
'Data Truncated' notifications with some queries, and traced the problem to
cases where the aliased column name is larger than 30 characters.

The cause seems to be DBAbstractStatement>>describeCols:, which is using the
ODBC Constant SQLMaxColumnNameLen (30) as the maximum column name length.
According to MSDN, SQLMaxColumnNameLen is actually a parameter for use with
SQLGetInfo, which will return the maximum column length for the driver (64
in the case of MySQL).

I'm currently using the following fix:

describeCols: columnNumbers
 "Answer an array of <DBColAttr>s describing the each of the columns
 of the receiver with indices in the <sequencedReadableCollection>
argument."

 | answer i name type precision ret colNameLen sqlType scale nullable len
hStmt colLen lib |

 len := self parent getInfoWord: SQLMaxColumnNameLen.

....etc.

Regards,

John Aspinall
Solutions Software
--


Reply | Threaded
Open this post in threaded view
|

Re: ODBCConnection >> DBField >> numberFromNumeric

Blair McGlashan
In reply to this post by Dmitry Zamotkin-2
Dmitry

You wrote in message news:9d84ck$kt8$[hidden email]...

> DBField >> numberFromNumeric
> ...
>  " ------------------------------ current code is:"
>  isNegative := stream peekFor: $-.
>
> "--------------------------------should be
>  isNegative := stream peekFor: ##($- codePoint).
> ------------------------------
> otherwise no string is treated as negative
> "
> ....

Thanks. Defect number 223. Will be fixed in the next patch level.

Regards

Blair


Reply | Threaded
Open this post in threaded view
|

Re: ODBCConnection >> DBAbstractStatement >> describeCols: (was DBField >> numberFromNumeric)

Blair McGlashan
In reply to this post by John Aspinall
John

You wrote in message news:rHOJ6.21477$[hidden email]...
> ...
> I'm developing a RDBMS interface layer which in some cases automatically
> aliases column names to ensure uniqueness. I recently started experiencing
> 'Data Truncated' notifications with some queries, and traced the problem
to
> cases where the aliased column name is larger than 30 characters.
>
> The cause seems to be DBAbstractStatement>>describeCols:, which is using
the
> ODBC Constant SQLMaxColumnNameLen (30) as the maximum column name length.
> According to MSDN, SQLMaxColumnNameLen is actually a parameter for use
with
> SQLGetInfo, which will return the maximum column length for the driver (64
> in the case of MySQL)....

Thanks, defect no. 229.

Regards

Blair