1314 int gidfound = 0, i, j, ret, status;
1331 "CREATE TEMP TABLE \"%s\" AS %s",
1337 if (PQresultStatus(
res) != PGRES_COMMAND_OK)
1357 "SELECT a.attname, a.atttypid, "
1358 "a.atttypmod, a.attlen FROM "
1359 "pg_attribute a, pg_class c, pg_namespace n WHERE "
1360 "n.nspname = '%s' AND a.attrelid = c.oid AND "
1361 "n.oid = c.relnamespace AND "
1362 "a.atttypid != 0 AND "
1363 "a.attnum > 0 AND c.relname = '%s'",
1370 "SELECT a.attname, a.atttypid, "
1371 "a.atttypmod, a.attlen FROM "
1372 "pg_attribute a, pg_class c WHERE "
1373 "a.attrelid = c.oid and a.attnum > 0 AND "
1374 "a.atttypid != 0 AND "
1375 "c.relname = '%s' AND "
1376 "pg_catalog.pg_table_is_visible(c.oid)",
1380 LWDEBUGF(3,
"query is: %s\n", query);
1385 if (PQresultStatus(
res) != PGRES_TUPLES_OK)
1392 if (!PQntuples(
res))
1408 if ( getenv(
"PGCLIENTENCODING") )
1439 for (i = 0; i < PQntuples(
res); i++)
1443 int pgfieldtype, pgtypmod, pgfieldlen;
1446 int dbffieldtype, dbffieldsize, dbffielddecs;
1449 pgfieldname = PQgetvalue(
res, i, 0);
1450 pgfieldtype = atoi(PQgetvalue(
res, i, 1));
1451 pgtypmod = atoi(PQgetvalue(
res, i, 2));
1452 pgfieldlen = atoi(PQgetvalue(
res, i, 3));
1483 if (!strcmp(pgfieldname,
"gid") )
1505 dbffieldname =
malloc(11);
1506 strncpy(dbffieldname, ptr, 10);
1507 dbffieldname[10] =
'\0';
1516 strncpy(dbffieldname, mapped, 10);
1517 dbffieldname[10] =
'\0';
1527 if (!strncasecmp(dbffieldname, state->
dbffieldnames[j], 10))
1529 sprintf(dbffieldname,
"%.7s_%.2d", ptr, abs(tmpint) % 100);
1539 for (nameit = 0; nameit < strlen(dbffieldname); nameit++)
1540 dbffieldname[nameit] = toupper(dbffieldname[nameit]);
1544 if (strcasecmp(dbffieldname, pgfieldname))
1546 snprintf(buf,
sizeof(buf),
_(
"Warning, field %s renamed to %s\n"), pgfieldname, dbffieldname);
1560 if (pgfieldtype == 21)
1573 else if (pgfieldtype == 23)
1586 else if (pgfieldtype == 20)
1607 else if (pgfieldtype == 700 || pgfieldtype == 701 || pgfieldtype == 1700)
1617 else if (pgfieldtype == 16)
1627 else if (pgfieldtype == 1082)
1637 else if (pgfieldtype == 1083 || pgfieldtype == 1266 || pgfieldtype == 1114 || pgfieldtype == 1184)
1650 secondsize = pgtypmod + 1;
1662 if (pgfieldtype == 1083)
1664 dbffieldsize = 8 + secondsize;
1667 else if (pgfieldtype == 1266)
1669 dbffieldsize = 8 + secondsize + 9;
1672 else if (pgfieldtype == 1114)
1674 dbffieldsize = 13 + 1 + 8 + secondsize;
1677 else if (pgfieldtype == 1184)
1679 dbffieldsize = 13 + 1 + 8 + secondsize + 9;
1689 else if (pgfieldtype == 2950)
1701 else if ((pgfieldtype == 1042 || pgfieldtype == 1043) && pgtypmod != -1)
1708 dbffieldsize = pgtypmod - 4;
1713 else if (dbffieldtype == -1)
1721 if (dbffieldsize == -1)
1739 snprintf(buf,
sizeof(buf),
_(
"Warning: values of field '%s' exceeding maximum dbf field width (%d) "
1751 LWDEBUGF(3,
"DBF FIELD_NAME: %s, SIZE: %d\n", dbffieldname, dbffieldsize);
1753 if (dbffieldtype != 9)
1756 if (
DBFAddField(state->
dbf, dbffieldname, dbffieldtype, dbffieldsize, dbffielddecs) == -1)
1758 snprintf(state->
message,
SHPDUMPERMSGLEN,
_(
"Error: field %s of type %d could not be created."), dbffieldname, dbffieldtype);
1797 snprintf(buf,
sizeof(buf),
_(
"No geometry column found.\nThe DBF file will be created but not the shx or shp files.\n"));
1860 #ifdef WORDS_BIGENDIAN
1863 "ST_asEWKB(ST_SetSRID(%s::geometry, 0), 'XDR') AS _geoX",
1869 "asbinary(%s::geometry, 'XDR') AS _geoX",
1876 "ST_AsEWKB(ST_SetSRID(%s::geometry, 0), 'NDR') AS _geoX",
1882 "asbinary(%s::geometry, 'NDR') AS _geoX",
1891 " FROM \"%s\".\"%s\"",
1916 res = PQexec(state->
conn,
"BEGIN");
1917 if (!
res || PQresultStatus(
res) != PGRES_COMMAND_OK)
1930 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 int getTableInfo(SHPDUMPERSTATE *state)
char * quote_identifier(const char *s)
static char * core_asprintf(const char *format,...)
#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]