PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ getMaxFieldSize()

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

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

549 {
550  int size;
551  stringbuffer_t query;
552  PGresult *res;
553 
554  /*( this is ugly: don't forget counting the length */
555  /* when changing the fixed query strings ) */
556 
557  stringbuffer_init(&query);
558  if ( schema )
559  {
561  &query,
562  "select max(octet_length(\"%s\"::text)) from \"%s\".\"%s\"",
563  fname, schema, table);
564  }
565  else
566  {
568  &query,
569  "select max(octet_length(\"%s\"::text)) from \"%s\"",
570  fname, table);
571  }
572 
573  LWDEBUGF(4, "maxFieldLenQuery: %s\n", stringbuffer_getstring(&query));
574 
575  res = PQexec(conn, stringbuffer_getstring(&query));
576  stringbuffer_release(&query);
577  if ( ! res || PQresultStatus(res) != PGRES_TUPLES_OK )
578  {
579  printf( _("Querying for maximum field length: %s"),
580  PQerrorMessage(conn));
581  return -1;
582  }
583 
584  if (PQntuples(res) <= 0 )
585  {
586  PQclear(res);
587  return -1;
588  }
589  size = atoi(PQgetvalue(res, 0, 0));
590  PQclear(res);
591  return size;
592 }
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
tuple res
Definition: window.py:79
static SHPCONNECTIONCONFIG * conn
#define _(String)
Definition: shpcommon.h:24
void stringbuffer_release(stringbuffer_t *s)
Definition: stringbuffer.c:48
int stringbuffer_aprintf(stringbuffer_t *s, const char *fmt,...)
Appends a formatted string to the current string buffer, using the format and argument list provided.
Definition: stringbuffer.c:230
void stringbuffer_init(stringbuffer_t *s)
Definition: stringbuffer.c:54
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:113

References _, conn, LWDEBUGF, window::res, stringbuffer_aprintf(), stringbuffer_getstring(), stringbuffer_init(), and stringbuffer_release().

Referenced by ShpDumperOpenTable().

Here is the call graph for this function:
Here is the caller graph for this function: