8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.342 2003/05/09 18:08:48 tgl Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.343 2003/05/12 16:48:17 tgl Exp $
12
12
*
13
13
* NOTES
14
14
* this is the "main" module of the postgres backend and
@@ -1265,13 +1265,9 @@ exec_bind_message(StringInfo input_message)
1265
1265
if (numParams > 0 )
1266
1266
{
1267
1267
bool isaborted = IsAbortedTransactionBlockState ();
1268
- StringInfoData pbuf ;
1269
1268
List * l ;
1270
1269
MemoryContext oldContext ;
1271
1270
1272
- /* Note that the string buffer lives in MessageContext */
1273
- initStringInfo (& pbuf );
1274
-
1275
1271
oldContext = MemoryContextSwitchTo (PortalGetHeapMemory (portal ));
1276
1272
1277
1273
params = (ParamListInfo )
@@ -1289,14 +1285,7 @@ exec_bind_message(StringInfo input_message)
1289
1285
1290
1286
if (!isNull )
1291
1287
{
1292
- /* Reset pbuf to empty, and insert raw data into it */
1293
- pbuf .len = 0 ;
1294
- pbuf .data [0 ] = '\0' ;
1295
- pbuf .cursor = 0 ;
1296
-
1297
- appendBinaryStringInfo (& pbuf ,
1298
- pq_getmsgbytes (input_message , plength ),
1299
- plength );
1288
+ const char * pvalue = pq_getmsgbytes (input_message , plength );
1300
1289
1301
1290
if (isaborted )
1302
1291
{
@@ -1306,6 +1295,8 @@ exec_bind_message(StringInfo input_message)
1306
1295
else
1307
1296
{
1308
1297
int16 pformat ;
1298
+ StringInfoData pbuf ;
1299
+ char csave ;
1309
1300
1310
1301
if (numPFormats > 1 )
1311
1302
pformat = pformats [i ];
@@ -1314,6 +1305,23 @@ exec_bind_message(StringInfo input_message)
1314
1305
else
1315
1306
pformat = 0 ; /* default = text */
1316
1307
1308
+ /*
1309
+ * Rather than copying data around, we just set up a phony
1310
+ * StringInfo pointing to the correct portion of the
1311
+ * message buffer. We assume we can scribble on the
1312
+ * message buffer so as to maintain the convention that
1313
+ * StringInfos have a trailing null. This is grotty but
1314
+ * is a big win when dealing with very large parameter
1315
+ * strings.
1316
+ */
1317
+ pbuf .data = (char * ) pvalue ;
1318
+ pbuf .maxlen = plength + 1 ;
1319
+ pbuf .len = plength ;
1320
+ pbuf .cursor = 0 ;
1321
+
1322
+ csave = pbuf .data [plength ];
1323
+ pbuf .data [plength ] = '\0' ;
1324
+
1317
1325
if (pformat == 0 )
1318
1326
{
1319
1327
Oid typInput ;
@@ -1322,11 +1330,8 @@ exec_bind_message(StringInfo input_message)
1322
1330
1323
1331
getTypeInputInfo (ptype , & typInput , & typElem );
1324
1332
/*
1325
- * Since stringinfo.c keeps a trailing null in
1326
- * place even for binary data, the contents of
1327
- * pbuf are a valid C string. We have to do
1328
- * encoding conversion before calling the typinput
1329
- * routine, though.
1333
+ * We have to do encoding conversion before calling
1334
+ * the typinput routine.
1330
1335
*/
1331
1336
pstring = (char * )
1332
1337
pg_client_to_server ((unsigned char * ) pbuf .data ,
@@ -1362,6 +1367,9 @@ exec_bind_message(StringInfo input_message)
1362
1367
{
1363
1368
elog (ERROR , "Invalid format code %d" , pformat );
1364
1369
}
1370
+
1371
+ /* Restore message buffer contents */
1372
+ pbuf .data [plength ] = csave ;
1365
1373
}
1366
1374
}
1367
1375
@@ -2524,7 +2532,7 @@ PostgresMain(int argc, char *argv[], const char *username)
2524
2532
if (!IsUnderPostmaster )
2525
2533
{
2526
2534
puts ("\nPOSTGRES backend interactive interface " );
2527
- puts ("$Revision: 1.342 $ $Date: 2003/05/09 18:08:48 $\n" );
2535
+ puts ("$Revision: 1.343 $ $Date: 2003/05/12 16:48:17 $\n" );
2528
2536
}
2529
2537
2530
2538
/*
0 commit comments