From ad3611a4675161dd19cde74fcda27da731afc72b Mon Sep 17 00:00:00 2001 From: Todd Blanchard Date: Mon, 22 Jun 2020 01:29:07 -0700 Subject: [PATCH 1/4] Working with glorp and prefixed foreign keys. --- MySQL-Core/MySQLCommandQuery.class.st | 25 +++++++++- MySQL-Core/MysqlField.class.st | 20 +++++++- MySQL-Core/MysqlHelper.class.st | 2 +- MySQL-Core/MysqlQueryRowData.class.st | 66 +++++++++++++++++++++++++-- MySQL-Core/MysqlTypes.class.st | 9 ++++ 5 files changed, 116 insertions(+), 6 deletions(-) diff --git a/MySQL-Core/MySQLCommandQuery.class.st b/MySQL-Core/MySQLCommandQuery.class.st index cbb949d..e4303e0 100644 --- a/MySQL-Core/MySQLCommandQuery.class.st +++ b/MySQL-Core/MySQLCommandQuery.class.st @@ -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 | @@ -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; @@ -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 diff --git a/MySQL-Core/MysqlField.class.st b/MySQL-Core/MysqlField.class.st index 709b0b7..ab5c35e 100644 --- a/MySQL-Core/MysqlField.class.st +++ b/MySQL-Core/MysqlField.class.st @@ -28,6 +28,7 @@ Class { 'PrimaryKeyFlag', 'SetFlag', 'TimestampFlag', + 'TypeConverters', 'UniqueKeyFlag', 'UnsignedFlag', 'ZeroFillFlag' @@ -58,7 +59,16 @@ MySQLField class >> initBitMasksForFlags [ MySQLField class >> initialize [ "self initialize" self initBitMasksForFlags. - + self initializeTypeConverters. +] + +{ #category : #initialization } +MySQLField class >> initializeTypeConverters [ + TypeConverters ifNil: [ + TypeConverters := Dictionary new. + + + ] ] { #category : #accessing } @@ -140,3 +150,11 @@ MySQLField >> type [ ^ type ] + +{ #category : #'as yet unclassified' } +MySQLField >> typedValueFrom: aString [ + ^(TypeConverters + at: self type + ifAbsent: [ self error: ('No Type Converter Registered For Type: ', (self type asString)) ]) + value: aString +] diff --git a/MySQL-Core/MysqlHelper.class.st b/MySQL-Core/MysqlHelper.class.st index 659e6de..b5c9b82 100644 --- a/MySQL-Core/MysqlHelper.class.st +++ b/MySQL-Core/MysqlHelper.class.st @@ -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. ] diff --git a/MySQL-Core/MysqlQueryRowData.class.st b/MySQL-Core/MysqlQueryRowData.class.st index f05147c..9b6cf68 100644 --- a/MySQL-Core/MysqlQueryRowData.class.st +++ b/MySQL-Core/MysqlQueryRowData.class.st @@ -5,7 +5,8 @@ Class { #name : #MySQLQueryRowData, #superclass : #MySQLRowData, #instVars : [ - 'columns' + 'columns', + 'fields' ], #category : #'MySQL-Core-Packet-RowData' } @@ -26,14 +27,73 @@ MySQLQueryRowData >> columnCount: aCount [ ] +{ #category : #accessing } +MySQLQueryRowData >> fields [ + ^ fields +] + +{ #category : #accessing } +MySQLQueryRowData >> fields: anObject [ + fields := anObject +] + { #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']. + + + +] diff --git a/MySQL-Core/MysqlTypes.class.st b/MySQL-Core/MysqlTypes.class.st index 497b1cb..62675f9 100644 --- a/MySQL-Core/MysqlTypes.class.st +++ b/MySQL-Core/MysqlTypes.class.st @@ -15,6 +15,7 @@ Class { 'TypeFLOAT', 'TypeGEOMETRY', 'TypeINT24', + 'TypeJSON', 'TypeLONG', 'TypeLONGBLOB', 'TypeLONGLONG', @@ -75,6 +76,7 @@ MySQLTypes class >> initFieldTypes [ TypeFLOAT := 4. TypeGEOMETRY := 255. TypeINT24 := 9. + TypeJSON := 245. TypeLONG := 3. TypeLONGLONG := 8. TypeLONGBLOB := 251. @@ -97,6 +99,7 @@ MySQLTypes class >> initFieldTypes [ { #category : #'class initialization' } MySQLTypes class >> initialize [ + "MySQLTypes initialize" self initFieldTypes ] @@ -218,6 +221,12 @@ MySQLTypes class >> typeINT24 [ ] +{ #category : #'accessing - types' } +MySQLTypes class >> typeJSON [ + ^ TypeJSON + +] + { #category : #'accessing - types' } MySQLTypes class >> typeLONG [ ^ TypeLONG From 16b6cc8349ec3836695744b5bd003bfc21957d1e Mon Sep 17 00:00:00 2001 From: Todd Blanchard Date: Mon, 22 Jun 2020 03:25:28 -0700 Subject: [PATCH 2/4] Removed unused TypeConverters --- MySQL-Core/MysqlField.class.st | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/MySQL-Core/MysqlField.class.st b/MySQL-Core/MysqlField.class.st index ab5c35e..523a180 100644 --- a/MySQL-Core/MysqlField.class.st +++ b/MySQL-Core/MysqlField.class.st @@ -28,7 +28,6 @@ Class { 'PrimaryKeyFlag', 'SetFlag', 'TimestampFlag', - 'TypeConverters', 'UniqueKeyFlag', 'UnsignedFlag', 'ZeroFillFlag' @@ -58,17 +57,7 @@ MySQLField class >> initBitMasksForFlags [ { #category : #initialization } MySQLField class >> initialize [ "self initialize" - self initBitMasksForFlags. - self initializeTypeConverters. -] - -{ #category : #initialization } -MySQLField class >> initializeTypeConverters [ - TypeConverters ifNil: [ - TypeConverters := Dictionary new. - - - ] + self initBitMasksForFlags ] { #category : #accessing } @@ -150,11 +139,3 @@ MySQLField >> type [ ^ type ] - -{ #category : #'as yet unclassified' } -MySQLField >> typedValueFrom: aString [ - ^(TypeConverters - at: self type - ifAbsent: [ self error: ('No Type Converter Registered For Type: ', (self type asString)) ]) - value: aString -] From af18233e6acd35490946128fbbe14bb9d08ddfd4 Mon Sep 17 00:00:00 2001 From: Todd Blanchard Date: Mon, 22 Jun 2020 09:29:25 -0700 Subject: [PATCH 3/4] Added column value access by ordinals --- MySQL-Core/MySQLBinaryRowData.class.st | 5 +++ MySQL-Core/MysqlQueryRowData.class.st | 5 +++ MySQL-Core/MysqlRowData.class.st | 55 ++++++++++++++++++++++++++ MySQL-Core/MysqlStringRowData.class.st | 6 +++ 4 files changed, 71 insertions(+) diff --git a/MySQL-Core/MySQLBinaryRowData.class.st b/MySQL-Core/MySQLBinaryRowData.class.st index 5355e19..f076bb1 100644 --- a/MySQL-Core/MySQLBinaryRowData.class.st +++ b/MySQL-Core/MySQLBinaryRowData.class.st @@ -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 diff --git a/MySQL-Core/MysqlQueryRowData.class.st b/MySQL-Core/MysqlQueryRowData.class.st index 9b6cf68..88322b2 100644 --- a/MySQL-Core/MysqlQueryRowData.class.st +++ b/MySQL-Core/MysqlQueryRowData.class.st @@ -37,6 +37,11 @@ MySQLQueryRowData >> fields: anObject [ fields := anObject ] +{ #category : #accessing } +MySQLQueryRowData >> last [ + ^ columns atIndex: (columns size) +] + { #category : #parsing } MySQLQueryRowData >> parse [ | indx value field | diff --git a/MySQL-Core/MysqlRowData.class.st b/MySQL-Core/MysqlRowData.class.st index 063b5be..34a4f08 100644 --- a/MySQL-Core/MysqlRowData.class.st +++ b/MySQL-Core/MysqlRowData.class.st @@ -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 +] diff --git a/MySQL-Core/MysqlStringRowData.class.st b/MySQL-Core/MysqlStringRowData.class.st index 9794591..512bee3 100644 --- a/MySQL-Core/MysqlStringRowData.class.st +++ b/MySQL-Core/MysqlStringRowData.class.st @@ -16,6 +16,12 @@ MySQLStringRowData >> atIndex: indx [ ] +{ #category : #accessing } +MySQLStringRowData >> last [ + ^ self atIndex: (columnStrings size) + +] + { #category : #parsing } MySQLStringRowData >> parse [ super parse. From fb507d8aaaf60d7819c702c943feb8c7c9eb9358 Mon Sep 17 00:00:00 2001 From: Todd Blanchard Date: Mon, 22 Jun 2020 13:23:18 -0700 Subject: [PATCH 4/4] Added glorp target and NeoJSON dependencies since it is required to handle json data type --- BaselineOfMySQL/BaselineOfMySQL.class.st | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/BaselineOfMySQL/BaselineOfMySQL.class.st b/BaselineOfMySQL/BaselineOfMySQL.class.st index 407e378..21ce725 100644 --- a/BaselineOfMySQL/BaselineOfMySQL.class.st +++ b/BaselineOfMySQL/BaselineOfMySQL.class.st @@ -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 }