PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ ShpDumperOpenTable()

int ShpDumperOpenTable ( SHPDUMPERSTATE state)

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

1310 {
1311  PGresult *res;
1312 
1313  char buf[256];
1314  int gidfound = 0, i, j, ret, status;
1315  stringbuffer_t sb;
1316 
1317  /* Open the column map if one was specified */
1318  if (state->config->column_map_filename)
1319  {
1320  ret = colmap_read(state->config->column_map_filename,
1321  &state->column_map, state->message, SHPDUMPERMSGLEN);
1322  if (!ret) return SHPDUMPERERR;
1323  }
1324 
1325  /* If a user-defined query has been specified, create and point the state to our new table */
1326  if (state->config->usrquery)
1327  {
1328  state->table = core_asprintf("__pgsql2shp%lu_tmp_table", (long)getpid());
1329  stringbuffer_init(&sb);
1331  "CREATE TEMP TABLE \"%s\" AS %s",
1332  state->table, state->config->usrquery);
1333  res = PQexec(state->conn, stringbuffer_getstring(&sb));
1334  stringbuffer_release(&sb);
1335 
1336  /* Execute the code to create the table */
1337  if (PQresultStatus(res) != PGRES_COMMAND_OK)
1338  {
1339  snprintf(state->message, SHPDUMPERMSGLEN, _("Error executing user query: %s"), PQresultErrorMessage(res));
1340  PQclear(res);
1341  return SHPDUMPERERR;
1342  }
1343  }
1344  else
1345  {
1346  /* Simply point the state to copies of the supplied schema and table */
1347  state->table = strdup(state->config->table);
1348  if (state->config->schema)
1349  state->schema = strdup(state->config->schema);
1350  }
1351 
1352  stringbuffer_init(&sb);
1353  /* Get the list of columns and their types for the selected table */
1354  if (state->schema)
1355  {
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'",
1364  state->schema,
1365  state->table);
1366  }
1367  else
1368  {
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)",
1377  state->table);
1378  }
1379 
1380  LWDEBUGF(3, "query is: %s\n", query);
1381 
1382  res = PQexec(state->conn, stringbuffer_getstring(&sb));
1383  stringbuffer_release(&sb);
1384 
1385  if (PQresultStatus(res) != PGRES_TUPLES_OK)
1386  {
1387  snprintf(state->message, SHPDUMPERMSGLEN, _("Error querying for attributes: %s"), PQresultErrorMessage(res));
1388  PQclear(res);
1389  return SHPDUMPERERR;
1390  }
1391 
1392  if (!PQntuples(res))
1393  {
1394  snprintf(state->message, SHPDUMPERMSGLEN, _("Table %s does not exist"), state->table);
1395  PQclear(res);
1396  return SHPDUMPERERR;
1397  }
1398 
1399  /* If a shapefile name was specified, use it. Otherwise simply use the table name. */
1400  if (state->config->shp_file != NULL)
1401  state->shp_file = state->config->shp_file;
1402  else
1403  state->shp_file = state->table;
1404 
1405  /* Create the dbf file: */
1406  /* If there's a user-specified encoding hanging around, try and use that. */
1407  /* Otherwise, just use UTF-8 encoding, since that's usually our client encoding. */
1408  if ( getenv("PGCLIENTENCODING") )
1409  {
1410  char *codepage = encoding2codepage(getenv("PGCLIENTENCODING"));
1411  state->dbf = DBFCreateEx(state->shp_file, codepage);
1412  }
1413  else
1414  {
1415  state->dbf = DBFCreateEx(state->shp_file, "UTF-8");
1416  }
1417 
1418  if (!state->dbf)
1419  {
1420  snprintf(state->message, SHPDUMPERMSGLEN, _("Could not create dbf file %s"), state->shp_file);
1421  return SHPDUMPERERR;
1422  }
1423 
1424  /* Mimic old behaviour and skip the EOF character (1A) */
1425  DBFSetWriteEndOfFileChar(state->dbf, 0);
1426 
1427  /*
1428  * Scan the result setting fields to be returned in mainscan
1429  * query, filling the type_ary, and creating .dbf and .shp files.
1430  */
1431  state->dbffieldnames = malloc(sizeof(char *) * PQntuples(res));
1432  state->dbffieldtypes = malloc(sizeof(int) * PQntuples(res));
1433  state->pgfieldnames = malloc(sizeof(char *) * PQntuples(res));
1434  state->pgfieldlens = malloc(sizeof(int) * PQntuples(res));
1435  state->pgfieldtypmods = malloc(sizeof(int) * PQntuples(res));
1436  state->fieldcount = 0;
1437  int tmpint = 1;
1438 
1439  for (i = 0; i < PQntuples(res); i++)
1440  {
1441  char *ptr;
1442 
1443  int pgfieldtype, pgtypmod, pgfieldlen;
1444  char *pgfieldname;
1445 
1446  int dbffieldtype, dbffieldsize, dbffielddecs;
1447  char *dbffieldname;
1448 
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));
1453  dbffieldtype = -1;
1454  dbffieldsize = 0;
1455  dbffielddecs = 0;
1456 
1457  /*
1458  * This is a geometry/geography column
1459  */
1460  if (pgfieldtype == state->geom_oid || pgfieldtype == state->geog_oid)
1461  {
1462  /* If no geometry/geography column has been found yet... */
1463  if (!state->geo_col_name)
1464  {
1465  /* If either no geo* column name was provided (in which case this is
1466  the first match) or we match the provided column name, we have
1467  found our geo* column */
1468  if (!state->config->geo_col_name || !strcmp(state->config->geo_col_name, pgfieldname))
1469  {
1470  dbffieldtype = 9;
1471 
1472  state->geo_col_name = strdup(pgfieldname);
1473  }
1474  }
1475  }
1476 
1477  /*
1478  * Everything else (non geometries) will be
1479  * a DBF attribute.
1480  */
1481 
1482  /* Skip gid (if not asked to do otherwise */
1483  if (!strcmp(pgfieldname, "gid") )
1484  {
1485  gidfound = 1;
1486 
1487  if (!state->config->includegid)
1488  continue;
1489  }
1490 
1491  /* Unescape any reserved column names */
1492  ptr = pgfieldname;
1493  if (!state->config->unescapedattrs)
1494  {
1495  if (*ptr == '_')
1496  ptr += 2;
1497  }
1498 
1499  /*
1500  * This needs special handling since both xmin and _xmin
1501  * becomes __xmin when escaped
1502  */
1503 
1504  /* Limit dbf field name to 10-digits */
1505  dbffieldname = malloc(11);
1506  strncpy(dbffieldname, ptr, 10);
1507  dbffieldname[10] = '\0';
1508 
1509  /* If a column map file has been passed in,
1510  * use this to create the dbf field name from
1511  * the PostgreSQL column name */
1512  {
1513  const char *mapped = colmap_dbf_by_pg(&state->column_map, pgfieldname);
1514  if (mapped)
1515  {
1516  strncpy(dbffieldname, mapped, 10);
1517  dbffieldname[10] = '\0';
1518  }
1519  }
1520 
1521  /*
1522  * make sure the fields all have unique names,
1523  */
1524  tmpint = 1;
1525  for (j = 0; j < state->fieldcount; j++)
1526  {
1527  if (!strncasecmp(dbffieldname, state->dbffieldnames[j], 10))
1528  {
1529  sprintf(dbffieldname, "%.7s_%.2d", ptr, abs(tmpint) % 100);
1530  tmpint++;
1531  continue;
1532  }
1533  }
1534 
1535  /* make UPPERCASE if keep_fieldname_case = 0 */
1536  if (!state->config->keep_fieldname_case)
1537  {
1538  size_t nameit;
1539  for (nameit = 0; nameit < strlen(dbffieldname); nameit++)
1540  dbffieldname[nameit] = toupper(dbffieldname[nameit]);
1541  }
1542 
1543  /* Issue warning if column has been renamed */
1544  if (strcasecmp(dbffieldname, pgfieldname))
1545  {
1546  snprintf(buf, sizeof(buf), _("Warning, field %s renamed to %s\n"), pgfieldname, dbffieldname);
1547  /* Note: we concatenate all warnings from the main loop as this is useful information */
1548  if (SHPDUMPERMSGLEN > (strlen(state->message) + 1))
1549  strncat(state->message, buf, SHPDUMPERMSGLEN - (strlen(state->message) + 1));
1550 
1551  ret = SHPDUMPERWARN;
1552  }
1553 
1554 
1555  /*
1556  * Find appropriate type of dbf attributes
1557  */
1558 
1559  /* int2 type */
1560  if (pgfieldtype == 21)
1561  {
1562  /*
1563  * Longest text representation for
1564  * an int2 type (16bit) is 6 bytes
1565  * (-32768)
1566  */
1567  dbffieldtype = FTInteger;
1568  dbffieldsize = 6;
1569  dbffielddecs = 0;
1570  }
1571 
1572  /* int4 type */
1573  else if (pgfieldtype == 23)
1574  {
1575  /*
1576  * Longest text representation for
1577  * an int4 type (32bit) is 11 bytes
1578  * (-2147483648)
1579  */
1580  dbffieldtype = FTInteger;
1581  dbffieldsize = 11;
1582  dbffielddecs = 0;
1583  }
1584 
1585  /* int8 type */
1586  else if (pgfieldtype == 20)
1587  {
1588  /*
1589  * Longest text representation for
1590  * an int8 type (64bit) is 20 bytes
1591  * (-9223372036854775808)
1592  */
1593  dbffieldtype = FTInteger;
1594  dbffieldsize = 19;
1595  dbffielddecs = 0;
1596  }
1597 
1598  /*
1599  * double or numeric types:
1600  * 700: float4
1601  * 701: float8
1602  * 1700: numeric
1603  *
1604  *
1605  * TODO: stricter handling of sizes
1606  */
1607  else if (pgfieldtype == 700 || pgfieldtype == 701 || pgfieldtype == 1700)
1608  {
1609  dbffieldtype = FTDouble;
1610  dbffieldsize = 32;
1611  dbffielddecs = 10;
1612  }
1613 
1614  /*
1615  * Boolean field, we use FTLogical
1616  */
1617  else if (pgfieldtype == 16)
1618  {
1619  dbffieldtype = FTLogical;
1620  dbffieldsize = 1;
1621  dbffielddecs = 0;
1622  }
1623 
1624  /*
1625  * Date field
1626  */
1627  else if (pgfieldtype == 1082)
1628  {
1629  dbffieldtype = FTDate;
1630  dbffieldsize = 8;
1631  dbffielddecs = 0;
1632  }
1633 
1634  /*
1635  * time, timetz, timestamp, or timestamptz field.
1636  */
1637  else if (pgfieldtype == 1083 || pgfieldtype == 1266 || pgfieldtype == 1114 || pgfieldtype == 1184)
1638  {
1639  int secondsize;
1640 
1641  switch (pgtypmod)
1642  {
1643  case -1:
1644  secondsize = 6 + 1;
1645  break;
1646  case 0:
1647  secondsize = 0;
1648  break;
1649  default:
1650  secondsize = pgtypmod + 1;
1651  break;
1652  }
1653 
1654  /* We assume the worst case scenario for all of these:
1655  * date = '5874897-12-31' = 13
1656  * date = '294276-11-20' = 12 (with --enable-interger-datetimes)
1657  * time = '00:00:00' = 8
1658  * zone = '+01:39:52' = 9 (see Europe/Helsinki around 1915)
1659  */
1660 
1661  /* time */
1662  if (pgfieldtype == 1083)
1663  {
1664  dbffieldsize = 8 + secondsize;
1665  }
1666  /* timetz */
1667  else if (pgfieldtype == 1266)
1668  {
1669  dbffieldsize = 8 + secondsize + 9;
1670  }
1671  /* timestamp */
1672  else if (pgfieldtype == 1114)
1673  {
1674  dbffieldsize = 13 + 1 + 8 + secondsize;
1675  }
1676  /* timestamptz */
1677  else if (pgfieldtype == 1184)
1678  {
1679  dbffieldsize = 13 + 1 + 8 + secondsize + 9;
1680  }
1681 
1682  dbffieldtype = FTString;
1683  dbffielddecs = 0;
1684  }
1685 
1686  /*
1687  * uuid type 36 bytes (12345678-9012-3456-7890-123456789012)
1688  */
1689  else if (pgfieldtype == 2950)
1690  {
1691  dbffieldtype = FTString;
1692  dbffieldsize = 36;
1693  dbffielddecs = 0;
1694  }
1695 
1696  /*
1697  * For variable-sized fields we know about, we use
1698  * the maximum allowed size.
1699  * 1042 is bpchar, 1043 is varchar
1700  */
1701  else if ((pgfieldtype == 1042 || pgfieldtype == 1043) && pgtypmod != -1)
1702  {
1703  /*
1704  * mod is maximum allowed size, including
1705  * header which contains *real* size.
1706  */
1707  dbffieldtype = FTString;
1708  dbffieldsize = pgtypmod - 4; /* 4 is header size */
1709  dbffielddecs = 0;
1710  }
1711 
1712  /* For all other valid non-geometry/geography fields... */
1713  else if (dbffieldtype == -1)
1714  {
1715  /*
1716  * For types we don't know anything about, all
1717  * we can do is query the table for the maximum field
1718  * size.
1719  */
1720  dbffieldsize = getMaxFieldSize(state->conn, state->schema, state->table, pgfieldname);
1721  if (dbffieldsize == -1)
1722  {
1723  free(dbffieldname);
1724  return 0;
1725  }
1726 
1727  if (!dbffieldsize)
1728  dbffieldsize = 32;
1729 
1730  /* might 0 be a good size ? */
1731 
1732  dbffieldtype = FTString;
1733  dbffielddecs = 0;
1734 
1735  /* Check to make sure the final field size isn't too large */
1736  if (dbffieldsize > MAX_DBF_FIELD_SIZE)
1737  {
1738  /* Note: we concatenate all warnings from the main loop as this is useful information */
1739  snprintf(buf, sizeof(buf), _("Warning: values of field '%s' exceeding maximum dbf field width (%d) "
1740  "will be truncated.\n"), dbffieldname, MAX_DBF_FIELD_SIZE);
1741 
1742  if (SHPDUMPERMSGLEN > (strlen(state->message) + 1))
1743  strncat(state->message, buf, SHPDUMPERMSGLEN - (strlen(state->message)+1));
1744 
1745  dbffieldsize = MAX_DBF_FIELD_SIZE;
1746 
1747  ret = SHPDUMPERWARN;
1748  }
1749  }
1750 
1751  LWDEBUGF(3, "DBF FIELD_NAME: %s, SIZE: %d\n", dbffieldname, dbffieldsize);
1752 
1753  if (dbffieldtype != 9)
1754  {
1755  /* Add the field to the DBF file */
1756  if (DBFAddField(state->dbf, dbffieldname, dbffieldtype, dbffieldsize, dbffielddecs) == -1)
1757  {
1758  snprintf(state->message, SHPDUMPERMSGLEN, _("Error: field %s of type %d could not be created."), dbffieldname, dbffieldtype);
1759 
1760  return SHPDUMPERERR;
1761  }
1762 
1763  /* Add the field information to our field arrays */
1764  state->dbffieldnames[state->fieldcount] = dbffieldname;
1765  state->dbffieldtypes[state->fieldcount] = dbffieldtype;
1766  state->pgfieldnames[state->fieldcount] = pgfieldname;
1767  state->pgfieldlens[state->fieldcount] = pgfieldlen;
1768  state->pgfieldtypmods[state->fieldcount] = pgtypmod;
1769 
1770  state->fieldcount++;
1771  }
1772  }
1773 
1774  /* Now we have generated the field lists, grab some info about the table */
1775  status = getTableInfo(state);
1776  if (status == SHPDUMPERERR)
1777  return SHPDUMPERERR;
1778 
1779  LWDEBUGF(3, "rows: %d\n", state->rowcount);
1780  LWDEBUGF(3, "shptype: %c\n", state->outtype);
1781  LWDEBUGF(3, "shpouttype: %d\n", state->outshptype);
1782 
1783  /* If we didn't find a geometry/geography column... */
1784  if (!state->geo_col_name)
1785  {
1786  if (state->config->geo_col_name)
1787  {
1788  /* A geo* column was specified, but not found */
1789  snprintf(state->message, SHPDUMPERMSGLEN, _("%s: no such attribute in table %s"), state->config->geo_col_name, state->table);
1790 
1791  return SHPDUMPERERR;
1792  }
1793  else
1794  {
1795  /* No geo* column specified so we can only create the DBF section -
1796  but let's issue a warning... */
1797  snprintf(buf, sizeof(buf), _("No geometry column found.\nThe DBF file will be created but not the shx or shp files.\n"));
1798  if (SHPDUMPERMSGLEN > (strlen(state->message) + 1))
1799  strncat(state->message, buf, SHPDUMPERMSGLEN - (strlen(state->message)+1));
1800 
1801  state->shp = NULL;
1802 
1803  ret = SHPDUMPERWARN;
1804  }
1805  }
1806  else
1807  {
1808  /* Since we have found a geo* column, open the shapefile */
1809  state->shp = SHPCreate(state->shp_file, state->outshptype);
1810  if (!state->shp)
1811  {
1812  snprintf(state->message, SHPDUMPERMSGLEN, _("Could not open shapefile %s!"), state->shp_file);
1813 
1814  return SHPDUMPERERR;
1815  }
1816  }
1817 
1818  /* Now we have the complete list of fieldnames, let's generate the SQL query. First let's make sure
1819  we reserve enough space for tables with lots of columns */
1820  j = 0;
1821 
1822  /*TODO: this really should be rewritten to use stringbuffer */
1823  for (i = 0; i < state->fieldcount; i++)
1824  j += strlen( state->pgfieldnames[i]) + 10; /*add extra space for the quotes to quote identify and any embedded quotes that may need escaping */
1825 
1826  stringbuffer_init(&sb);
1827 
1828  stringbuffer_append(&sb, "DECLARE cur ");
1829  if (state->config->binary)
1830  stringbuffer_append(&sb, "BINARY ");
1831 
1832  stringbuffer_append(&sb, "CURSOR FOR SELECT ");
1833 
1834  for (i = 0; i < state->fieldcount; i++)
1835  {
1836  /* Comma-separated column names */
1837  if (i > 0) {
1838  stringbuffer_append(&sb, ",");
1839  }
1840 
1841  if (state->config->binary) {
1843  "%s::text",
1844  quote_identifier(state->pgfieldnames[i]) );
1845  }
1846  else {
1847  stringbuffer_append(&sb,
1848  quote_identifier(state->pgfieldnames[i]) );
1849  }
1850  }
1851 
1852  /* If we found a valid geometry/geography column then use it */
1853  if (state->geo_col_name)
1854  {
1855  /* If this is the (only) column, no need for the initial comma */
1856  if (state->fieldcount > 0) {
1857  stringbuffer_append(&sb, ",");
1858  }
1859 
1860 #ifdef WORDS_BIGENDIAN
1861  if (state->pgis_major_version > 0) {
1863  "ST_asEWKB(ST_SetSRID(%s::geometry, 0), 'XDR') AS _geoX",
1864  quote_identifier(state->geo_col_name) );
1865  }
1866  else
1867  {
1869  "asbinary(%s::geometry, 'XDR') AS _geoX",
1870  quote_identifier(state->geo_col_name) );
1871  }
1872 #else
1873  if (state->pgis_major_version > 0)
1874  {
1876  "ST_AsEWKB(ST_SetSRID(%s::geometry, 0), 'NDR') AS _geoX",
1877  quote_identifier(state->geo_col_name) );
1878  }
1879  else
1880  {
1882  "asbinary(%s::geometry, 'NDR') AS _geoX",
1883  quote_identifier(state->geo_col_name) );
1884  }
1885 #endif
1886  }
1887 
1888  if (state->schema)
1889  {
1891  " FROM \"%s\".\"%s\"",
1892  state->schema, state->table);
1893  }
1894  else
1895  {
1897  " FROM \"%s\"",
1898  state->table);
1899  }
1900 
1901  /* Order by 'gid' (if found) */
1902  if (gidfound)
1903  {
1904  stringbuffer_append(&sb, " ORDER BY \"gid\"");
1905  }
1906 
1907  /* Now we've finished with the result set, we can dispose of it */
1908  PQclear(res);
1909 
1910  LWDEBUGF(3, "FINAL QUERY: %s\n", stringbuffer_getstring(&sb));
1911 
1912  /*
1913  * Begin the transaction
1914  * (a cursor can only be defined inside a transaction block)
1915  */
1916  res = PQexec(state->conn, "BEGIN");
1917  if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
1918  {
1919  snprintf(state->message, SHPDUMPERMSGLEN, _("Error starting transaction: %s"), PQresultErrorMessage(res));
1920  PQclear(res);
1921  return SHPDUMPERERR;
1922  }
1923 
1924  PQclear(res);
1925 
1926  /* Execute the main scan query */
1928  stringbuffer_release(&sb);
1929  res = PQexec(state->conn, state->main_scan_query);
1930  if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
1931  {
1932  snprintf(state->message, SHPDUMPERMSGLEN, _("Error executing main scan query: %s"), PQresultErrorMessage(res));
1933  PQclear(res);
1934  return SHPDUMPERERR;
1935  }
1936 
1937  PQclear(res);
1938 
1939  /* Setup initial scan state */
1940  state->currow = 0;
1941  state->curresrow = 0;
1942  state->currescount = 0;
1943  state->fetchres = NULL;
1944 
1945  /* Generate the fetch query */
1946  state->fetch_query = core_asprintf("FETCH %d FROM cur", state->config->fetchsize);
1947 
1948  return SHPDUMPEROK;
1949 }
int SHPAPI_CALL DBFAddField(DBFHandle psDBF, const char *pszFieldName, DBFFieldType eType, int nWidth, int nDecimals)
Definition: dbfopen.c:788
DBFHandle SHPAPI_CALL DBFCreateEx(const char *pszFilename, const char *pszCodePage)
Definition: dbfopen.c:662
void SHPAPI_CALL DBFSetWriteEndOfFileChar(DBFHandle psDBF, int bWriteFlag)
Definition: dbfopen.c:2297
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
void * malloc(YYSIZE_T)
void free(void *)
tuple res
Definition: window.py:79
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
#define SHPDUMPERMSGLEN
#define SHPDUMPEROK
#define SHPDUMPERERR
#define SHPDUMPERWARN
SHPHandle SHPAPI_CALL SHPCreate(const char *pszShapeFile, int nShapeType)
Definition: shpopen.c:979
@ FTDouble
Definition: shapefil.h:641
@ FTString
Definition: shapefil.h:639
@ FTLogical
Definition: shapefil.h:642
@ FTDate
Definition: shapefil.h:643
@ FTInteger
Definition: shapefil.h:640
char * encoding2codepage(const char *encoding)
Definition: shpcommon.c:347
int colmap_read(const char *filename, colmap *map, char *errbuf, size_t errbuflen)
Read the content of filename into a symbol map.
Definition: shpcommon.c:217
const char * colmap_dbf_by_pg(colmap *map, const char *pgname)
Definition: shpcommon.c:189
#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:247
void stringbuffer_init(stringbuffer_t *s)
Definition: stringbuffer.c:54
char * stringbuffer_getstringcopy(stringbuffer_t *s)
Returns a newly allocated string large enough to contain the current state of the string.
Definition: stringbuffer.c:133
const char * stringbuffer_getstring(stringbuffer_t *s)
Returns a reference to the internal string being managed by the stringbuffer.
Definition: stringbuffer.c:122
static void stringbuffer_append(stringbuffer_t *s, const char *a)
Append the specified string to the stringbuffer_t.
Definition: stringbuffer.h:105
char * column_map_filename
SHPDUMPERCONFIG * config
PGresult * fetchres
char message[SHPDUMPERMSGLEN]

References _, shp_dumper_config::binary, colmap_dbf_by_pg(), colmap_read(), shp_dumper_state::column_map, shp_dumper_config::column_map_filename, shp_dumper_state::config, shp_dumper_state::conn, core_asprintf(), shp_dumper_state::currescount, shp_dumper_state::curresrow, shp_dumper_state::currow, shp_dumper_state::dbf, DBFAddField(), DBFCreateEx(), shp_dumper_state::dbffieldnames, shp_dumper_state::dbffieldtypes, DBFSetWriteEndOfFileChar(), encoding2codepage(), shp_dumper_state::fetch_query, shp_dumper_state::fetchres, shp_dumper_config::fetchsize, shp_dumper_state::fieldcount, free(), FTDate, FTDouble, FTInteger, FTLogical, FTString, shp_dumper_config::geo_col_name, shp_dumper_state::geo_col_name, shp_dumper_state::geog_oid, shp_dumper_state::geom_oid, getMaxFieldSize(), getTableInfo(), shp_dumper_config::includegid, shp_dumper_config::keep_fieldname_case, LWDEBUGF, shp_dumper_state::main_scan_query, malloc(), MAX_DBF_FIELD_SIZE, shp_dumper_state::message, shp_dumper_state::outshptype, shp_dumper_state::outtype, shp_dumper_state::pgfieldlens, shp_dumper_state::pgfieldnames, shp_dumper_state::pgfieldtypmods, shp_dumper_state::pgis_major_version, quote_identifier(), window::res, shp_dumper_state::rowcount, shp_dumper_config::schema, shp_dumper_state::schema, shp_dumper_state::shp, shp_dumper_config::shp_file, shp_dumper_state::shp_file, SHPCreate(), SHPDUMPERERR, SHPDUMPERMSGLEN, SHPDUMPEROK, SHPDUMPERWARN, stringbuffer_append(), stringbuffer_aprintf(), stringbuffer_getstring(), stringbuffer_getstringcopy(), stringbuffer_init(), stringbuffer_release(), shp_dumper_config::table, shp_dumper_state::table, shp_dumper_config::unescapedattrs, and shp_dumper_config::usrquery.

Referenced by main(), and pgui_action_export().

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