Skip to content

Commit

Permalink
Fix issue 1: Timestamp conversion fail with legacy streams
Browse files Browse the repository at this point in the history
  • Loading branch information
nrgiii committed Oct 27, 2021
1 parent 04974ea commit c3d7a62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/GemConnectForPostgres_Tests_methods.gs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ PostgresTestCase sqlForCreateTableNamed: 'table1' columnTypes: { 'character(3)'
"

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws
nextPutAll: 'CREATE TABLE ';
nextPutAll: aName;
Expand Down Expand Up @@ -477,7 +477,7 @@ PostgresTestCase sqlForDeleteFromTable: 'table1' column: 'column1' value: 'abc'
"

|ws|
ws := WriteStream on: String new.
ws := AppendStream on: String new.
^ ws nextPutAll: 'DELETE FROM ' ;
nextPutAll: aName ;
nextPutAll: ' WHERE ';
Expand Down Expand Up @@ -511,7 +511,7 @@ PostgresTestCase sqlForInsertValue: 'abc' intoTableNamed: 'table1'
"

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
^ ws
nextPutAll: 'INSERT INTO ';
nextPutAll: aName;
Expand All @@ -528,7 +528,7 @@ PostgresTestCase sqlForInsertValue: 'abc' intoTableNamed: 'table1'
"

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws
nextPutAll: 'INSERT INTO ';
nextPutAll: aName;
Expand Down Expand Up @@ -572,7 +572,7 @@ PostgresTestCase sqlForUpdateTable: 'table1' column: 'column1' oldValue: 'abc' n
"

|ws|
ws := WriteStream on: String new.
ws := AppendStream on: String new.
^ ws nextPutAll: 'UPDATE ' ;
nextPutAll: aName ;
nextPutAll: ' SET ';
Expand Down Expand Up @@ -1002,7 +1002,7 @@ method: PostgresTestCase
tableNameExists: aTableName

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws nextPutAll: 'SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = ';
nextPut: $' ;
nextPutAll: aTableName ;
Expand Down
18 changes: 9 additions & 9 deletions src/GemConnectForPostgres_methods.gs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ byteArrayToPostgresString: aByteArray escaped: isEscaped
"Convert a multi-byte string to code point literals understood by Postgres."

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws
nextPutAll: '\x';
nextPutAll: aByteArray asHexString .
Expand Down Expand Up @@ -63,7 +63,7 @@ U&'\+xxxxxx'
"
^ isEscaped ifTrue:[
| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws nextPutAll: 'CONCAT('.
1 to: aMbString size
do:
Expand Down Expand Up @@ -143,7 +143,7 @@ U&'\+xxxxxx'
"

| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws nextPutAll: 'CONCAT('.
1 to: aMbString size
do:
Expand Down Expand Up @@ -197,7 +197,7 @@ U&'\+xxxxxx'
^isEscaped
ifTrue:
[| ws |
ws := WriteStream on: String new.
ws := AppendStream on: String new.
ws nextPutAll: 'CONCAT('.
1 to: aMbString size
do:
Expand Down Expand Up @@ -518,7 +518,7 @@ postgresBinDirectory
"Derive the bin directory from the library path"
"GsLibpq postgresBinDirectory"

^((ReadStream on: self libraryPath) upToAll: '/lib/') addAll: '/bin/' ; yourself
^((ReadStreamPortable on: self libraryPath) upToAll: '/lib/') addAll: '/bin/' ; yourself
%
category: 'Read Me'
classmethod: GsLibpq
Expand Down Expand Up @@ -2839,7 +2839,7 @@ createInstanceOf: aClass fromFloatString: aString
"This code is needed to make Postgres 'money' type map correctly to ScaledDecimal. The $$ and $, characters need to be removed"

| rs str |
rs := ReadStream on: aString.
rs := ReadStreamPortable on: aString.
rs skipSeparators.
rs peek == $$
ifTrue: "We have a currency "
Expand Down Expand Up @@ -2921,7 +2921,7 @@ GsPostgresResult dateAndTimeFromTimestampTz: '2017-08-25 04:50:00-07'
| rs year month day hour minute second tzoffset sign negate haveMicro micro |
negate := false.
tzoffset := 0.
rs := ReadStream on: aString.
rs := ReadStreamPortable on: aString.
year := (rs upTo: $-) asInteger.
month := (rs upTo: $-) asInteger.
day := (rs upTo: Character space) asInteger.
Expand Down Expand Up @@ -2970,7 +2970,7 @@ GsPostgresResult dateTimeFromTimestampDiscardTz: '2017-08-25 04:50:12.222-07'

| rs year month day hour minute second ms tmp haveMs |
haveMs := false.
rs := ReadStream on: aString.
rs := ReadStreamPortable on: aString.
year := (rs upTo: $-) asInteger.
month := (rs upTo: $-) asInteger.
day := (rs upTo: Character space) asInteger.
Expand Down Expand Up @@ -3341,7 +3341,7 @@ timeFromPostgresTimeString: aString
Note: Postgres times with timezones are not supported and the timezone is discarded."

| rs secs micro |
rs := ReadStream on: aString.
rs := ReadStreamPortable on: aString.
secs :=(rs upTo: $: ) asInteger * 3600. "hours"
secs := secs + ((rs upTo: $: ) asInteger * 60). "minutes"
"Stop at $+ or $- which is the start of the time zone offset, if any. Otherwise read to the end to get the second"
Expand Down

0 comments on commit c3d7a62

Please sign in to comment.