1318         int gidfound = 0, i, j, ret, status;
 
 1320         char *quoted = NULL;
 
 1336                         "CREATE TEMP TABLE \"%s\" AS %s",
 
 1342                 if (PQresultStatus(
res) != PGRES_COMMAND_OK)
 
 1363                         "SELECT a.attname, a.atttypid, " 
 1364                 "a.atttypmod, a.attlen FROM " 
 1365                     "pg_attribute a, pg_class c, pg_namespace n WHERE " 
 1366                     "n.nspname = '%s' AND a.attrelid = c.oid AND " 
 1367                     "n.oid = c.relnamespace AND " 
 1368                     "a.atttypid != 0 AND " 
 1369                     "a.attnum > 0 AND c.relname = '%s'",
 
 1376                     "SELECT a.attname, a.atttypid, " 
 1377                     "a.atttypmod, a.attlen FROM " 
 1378                     "pg_attribute a, pg_class c WHERE " 
 1379                     "a.attrelid = c.oid and a.attnum > 0 AND " 
 1380                     "a.atttypid != 0 AND " 
 1381                     "c.relname = '%s' AND " 
 1382                     "pg_catalog.pg_table_is_visible(c.oid)",
 
 1391         if (PQresultStatus(
res) != PGRES_TUPLES_OK)
 
 1398         if (!PQntuples(
res))
 
 1414         if ( getenv(
"PGCLIENTENCODING") )
 
 1448         for (i = 0; i < PQntuples(
res); i++)
 
 1452                 int pgfieldtype, pgtypmod, pgfieldlen;
 
 1455                 int dbffieldtype, dbffieldsize, dbffielddecs;
 
 1458                 pgfieldname = PQgetvalue(
res, i, 0);
 
 1459                 pgfieldtype = atoi(PQgetvalue(
res, i, 1));
 
 1460                 pgtypmod = atoi(PQgetvalue(
res, i, 2));
 
 1461                 pgfieldlen = atoi(PQgetvalue(
res, i, 3));
 
 1492                 if (!strcmp(pgfieldname, 
"gid") )
 
 1514                 dbffieldname = 
malloc(11);
 
 1515                 strncpy(dbffieldname, ptr, 10);
 
 1516                 dbffieldname[10] = 
'\0';
 
 1525                                 strncpy(dbffieldname, mapped, 10);
 
 1526                                 dbffieldname[10] = 
'\0';
 
 1536                         if (!strncasecmp(dbffieldname, state->
dbffieldnames[j], 10))
 
 1538                                 sprintf(dbffieldname, 
"%.7s_%.2d", ptr, abs(tmpint) % 100);
 
 1548                         for (nameit = 0; nameit < strlen(dbffieldname); nameit++)
 
 1549                                 dbffieldname[nameit] = toupper(dbffieldname[nameit]);
 
 1553                 if (strcasecmp(dbffieldname, pgfieldname))
 
 1555                         snprintf(buf, 
sizeof(buf), 
_(
"Warning, field %s renamed to %s\n"), pgfieldname, dbffieldname);
 
 1569                 if (pgfieldtype == 21)
 
 1582                 else if (pgfieldtype == 23)
 
 1595                 else if (pgfieldtype == 20)
 
 1616                 else if (pgfieldtype == 700 || pgfieldtype == 701 || pgfieldtype == 1700)
 
 1626                 else if (pgfieldtype == 16)
 
 1636                 else if (pgfieldtype == 1082)
 
 1646                 else if (pgfieldtype == 1083 || pgfieldtype == 1266 || pgfieldtype == 1114 || pgfieldtype == 1184)
 
 1659                                 secondsize = pgtypmod + 1;
 
 1671                         if (pgfieldtype == 1083)
 
 1673                                 dbffieldsize = 8 + secondsize;
 
 1676                         else if (pgfieldtype == 1266)
 
 1678                                 dbffieldsize = 8 + secondsize + 9;
 
 1681                         else if (pgfieldtype == 1114)
 
 1683                                 dbffieldsize = 13 + 1 + 8 + secondsize;
 
 1686                         else if (pgfieldtype == 1184)
 
 1688                                 dbffieldsize = 13 + 1 + 8 + secondsize + 9;
 
 1698                 else if (pgfieldtype == 2950)
 
 1710                 else if ((pgfieldtype == 1042 || pgfieldtype == 1043) && pgtypmod != -1)
 
 1717                         dbffieldsize = pgtypmod - 4; 
 
 1722                 else if (dbffieldtype == -1)
 
 1730                         if (dbffieldsize == -1)
 
 1748                                 snprintf(buf, 
sizeof(buf), 
_(
"Warning: values of field '%s' exceeding maximum dbf field width (%d) " 
 1760                 LWDEBUGF(3, 
"DBF FIELD_NAME: %s, SIZE: %d\n", dbffieldname, dbffieldsize);
 
 1762                 if (dbffieldtype != 9)
 
 1765                         if (
DBFAddField(state->
dbf, dbffieldname, dbffieldtype, dbffieldsize, dbffielddecs) == -1)
 
 1767                                 snprintf(state->
message, 
SHPDUMPERMSGLEN, 
_(
"Error: field %s of type %d could not be created."), dbffieldname, dbffieldtype);
 
 1811                         snprintf(buf, 
sizeof(buf), 
_(
"No geometry column found.\nThe DBF file will be created but not the shx or shp files.\n"));
 
 1876 #ifndef WORDS_BIGENDIAN 
 1900                     " FROM \"%s\".\"%s\"",
 
 1925         res = PQexec(state->
conn, 
"BEGIN");
 
 1926         if (!
res || PQresultStatus(
res) != PGRES_COMMAND_OK)
 
 1939         if (!
res || PQresultStatus(
res) != PGRES_COMMAND_OK)
 
int SHPAPI_CALL DBFAddField(DBFHandle psDBF, const char *pszFieldName, DBFFieldType eType, int nWidth, int nDecimals)
DBFHandle SHPAPI_CALL DBFCreateEx(const char *pszFilename, const char *pszCodePage)
void SHPAPI_CALL DBFSetWriteEndOfFileChar(DBFHandle psDBF, int bWriteFlag)
#define LWDEBUGF(level, msg,...)
static int getMaxFieldSize(PGconn *conn, char *schema, char *table, char *fname)
static char * core_asprintf(const char *format,...) __attribute__((format(printf
static int getTableInfo(SHPDUMPERSTATE *state)
char * quote_identifier(const char *s)
#define MAX_DBF_FIELD_SIZE
SHPHandle SHPAPI_CALL SHPCreate(const char *pszShapeFile, int nShapeType)
char * encoding2codepage(const char *encoding)
int colmap_read(const char *filename, colmap *map, char *errbuf, size_t errbuflen)
Read the content of filename into a symbol map.
const char * colmap_dbf_by_pg(colmap *map, const char *pgname)
void stringbuffer_release(stringbuffer_t *s)
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.
void stringbuffer_init(stringbuffer_t *s)
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string.
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
char * column_map_filename
char message[SHPDUMPERMSGLEN]