@ -3033,9 +3033,8 @@ static char *
_complete_from_query ( int is_schema_query , const char * text , int state )
_complete_from_query ( int is_schema_query , const char * text , int state )
{
{
static int list_index ,
static int list_index ,
string _length;
byte _length;
static PGresult * result = NULL ;
static PGresult * result = NULL ;
/*
/*
* If this is the first time for this completion , we fetch a list of our
* If this is the first time for this completion , we fetch a list of our
* " things " from the backend .
* " things " from the backend .
@ -3046,9 +3045,18 @@ _complete_from_query(int is_schema_query, const char *text, int state)
char * e_text ;
char * e_text ;
char * e_info_charp ;
char * e_info_charp ;
char * e_info_charp2 ;
char * e_info_charp2 ;
const char * pstr = text ;
int char_length = 0 ;
list_index = 0 ;
list_index = 0 ;
string_length = strlen ( text ) ;
byte_length = strlen ( text ) ;
/* Count length as number of characters (not bytes), for passing to substring */
while ( * pstr )
{
char_length + + ;
pstr + = PQmblen ( pstr , pset . encoding ) ;
}
/* Free any prior result */
/* Free any prior result */
PQclear ( result ) ;
PQclear ( result ) ;
@ -3101,7 +3109,7 @@ _complete_from_query(int is_schema_query, const char *text, int state)
completion_squery - > selcondition ) ;
completion_squery - > selcondition ) ;
appendPQExpBuffer ( & query_buffer , " substring(%s,1,%d)='%s' " ,
appendPQExpBuffer ( & query_buffer , " substring(%s,1,%d)='%s' " ,
completion_squery - > result ,
completion_squery - > result ,
string _length, e_text ) ;
char _length, e_text ) ;
appendPQExpBuffer ( & query_buffer , " AND %s " ,
appendPQExpBuffer ( & query_buffer , " AND %s " ,
completion_squery - > viscondition ) ;
completion_squery - > viscondition ) ;
@ -3128,13 +3136,13 @@ _complete_from_query(int is_schema_query, const char *text, int state)
" SELECT pg_catalog.quote_ident(n.nspname) || '.' "
" SELECT pg_catalog.quote_ident(n.nspname) || '.' "
" FROM pg_catalog.pg_namespace n "
" FROM pg_catalog.pg_namespace n "
" WHERE substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d)='%s' " ,
" WHERE substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d)='%s' " ,
string _length, e_text ) ;
char _length, e_text ) ;
appendPQExpBuffer ( & query_buffer ,
appendPQExpBuffer ( & query_buffer ,
" AND (SELECT pg_catalog.count(*) "
" AND (SELECT pg_catalog.count(*) "
" FROM pg_catalog.pg_namespace "
" FROM pg_catalog.pg_namespace "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1 " ,
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) > 1 " ,
string _length, e_text ) ;
char _length, e_text ) ;
/*
/*
* Add in matching qualified names , but only if there is exactly
* Add in matching qualified names , but only if there is exactly
@ -3152,7 +3160,7 @@ _complete_from_query(int is_schema_query, const char *text, int state)
completion_squery - > selcondition ) ;
completion_squery - > selcondition ) ;
appendPQExpBuffer ( & query_buffer , " substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s' " ,
appendPQExpBuffer ( & query_buffer , " substring(pg_catalog.quote_ident(n.nspname) || '.' || %s,1,%d)='%s' " ,
qualresult ,
qualresult ,
string _length, e_text ) ;
char _length, e_text ) ;
/*
/*
* This condition exploits the single - matching - schema rule to
* This condition exploits the single - matching - schema rule to
@ -3161,13 +3169,13 @@ _complete_from_query(int is_schema_query, const char *text, int state)
appendPQExpBuffer ( & query_buffer ,
appendPQExpBuffer ( & query_buffer ,
" AND substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d) = "
" AND substring(pg_catalog.quote_ident(n.nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1) " ,
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(n.nspname))+1) " ,
string _length, e_text ) ;
char _length, e_text ) ;
appendPQExpBuffer ( & query_buffer ,
appendPQExpBuffer ( & query_buffer ,
" AND (SELECT pg_catalog.count(*) "
" AND (SELECT pg_catalog.count(*) "
" FROM pg_catalog.pg_namespace "
" FROM pg_catalog.pg_namespace "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" WHERE substring(pg_catalog.quote_ident(nspname) || '.',1,%d) = "
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1 " ,
" substring('%s',1,pg_catalog.length(pg_catalog.quote_ident(nspname))+1)) = 1 " ,
string _length, e_text ) ;
char _length, e_text ) ;
/* If an addon query was provided, use it */
/* If an addon query was provided, use it */
if ( completion_charp )
if ( completion_charp )
@ -3177,7 +3185,7 @@ _complete_from_query(int is_schema_query, const char *text, int state)
{
{
/* completion_charp is an sprintf-style format string */
/* completion_charp is an sprintf-style format string */
appendPQExpBuffer ( & query_buffer , completion_charp ,
appendPQExpBuffer ( & query_buffer , completion_charp ,
string _length, e_text ,
char _length, e_text ,
e_info_charp , e_info_charp ,
e_info_charp , e_info_charp ,
e_info_charp2 , e_info_charp2 ) ;
e_info_charp2 , e_info_charp2 ) ;
}
}
@ -3203,7 +3211,7 @@ _complete_from_query(int is_schema_query, const char *text, int state)
while ( list_index < PQntuples ( result ) & &
while ( list_index < PQntuples ( result ) & &
( item = PQgetvalue ( result , list_index + + , 0 ) ) )
( item = PQgetvalue ( result , list_index + + , 0 ) ) )
if ( pg_strncasecmp ( text , item , string _length) = = 0 )
if ( pg_strncasecmp ( text , item , byte _length) = = 0 )
return pg_strdup ( item ) ;
return pg_strdup ( item ) ;
}
}