@@ -915,6 +915,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
915
915
char swallow ;
916
916
int id ;
917
917
SocketClass * sock = self -> sock ;
918
+ int maxlen ;
918
919
919
920
/* ERROR_MSG_LENGTH is suffcient */
920
921
static char msgbuffer [ERROR_MSG_LENGTH + 1 ];
@@ -926,7 +927,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
926
927
qlog ("conn=%u, query='%s'\n" , self , query );
927
928
928
929
/* Indicate that we are sending a query to the backend */
929
- if (strlen (query ) > MAX_MESSAGE_LEN - 2 )
930
+ maxlen = CC_get_max_query_len (self );
931
+ if (maxlen > 0 && maxlen < (int ) strlen (query ) + 1 )
930
932
{
931
933
self -> errornumber = CONNECTION_MSG_TOO_LONG ;
932
934
self -> errormsg = "Query string is too long" ;
@@ -1643,3 +1645,18 @@ CC_log_error(char *func, char *desc, ConnectionClass *self)
1643
1645
qlog ("INVALID CONNECTION HANDLE ERROR: func=%s, desc='%s'\n" , func , desc );
1644
1646
#undef PRN_NULLCHECK
1645
1647
}
1648
+
1649
+ int CC_get_max_query_len (const ConnectionClass * conn )
1650
+ {
1651
+ int value ;
1652
+ /* Long Queries in 7.0+ */
1653
+ if (PG_VERSION_GE (conn , 7.0 ))
1654
+ value = 0 /* MAX_STATEMENT_LEN */ ;
1655
+ /* Prior to 7.0 we used 2*BLCKSZ */
1656
+ else if (PG_VERSION_GE (conn , 6.5 ))
1657
+ value = (2 * BLCKSZ );
1658
+ else
1659
+ /* Prior to 6.5 we used BLCKSZ */
1660
+ value = BLCKSZ ;
1661
+ return value ;
1662
+ }
0 commit comments