PostGIS  2.2.7dev-r@@SVN_REVISION@@
static int getMaxFieldSize ( PGconn *  conn,
char *  schema,
char *  table,
char *  fname 
)
static

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

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

Referenced by ShpDumperOpenTable().

523 {
524  int size;
525  char *query;
526  PGresult *res;
527 
528  /*( this is ugly: don't forget counting the length */
529  /* when changing the fixed query strings ) */
530 
531  if ( schema )
532  {
533  query = (char *)malloc(strlen(fname)+strlen(table)+
534  strlen(schema)+46);
535  sprintf(query,
536  "select max(octet_length(\"%s\"::text)) from \"%s\".\"%s\"",
537  fname, schema, table);
538  }
539  else
540  {
541  query = (char *)malloc(strlen(fname)+strlen(table)+46);
542  sprintf(query,
543  "select max(octet_length(\"%s\"::text)) from \"%s\"",
544  fname, table);
545  }
546 
547  LWDEBUGF(4, "maxFieldLenQuery: %s\n", query);
548 
549  res = PQexec(conn, query);
550  free(query);
551  if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK )
552  {
553  printf( _("Querying for maximum field length: %s"),
554  PQerrorMessage(conn));
555  return -1;
556  }
557 
558  if (PQntuples(res) <= 0 )
559  {
560  PQclear(res);
561  return -1;
562  }
563  size = atoi(PQgetvalue(res, 0, 0));
564  PQclear(res);
565  return size;
566 }
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:55

Here is the call graph for this function:

Here is the caller graph for this function: