@@ -19,6 +19,8 @@ var Connection = function(config) {
19
19
this . parsedStatements = { } ;
20
20
this . writer = new Writer ( ) ;
21
21
this . ssl = config . ssl || false ;
22
+ this . longNameI = 0 ;
23
+ this . longNameMap = { } ;
22
24
this . _ending = false ;
23
25
this . _mode = TEXT_MODE ;
24
26
this . _emitMessage = false ;
@@ -189,6 +191,15 @@ Connection.prototype.query = function(text) {
189
191
this . stream . write ( this . writer . addCString ( text ) . flush ( 0x51 ) ) ;
190
192
} ;
191
193
194
+ Connection . prototype . getShortName = function ( longName ) {
195
+ var shortName = this . longNameMap [ longName ] ;
196
+ if ( ! shortName ) {
197
+ shortName = '__node_pg_short_name_' + ( ++ this . longNameI ) + '__' ;
198
+ this . longNameMap [ longName ] = shortName ;
199
+ }
200
+ return shortName ;
201
+ } ;
202
+
192
203
//send parse message
193
204
//"more" === true to buffer the message until flush() is called
194
205
Connection . prototype . parse = function ( query , more ) {
@@ -198,12 +209,16 @@ Connection.prototype.parse = function(query, more) {
198
209
// types: ['int8', 'bool'] }
199
210
200
211
//normalize missing query names to allow for null
201
- query . name = query . name || '' ;
212
+ var query_name = query . name || '' ;
213
+ //shorten long (>63 character) names
214
+ if ( query_name . length > 63 ) {
215
+ query_name = this . getShortName ( query_name ) ;
216
+ }
202
217
//normalize null type array
203
218
query . types = query . types || [ ] ;
204
219
var len = query . types . length ;
205
220
var buffer = this . writer
206
- . addCString ( query . name ) //name of query
221
+ . addCString ( query_name ) //name of query
207
222
. addCString ( query . text ) //actual query text
208
223
. addInt16 ( len ) ;
209
224
for ( var i = 0 ; i < len ; i ++ ) {
@@ -220,7 +235,11 @@ Connection.prototype.bind = function(config, more) {
220
235
//normalize config
221
236
config = config || { } ;
222
237
config . portal = config . portal || '' ;
223
- config . statement = config . statement || '' ;
238
+ var config_statement = config . statement || '' ;
239
+ //shorten long (>63 character) names
240
+ if ( config_statement . length > 63 ) {
241
+ config_statement = this . getShortName ( config_statement ) ;
242
+ }
224
243
config . binary = config . binary || false ;
225
244
var values = config . values || [ ] ;
226
245
var len = values . length ;
@@ -229,7 +248,7 @@ Connection.prototype.bind = function(config, more) {
229
248
useBinary |= values [ j ] instanceof Buffer ;
230
249
var buffer = this . writer
231
250
. addCString ( config . portal )
232
- . addCString ( config . statement ) ;
251
+ . addCString ( config_statement ) ;
233
252
if ( ! useBinary )
234
253
buffer . addInt16 ( 0 ) ;
235
254
else {
0 commit comments