PostGIS  2.5.2dev-r@@SVN_REVISION@@

◆ getMaxFieldSize()

static int getMaxFieldSize ( PGconn *  conn,
char *  schema,
char *  table,
char *  fname 
)
static

Definition at line 523 of file pgsql2shp-core.c.

References _, free(), LWDEBUGF, malloc(), and window::res.

Referenced by ShpDumperOpenTable().

524 {
525  int size;
526  char *query;
527  PGresult *res;
528 
529  /*( this is ugly: don't forget counting the length */
530  /* when changing the fixed query strings ) */
531 
532  if ( schema )
533  {
534  query = (char *)malloc(strlen(fname)+strlen(table)+
535  strlen(schema)+46);
536  sprintf(query,
537  "select max(octet_length(\"%s\"::text)) from \"%s\".\"%s\"",
538  fname, schema, table);
539  }
540  else
541  {
542  query = (char *)malloc(strlen(fname)+strlen(table)+46);
543  sprintf(query,
544  "select max(octet_length(\"%s\"::text)) from \"%s\"",
545  fname, table);
546  }
547 
548  LWDEBUGF(4, "maxFieldLenQuery: %s\n", query);
549 
550  res = PQexec(conn, query);
551  free(query);
552  if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK )
553  {
554  printf( _("Querying for maximum field length: %s"),
555  PQerrorMessage(conn));
556  return -1;
557  }
558 
559  if (PQntuples(res) <= 0 )
560  {
561  PQclear(res);
562  return -1;
563  }
564  size = atoi(PQgetvalue(res, 0, 0));
565  PQclear(res);
566  return size;
567 }
tuple res
Definition: window.py:78
#define _(String)
Definition: shpcommon.h:24
static SHPCONNECTIONCONFIG * conn
void free(void *)
void * malloc(YYSIZE_T)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
Here is the call graph for this function:
Here is the caller graph for this function: