Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and Tests for Issues #5, #6 and #7 #8

Merged
merged 3 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,75 @@ MySQLServerStatementFetchTest >> testReadAllRowsAtATime [

]

{ #category : #tests }
MySQLServerStatementFetchTest >> testReadNextRowFetchAll [

"Test nextRow where fetch size is greater than data size"

| rs rd |

stmt fetchSize: 100.

stmt params: (Array with: (MySQLBindParameter withValue: '2011-09-01')).
rs := stmt execute.
self assert: rs isResultSet; assert: rs hasOpenCursor; deny: rs hasLastRowSent.
10 timesRepeat:
[ rd := rs nextRow.
self deny: rd isNil ].

self assert: rs atEnd.
rd := rs nextRow.
self
assert: rd isNil;
assert: rs atEnd
]

{ #category : #tests }
MySQLServerStatementFetchTest >> testReadNextRowFetchExact [

"Test nextRow where fetch size is same as data size"

| rs rd |

stmt fetchSize: 10.

stmt params: (Array with: (MySQLBindParameter withValue: '2011-09-01')).
rs := stmt execute.
self assert: rs isResultSet; assert: rs hasOpenCursor; deny: rs hasLastRowSent.
10 timesRepeat:
[ rd := rs nextRow.
self deny: rd isNil ].

self assert: rs atEnd.
rd := rs nextRow.
self
assert: rd isNil;
assert: rs atEnd
]

{ #category : #tests }
MySQLServerStatementFetchTest >> testReadNextRowFetchIncremental [

"Test nextRow where incremental fetches are needed"

| rs rd |

stmt fetchSize: 2.

stmt params: (Array with: (MySQLBindParameter withValue: '2011-09-01')).
rs := stmt execute.
self assert: rs isResultSet; assert: rs hasOpenCursor; deny: rs hasLastRowSent.
10 timesRepeat:
[ rd := rs nextRow.
self deny: rd isNil ].

self assert: rs atEnd.
rd := rs nextRow.
self
assert: rd isNil;
assert: rs atEnd
]

{ #category : #tests }
MySQLServerStatementFetchTest >> testReadOneRowAtATime [
| rs rd |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ MySQLServerStatementInputTest >> testAcceptPositiveIntegers [

]

{ #category : #tests }
MySQLServerStatementInputTest >> testInputDoubles [
| prep stmtId resp testVals params stmt |
prep := self connection
prepare:
'insert into
testReals (floatValue, doubleValue, realValue)
values (?, ?, ?)'.
stmtId := prep prepareOkay stmtHandlerId.
params := MySQLBindParameter
listOfSize: prep prepareOkay numParams
forDescriptors: prep paramDescriptors.
(testVals := #(0 1.0 4.2 4.25 4.5s6))
do: [ :val |
params do: [ :param | param bindValue: val ].
stmt := MySQLDriverStatement onConnection: self connection.
stmt
stmtId: stmtId;
params: params.
resp := stmt execute.
self assert: resp isOkay.
self assert: resp affectedRows = 1 ].

(self connection query: 'select floatValue, doubleValue, realValue from testReals order by floatValue') rows with: testVals do:
[ :row :val |
self assert: (row at: 1) asNumber equals: val]
]

{ #category : #tests }
MySQLServerStatementInputTest >> testInputParamExpectingNoResultSet [
| prep stmtId params resp stmt |
Expand Down Expand Up @@ -234,6 +262,34 @@ MySQLServerStatementInputTest >> testInputParamExpectingResultSet [

]

{ #category : #tests }
MySQLServerStatementInputTest >> testInputScaledDecimals [
| prep stmtId resp testVals params stmt |
prep := self connection
prepare:
'insert into
testReals (decimalValue, numericValue)
values (?, ?)'.
stmtId := prep prepareOkay stmtHandlerId.
params := MySQLBindParameter
listOfSize: prep prepareOkay numParams
forDescriptors: prep paramDescriptors.
(testVals := #(-1s6 0s6 1s6))
do: [ :val |
params do: [ :param | param bindValue: val ].
stmt := MySQLDriverStatement onConnection: self connection.
stmt
stmtId: stmtId;
params: params.
resp := stmt execute.
self assert: resp isOkay.
self assert: resp affectedRows equals: 1 ].

(self connection query: 'select decimalValue, numericValue from testReals order by decimalValue') rows with: testVals do:
[ :row :val |
self assert: (row at: 1) asNumber equals: val]
]

{ #category : #tests }
MySQLServerStatementInputTest >> testInputTimeTypes [
| prep stmtId params stmt resp |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ MySQLServerStatementReadStringTest >> testReadRealTypesNull [

{ #category : #tests }
MySQLServerStatementReadStringTest >> testReadTimeTypes [

"From https://dev.mysql.com/doc/refman/8.0/en/datetime.html
'The offset is not displayed when selecting a datetime value [column 4], even if one was used when inserting it.'
This implies timestamps include the timezone offset, however the example SELECT results at that URL omits it.
Therefore we hedge our bets here with a 'beginsWith:' test"


| prep stmtId params resp stmt |
self withFixtures: #(#times) do: [:conn |
prep := conn prepare: 'select * from testTimes order by id'.
Expand All @@ -228,18 +235,18 @@ MySQLServerStatementReadStringTest >> testReadTimeTypes [

resp := stmt execute.
self assert: resp isResultSet.
self assert: resp rows size = 4.

self assert: (resp rows first atIndex: 2) = '2011-07-01'.
self assert: (resp rows first atIndex: 3) = '18:35:23'.
self assert: (resp rows first atIndex: 4) = '2011-07-02T10:12:45+00:00'.
self assert: (resp rows first atIndex: 5) = '1980-01-12T00:45:56+00:00'.
self assert: (resp rows first atIndex: 6) = '1999'.

self assert: (resp rows second atIndex: 2) = '2011-06-01'.
self assert: (resp rows second atIndex: 3) = '3:17:34:22'.
self assert: (resp rows second atIndex: 4) = '2011-06-02T09:11:44+00:00'.
self assert: (resp rows second atIndex: 5) = '1980-02-13T01:44:55+00:00']
self assert: resp rows size equals: 4.

self assert: (resp rows first atIndex: 2) equals: '2011-07-01'.
self assert: (resp rows first atIndex: 3) equals: '18:35:23'.
self assert: (resp rows first atIndex: 4) equals: '2011-07-02T10:12:45'.
self assert: ((resp rows first atIndex: 5) beginsWith: '1980-01-12T00:45:56').
self assert: (resp rows first atIndex: 6) equals: '1999'.

self assert: (resp rows second atIndex: 2) equals: '2011-06-01'.
self assert: (resp rows second atIndex: 3) equals: '3:17:34:22'.
self assert: (resp rows second atIndex: 4) equals: '2011-06-02T09:11:44'.
self assert: ((resp rows second atIndex: 5) beginsWith: '1980-02-13T01:44:55')]

]

Expand Down
13 changes: 4 additions & 9 deletions MySQL-Core-Tests-Integration/MysqlDriverTest.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Class {
#name : #MySQLDriverTest,
#superclass : #TestCase,
#superclass : #MySQLTestCase,
#instVars : [
'connector'
],
Expand All @@ -22,12 +22,7 @@ MySQLDriverTest >> badConnectionSpec [

{ #category : #accessing }
MySQLDriverTest >> goodConnectionSpec [
^ MySQLDriverSpec new
host: 'localhost';
port: 3306;
user: 'root';
password: '';
yourself
^ MySQLTestResource driverSpecNoDb
]

{ #category : #accessing }
Expand Down Expand Up @@ -93,12 +88,12 @@ MySQLDriverTest >> testConnectGood [
MySQLDriverTest >> testConnectWithDb [
| connSpec resp |
connSpec := self goodConnectionSpec.
connSpec db: 'sodbxtest2'.
connSpec db: MySQLTestResource dbName.
resp := connector connect: connSpec.
self assert: resp isOkay.
connector disconnect.

connSpec db: 'sodbxtest2' reversed.
connSpec db: MySQLTestResource dbName reversed.
self assert: (connector connect: connSpec) isError.
connector connected ifTrue: [ connector disconnect].

Expand Down
7 changes: 6 additions & 1 deletion MySQL-Core-Tests-Integration/MysqlTestResource.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
"
Test resource for MySQL testing
Test resource for MySQL testing.

Requires MySQL running on the localhost (or edit the ip in driverSpecNoDb) and the following user to be setup:

create user 'sodbxtest'@'<test ip or *>' identified by 'sodbxtest';
grant create, drop, create user, select, insert, update, delete on *.* to 'sodbxtest'@'<test ip or *>';
"
Class {
#name : #MySQLTestResource,
Expand Down
10 changes: 10 additions & 0 deletions MySQL-Core-Tests/MySQLBindParameterDateTimeTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Class {
#category : #'MySQL-Core-Tests-Utilities'
}

{ #category : #tests }
MySQLBindParameterDateTimeTest >> expectedFailures [

^super expectedFailures, #(#testParamTimestamp )
]

{ #category : #running }
MySQLBindParameterDateTimeTest >> setUp [
theParam := MySQLBindParameter new.
Expand Down Expand Up @@ -60,6 +66,10 @@ MySQLBindParameterDateTimeTest >> testParamTime [

{ #category : #tests }
MySQLBindParameterDateTimeTest >> testParamTimestamp [

"Currently an expected failure - this directly contradicts testParamDateTime.
Needs an explicit Timestamp class to map to MySQL typeTIMESTAMP"

theParam bindValue: DateAndTime current.
self assert: (theParam detectParamType = MySQLTypes typeTIMESTAMP).
self assert: theParam isUnsigned.
Expand Down
24 changes: 12 additions & 12 deletions MySQL-Core-Tests/MySQLBindParameterRealTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ MySQLBindParameterRealTest >> testParamDouble [
{ #category : #tests }
MySQLBindParameterRealTest >> testParamFloat [
theParam bindValue: 65.0.
self assert: theParam paramType = MySQLTypes typeFLOAT.
self assert: theParam paramType = MySQLTypes typeDOUBLE.
self assert: theParam isUnsigned.

theParam bindValue: -65.0.
self assert: theParam paramType = MySQLTypes typeFLOAT.
self assert: theParam paramType = MySQLTypes typeDOUBLE.
self deny: theParam isUnsigned.

]
Expand All @@ -67,11 +67,11 @@ MySQLBindParameterRealTest >> testParamFraction [
self deny: theParam isUnsigned.

theParam bindValue: 17/4.
self assert: theParam paramType = MySQLTypes typeFLOAT.
self assert: theParam paramType = MySQLTypes typeDOUBLE.
self assert: theParam isUnsigned.

theParam bindValue: -17/4.
self assert: theParam paramType = MySQLTypes typeFLOAT.
self assert: theParam paramType = MySQLTypes typeDOUBLE.
self deny: theParam isUnsigned.

]
Expand All @@ -81,7 +81,7 @@ MySQLBindParameterRealTest >> testStoreBinarySignedDecimal [
theParam bindValue: -12345.678901s6.
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents asString = '12345.678901')]
self assert: (strm contents asString = ((String with: (Character value: 13 "Length")), '-12345.678901'))]
]

{ #category : #tests }
Expand All @@ -91,7 +91,7 @@ MySQLBindParameterRealTest >> testStoreBinarySignedDouble [
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements:
(MySQLHelper bytesFromHexString: 'B4697BC3F105CDBA'))]
(MySQLHelper bytesFromHexString: 'F105CDBAB4697BC3'))]

]

Expand All @@ -101,7 +101,7 @@ MySQLBindParameterRealTest >> testStoreBinarySignedFraction [
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements: (MySQLHelper bytesFromHexString: '000011C0'))]
hasEqualElements: (MySQLHelper bytesFromHexString: '00000000000011C0'))]

]

Expand All @@ -111,7 +111,7 @@ MySQLBindParameterRealTest >> testStoreBinarySingedFloat [
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements: (MySQLHelper bytesFromHexString: '004050C0'))]
hasEqualElements: (MySQLHelper bytesFromHexString: '00000000004050C0'))]

]

Expand All @@ -120,7 +120,7 @@ MySQLBindParameterRealTest >> testStoreBinaryUnsignedDecimal [
theParam bindValue: 12345.678901s6.
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents asString = '12345.678901')]
self assert: (strm contents asString = ((String with: (Character value: 12 "Length")), '12345.678901'))]
]

{ #category : #tests }
Expand All @@ -129,7 +129,7 @@ MySQLBindParameterRealTest >> testStoreBinaryUnsignedDouble [
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements: (MySQLHelper bytesFromHexString: 'B4697B43F105CDBA'))]
hasEqualElements: (MySQLHelper bytesFromHexString: 'F105CDBAB4697B43'))]

]

Expand All @@ -139,7 +139,7 @@ MySQLBindParameterRealTest >> testStoreBinaryUnsignedFloat [
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements: (MySQLHelper bytesFromHexString: '00405040'))]
hasEqualElements: (MySQLHelper bytesFromHexString: '0000000000405040'))]

]

Expand All @@ -149,6 +149,6 @@ MySQLBindParameterRealTest >> testStoreBinaryUnsignedFraction [
ByteArray streamContents: [:strm |
theParam storeBinaryOn: strm.
self assert: (strm contents
hasEqualElements: (MySQLHelper bytesFromHexString: '00001140'))]
hasEqualElements: (MySQLHelper bytesFromHexString: '0000000000001140'))]

]
Loading