Skip to content

Incorrect encoding of ScaledDecimal query parameters #5

Open
@rko281

Description

@rko281

Encoding of ScaledDecimal in MySQLBindParameter>>decimalBytes drops first digit of parameter value. Test case (where c is a connected MySQLDriver):

c query: 'drop table if exists decimal_test'.
c query: 'create table decimal_test (d decimal(10,2))'.
r := c prepare: 'insert into decimal_test(d) values(?)'.
s := (MySQLDriverStatement onConnection: c) stmtId: r prepareOkay stmtHandlerId; cursoredFetch: false; yourself.
s addBinding: 123.45s2.
s execute.
(c query: 'select * from decimal_test') rows first at: 1  " '23.45' "

Issue can be resolved as follows:

decimalBytes
	"For scaled decimal"
	ByteArray streamContents: [:strm |
		MySQLHelper encodeLcs: (paramValue abs printString allButLast:2) asByteArray on: strm.
		^ strm contents]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions