From 15d2da3ad56c9e0482df45b7335bde10e606c94b Mon Sep 17 00:00:00 2001 From: "LEFOU\\Daniel" Date: Fri, 14 Oct 2022 13:52:28 -0400 Subject: [PATCH] Support binding decimals with scale >= 10 to parameters Explicitly print just the digits rather than stripping off the scale from the full printString --- .../MySQLBindParameterDecimalTest.class.st | 49 +++++++++++++++++++ MySQL-Core/MySQLBindParameter.class.st | 9 ++-- MySQL-Core/MySQLOkay.class.st | 10 ++-- 3 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 MySQL-Core-Tests/MySQLBindParameterDecimalTest.class.st diff --git a/MySQL-Core-Tests/MySQLBindParameterDecimalTest.class.st b/MySQL-Core-Tests/MySQLBindParameterDecimalTest.class.st new file mode 100644 index 0000000..729f730 --- /dev/null +++ b/MySQL-Core-Tests/MySQLBindParameterDecimalTest.class.st @@ -0,0 +1,49 @@ +Class { + #name : #MySQLBindParameterDecimalTest, + #superclass : #TestCase, + #instVars : [ + 'theParam' + ], + #category : #'MySQL-Core-Tests-Utilities' +} + +{ #category : #running } +MySQLBindParameterDecimalTest >> setUp [ + super setUp. + theParam := MySQLBindParameter new. + +] + +{ #category : #accessing } +MySQLBindParameterDecimalTest >> storeBinary [ + ByteArray streamContents: [:strm | + theParam storeBinaryOn: strm. + ^ strm contents] + +] + +{ #category : #tests } +MySQLBindParameterDecimalTest >> testParamDecimal [ + theParam bindValue: 12.00s2. + self assert: theParam detectParamType equals: MySQLTypes typeDECIMAL +] + +{ #category : #tests } +MySQLBindParameterDecimalTest >> testStoreBinaryLargeScale [ + theParam bindValue: 1.0s10. + self + assert: self storeBinary + equals: #[12] , '1.0000000000' asByteArray. + theParam bindValue: 1.23456789012s. + self + assert: self storeBinary + equals: #[13] , '1.23456789012' asByteArray +] + +{ #category : #tests } +MySQLBindParameterDecimalTest >> testStoreBinarySmallScale [ + theParam bindValue: 12.345s. + self assert: self storeBinary equals: #[6] , '12.345' asByteArray. + theParam bindValue: 1.23s. + self assert: self storeBinary equals: #[4] , '1.23' asByteArray +] diff --git a/MySQL-Core/MySQLBindParameter.class.st b/MySQL-Core/MySQLBindParameter.class.st index 8e99ba0..e2f6fd7 100644 --- a/MySQL-Core/MySQLBindParameter.class.st +++ b/MySQL-Core/MySQLBindParameter.class.st @@ -99,9 +99,12 @@ MySQLBindParameter >> dateTimeBytes [ { #category : #writes } MySQLBindParameter >> decimalBytes [ "For scaled decimal" - ByteArray streamContents: [:strm | - MySQLHelper encodeLcs: (paramValue printString allButLast:2) asByteArray on: strm. - ^ strm contents] + + ^ ByteArray + streamContents: [ :strm | + MySQLHelper + encodeLcs: (paramValue printShowingDecimalPlaces: paramValue scale) asByteArray + on: strm ] ] { #category : #accessing } diff --git a/MySQL-Core/MySQLOkay.class.st b/MySQL-Core/MySQLOkay.class.st index 924b055..85f6329 100644 --- a/MySQL-Core/MySQLOkay.class.st +++ b/MySQL-Core/MySQLOkay.class.st @@ -26,6 +26,11 @@ MySQLOkay >> hasMoreResults [ ] +{ #category : #accessing } +MySQLOkay >> insertId [ + ^ insertId +] + { #category : #accessing } MySQLOkay >> inTransaction [ | autoCommit inTx | @@ -35,11 +40,6 @@ MySQLOkay >> inTransaction [ ] -{ #category : #accessing } -MySQLOkay >> insertId [ - ^ insertId -] - { #category : #testing } MySQLOkay >> isOkay [ ^ true