Skip to content

Commit

Permalink
Merge pull request #11 from tblanchard/glorp
Browse files Browse the repository at this point in the history
Improve glorp interoperability
  • Loading branch information
tblanchard authored Jun 25, 2020
2 parents fa2b74d + fb507d8 commit a32d8c4
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 12 deletions.
17 changes: 12 additions & 5 deletions BaselineOfMySQL/BaselineOfMySQL.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@ BaselineOfMySQL >> baseline: spec [
do: [
spec blessing: #baseline.

"Dependencies"
spec
baseline: 'NeoJSON' with: [ spec repository: 'github://svenvc/NeoJSON:master/repository' ];
baseline: 'ZTimestamp' with: [ spec repository: 'github://svenvc/ztimestamp:master/repository' ];
baseline: 'Glorp' with: [ spec repository: 'github://pharo-rdbms/glorp:master/'].
"Packages"
spec
package: 'MySQL-Core';
package: 'MySQL-Core' with: [ spec requires: #('NeoJSON' 'ZTimestamp') ];
package: 'MySQL-Glorp' with: [ spec requires: #('MySQL-Core' 'Glorp') ];
package: 'MySQL-Core-Tests' with: [ spec requires: #('MySQL-Core') ];
package: 'MySQL-Core-Tests-Integration' with: [ spec requires: #('MySQL-Core-Tests') ].

"Groups"
spec
group: 'Core' with: #('MySQL-Core');
group: 'Tests' with: #('MySQL-Core-Tests' 'MySQL-Core-Tests-Integration');
group: 'all' with: #('Core' 'Tests');
group: 'default' with: #('all')].
group: 'default' with: #('all');
group: 'core' with: #('MySQL-Core');
group: 'glorp' with: #('MySQL-Glorp');
group: 'all' with: #('MySQL-Core' 'MySQL-Core-Tests' 'MySQL-Core-Tests-Integration')
].
]

{ #category : #accessing }
Expand Down
5 changes: 5 additions & 0 deletions MySQL-Core/MySQLBinaryRowData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ MySQLBinaryRowData >> isColumnNullAt: index [

]

{ #category : #accessing }
MySQLBinaryRowData >> last [
^ self atIndex: (columnValues size)
]

{ #category : #accessing }
MySQLBinaryRowData >> nullBitMap: byteArray [ "primarily for testing"
nullBitMap := byteArray
Expand Down
25 changes: 24 additions & 1 deletion MySQL-Core/MySQLCommandQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ MySQLCommandQuery >> readOneRow: fieldCount [

]

{ #category : #reading }
MySQLCommandQuery >> readOneRow: fieldCount fields: fields [
| row |
row := MySQLQueryRowData new fields: fields; yourself.
row columnCount: fieldCount.
row read: session read.
^ row

]

{ #category : #reading }
MySQLCommandQuery >> readResponse [
| resp |
Expand All @@ -84,7 +94,7 @@ MySQLCommandQuery >> readResult [
ifFalse: [ resultSetHdr := self readRsHeader ].
fields := self readFields.
fieldsEof := self readEof.
rows := self readRowData: resultSetHdr fieldCount.
rows := self readRowData: resultSetHdr fieldCount fields: fields.
rowsEof := self readEof.
^ MySQLResultSet new
header: resultSetHdr;
Expand All @@ -109,6 +119,19 @@ MySQLCommandQuery >> readRowData: fieldCount [

]

{ #category : #reading }
MySQLCommandQuery >> readRowData: fieldCount fields: fields [
| respRows row |
respRows := OrderedCollection new.
[self gotEof] whileFalse: [
"Read each field and save it"
row := self readOneRow: fieldCount fields: fields.
respRows add: row].

^ respRows asArray

]

{ #category : #reading }
MySQLCommandQuery >> readRsHeader [
^ MySQLResultSetHeader from: session read
Expand Down
3 changes: 1 addition & 2 deletions MySQL-Core/MysqlField.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ MySQLField class >> initBitMasksForFlags [
{ #category : #initialization }
MySQLField class >> initialize [
"self initialize"
self initBitMasksForFlags.

self initBitMasksForFlags
]

{ #category : #accessing }
Expand Down
2 changes: 1 addition & 1 deletion MySQL-Core/MysqlHelper.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ MySQLHelper class >> decodeLcsFrom: aStream [
"parses length coded string"
| len |
len := self decodeLcbFrom: aStream.
len = -1 ifTrue: [^ 'NULL'].
len = -1 ifTrue: [^ nil].
^ aStream next: len.

]
Expand Down
71 changes: 68 additions & 3 deletions MySQL-Core/MysqlQueryRowData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Class {
#name : #MySQLQueryRowData,
#superclass : #MySQLRowData,
#instVars : [
'columns'
'columns',
'fields'
],
#category : #'MySQL-Core-Packet-RowData'
}
Expand All @@ -26,14 +27,78 @@ MySQLQueryRowData >> columnCount: aCount [

]

{ #category : #accessing }
MySQLQueryRowData >> fields [
^ fields
]

{ #category : #accessing }
MySQLQueryRowData >> fields: anObject [
fields := anObject
]

{ #category : #accessing }
MySQLQueryRowData >> last [
^ columns atIndex: (columns size)
]

{ #category : #parsing }
MySQLQueryRowData >> parse [
|indx value |
| indx value field |

indx := 1.
[inStream atEnd] whileFalse: [
value := (self decodeLcsFrom: inStream) asString.
field := fields at: indx.
value := (self readColumnFrom: inStream perDescrption: field).
columns at: indx put: value.
indx := indx + 1].

]

{ #category : #parsing }
MySQLQueryRowData >> readColumnFrom: aStream perDescrption: columnDescr [
| string |
string := (self decodeLcsFrom: aStream) ifNotNil: [:s | s asString] ifNil: [^nil].
^columnDescr type
caseOf: {
[MySQLTypes typeTINY]->[string asInteger].
[MySQLTypes typeSHORT]->[string asInteger].
[MySQLTypes typeINT24]->[string asInteger].
[MySQLTypes typeLONG]->[string asInteger].
[MySQLTypes typeLONGLONG]->[string asInteger].

[MySQLTypes typeFLOAT]->[string asNumber].
[MySQLTypes typeDOUBLE]->[string asNumber].
[MySQLTypes typeDECIMAL]->[ScaledDecimal readFrom: string].
[MySQLTypes typeNEWDECIMAL]->[ScaledDecimal readFrom: string].

[MySQLTypes typeSTRING]->[string].
[MySQLTypes typeVARCHAR]->[string].
[MySQLTypes typeVARSTRING]->[string].

[MySQLTypes typeTIME]->[Time fromString: string].
[MySQLTypes typeDATE]->[Date fromString: string].
[MySQLTypes typeDATETIME]->[DateAndTime fromString: string].
[MySQLTypes typeTIMESTAMP]->[DateAndTime fromString: string].
[MySQLTypes typeYEAR]->[string asInteger].
[MySQLTypes typeNEWDATE]->[DateAndTime fromString: string].

[MySQLTypes typeTINYBLOB]->[string].
[MySQLTypes typeBLOB]->[string].
[MySQLTypes typeMEDIUMBLOB]->[string].
[MySQLTypes typeLONGBLOB]->[string].

[MySQLTypes typeJSON]->[NeoJSONReader fromString: string].

[MySQLTypes typeNULL]->[self shouldBeImplemented].

[MySQLTypes typeGEOMETRY]->[self shouldBeImplemented].
[MySQLTypes typeSET]->[self shouldBeImplemented].
[MySQLTypes typeENUM]->[self shouldBeImplemented].
[MySQLTypes typeBIT]->[string asInteger].
}
otherwise: [^ self error: 'Unknown mysql type'].



]
55 changes: 55 additions & 0 deletions MySQL-Core/MysqlRowData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,63 @@ MySQLRowData >> atIndex: indx [

]

{ #category : #accessing }
MySQLRowData >> eighth [
^self atIndex: 8
]

{ #category : #accessing }
MySQLRowData >> fifth [
^self atIndex: 5
]

{ #category : #accessing }
MySQLRowData >> first [
^self atIndex: 1
]

{ #category : #accessing }
MySQLRowData >> fourth [
^self atIndex: 4
]

{ #category : #accessing }
MySQLRowData >> last [
self subclassResponsibility
]

{ #category : #accessing }
MySQLRowData >> ninth [
^self atIndex: 9
]

{ #category : #parsing }
MySQLRowData >> parse [
self subclassResponsibility

]

{ #category : #accessing }
MySQLRowData >> second [
^self atIndex: 2
]

{ #category : #accessing }
MySQLRowData >> seventh [
^self atIndex: 7
]

{ #category : #accessing }
MySQLRowData >> sixth [
^self atIndex: 6
]

{ #category : #accessing }
MySQLRowData >> tenth [
^self atIndex: 10
]

{ #category : #accessing }
MySQLRowData >> third [
^self atIndex: 3
]
6 changes: 6 additions & 0 deletions MySQL-Core/MysqlStringRowData.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ MySQLStringRowData >> atIndex: indx [

]

{ #category : #accessing }
MySQLStringRowData >> last [
^ self atIndex: (columnStrings size)

]

{ #category : #parsing }
MySQLStringRowData >> parse [
super parse.
Expand Down
9 changes: 9 additions & 0 deletions MySQL-Core/MysqlTypes.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Class {
'TypeFLOAT',
'TypeGEOMETRY',
'TypeINT24',
'TypeJSON',
'TypeLONG',
'TypeLONGBLOB',
'TypeLONGLONG',
Expand Down Expand Up @@ -75,6 +76,7 @@ MySQLTypes class >> initFieldTypes [
TypeFLOAT := 4.
TypeGEOMETRY := 255.
TypeINT24 := 9.
TypeJSON := 245.
TypeLONG := 3.
TypeLONGLONG := 8.
TypeLONGBLOB := 251.
Expand All @@ -97,6 +99,7 @@ MySQLTypes class >> initFieldTypes [

{ #category : #'class initialization' }
MySQLTypes class >> initialize [
"MySQLTypes initialize"
self initFieldTypes

]
Expand Down Expand Up @@ -218,6 +221,12 @@ MySQLTypes class >> typeINT24 [

]

{ #category : #'accessing - types' }
MySQLTypes class >> typeJSON [
^ TypeJSON

]

{ #category : #'accessing - types' }
MySQLTypes class >> typeLONG [
^ TypeLONG
Expand Down

0 comments on commit a32d8c4

Please sign in to comment.