1439{
1442 gint is_valid;
1443 gpointer gptr;
1444 GtkTreeIter iter;
1445 char *sql_form, *query, *connection_string, *progress_shapefile = NULL;
1448
1449 int ret, i = 0;
1450 char *header, *footer, *record;
1451
1452
1454 if (!is_valid)
1455 {
1456 pgui_seterr(
_(
"ERROR: You haven't specified any files to import"));
1458
1459 return;
1460 }
1461
1462
1463
1465 {
1466 pgui_seterr(
_(
"Unable to connect to the database - please check your connection settings"));
1468
1469
1471
1473 return;
1474 }
1475
1476
1477
1478
1481
1482
1483 sql_form = "SELECT a.attnum, a.attname AS field, t.typname AS type, a.attlen AS length, a.atttypmod AS precision FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n WHERE c.relname = '%s' AND n.nspname = '%s' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid AND c.relnamespace = n.oid ORDER BY a.attnum";
1484
1485
1486 while (is_valid)
1487 {
1488 size_t sz;
1489
1492
1493
1494
1495 sz = strlen(sql_form) + strlen(loader_file_config->
schema) + strlen(loader_file_config->
table) + 1;
1497 snprintf(query, sz, sql_form, loader_file_config->
table, loader_file_config->
schema);
1499
1500
1503 {
1505
1508
1509 return;
1510 }
1511
1512
1515
1516
1518 }
1519
1520
1522
1523
1524
1526 while (is_valid)
1527 {
1528
1531
1532 pgui_logf(
"\n==============================");
1533 pgui_logf(
"Importing with configuration: %s, %s, %s, %s, mode=%c, dump=%d, simple=%d, geography=%d, index=%d, shape=%d, srid=%d", loader_file_config->
table, loader_file_config->
schema, loader_file_config->
geo_col, loader_file_config->
shp_file, loader_file_config->
opt, loader_file_config->
dump_format, loader_file_config->
simple_geometries, loader_file_config->
geography, loader_file_config->
createindex, loader_file_config->
readshape, loader_file_config->
sr_id);
1534
1535
1536
1537
1539
1540
1542
1543
1544 gtk_widget_set_sensitive(widget,
FALSE);
1545
1546
1547 while (gtk_events_pending())
1548 gtk_main_iteration();
1549
1550
1552
1553
1556 {
1558
1560 goto import_cleanup;
1561 }
1562
1563
1564 for (i = strlen(loader_file_config->
shp_file); i >= 0
1565 && loader_file_config->
shp_file[i - 1] !=
'\\' && loader_file_config->
shp_file[i - 1] !=
'/'; i--);
1566
1567 progress_shapefile =
malloc(strlen(loader_file_config->
shp_file));
1568 strcpy(progress_shapefile, &loader_file_config->
shp_file[i]);
1569
1570
1574 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(
progress), 0.0);
1576
1577
1579 {
1582 }
1583
1584
1587 {
1589
1591 goto import_cleanup;
1592 }
1593
1594
1595
1598
1599 if (!ret)
1600 goto import_cleanup;
1601
1602
1604 {
1606 int records_per_tick = (numrecords / 200) - 1;
1607
1608 if ( records_per_tick < 1 )
1609 records_per_tick = 1;
1610
1611
1613 {
1615
1617 {
1619
1621 goto import_cleanup;
1622 }
1623
1624
1627
1628 if (!ret)
1629 goto import_cleanup;
1630 }
1631
1632
1633 for (i = 0; i < numrecords &&
is_running; i++)
1634 {
1636
1637 switch (ret)
1638 {
1640
1643 else
1645
1646
1647 if (!ret)
1648 pgui_logf(
_(
"Import failed on record number %d"), i);
1649
1651 break;
1652
1654
1656 goto import_cleanup;
1657 break;
1658
1660
1662
1665 else
1667
1668
1669 if (!ret)
1670 pgui_logf(
_(
"Import failed on record number %d"), i);
1671
1673 break;
1674
1676
1677 break;
1678
1680
1681 break;
1682 }
1683
1684
1685 if ( i % records_per_tick == 0 )
1686 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(
progress), (
float)i / numrecords);
1687
1688
1689 while (gtk_events_pending())
1690 gtk_main_iteration();
1691 }
1692
1693
1695 {
1697 goto import_cleanup;
1698
1700 if (PQresultStatus(
result) != PGRES_COMMAND_OK)
1701 {
1704 goto import_cleanup;
1705 }
1706 }
1707 }
1708
1709
1711 {
1712
1715 {
1717
1719 goto import_cleanup;
1720 }
1721
1722
1724 {
1725 gtk_label_set_text(GTK_LABEL(
label_progress),
_(
"Creating spatial index..."));
1726
1727
1728 while (gtk_events_pending())
1729 gtk_main_iteration();
1730 }
1731
1732
1735
1736 if (!ret)
1737 goto import_cleanup;
1738 }
1739
1740import_cleanup:
1741
1743
1744
1747
1748
1751 else
1753
1754
1756
1757
1758 if (progress_shapefile)
1759 free(progress_shapefile);
1760
1761
1763 }
1764
1765
1767
1768
1769 gtk_widget_set_sensitive(widget,
TRUE);
1770
1771
1772 gtk_widget_hide(widget);
1773 gtk_widget_show(widget);
1774
1775
1777
1778
1779 while (gtk_events_pending())
1780 gtk_main_iteration();
1781
1782
1783 free(connection_string);
1784
1785 return;
1786}
char result[OUT_DOUBLE_BUFFER_SIZE]
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *conn)
const char SHPAPI_CALL1 * SHPTypeName(int nSHPType);const char SHPAPI_CALL1(*) SHPPartTypeName(int nPartType
int ShpLoaderGetRecordCount(SHPLOADERSTATE *state)
void ShpLoaderDestroy(SHPLOADERSTATE *state)
SHPLOADERSTATE * ShpLoaderCreate(SHPLOADERCONFIG *config)
int ShpLoaderGetSQLCopyStatement(SHPLOADERSTATE *state, char **strheader)
int ShpLoaderOpenShape(SHPLOADERSTATE *state)
int ShpLoaderGenerateSQLRowStatement(SHPLOADERSTATE *state, int item, char **strrecord)
int ShpLoaderGetSQLFooter(SHPLOADERSTATE *state, char **strfooter)
int ShpLoaderGetSQLHeader(SHPLOADERSTATE *state, char **strheader)
#define SHPLOADERRECISNULL
#define SHPLOADERRECDELETED
static GtkWidget * label_progress
static GtkWidget * progress
static void static void static void static void pgui_seterr(const char *fmt,...) __attribute__((format(printf
static int pgui_copy_write(const char *line)
static volatile int is_running
static int validate_remote_loader_columns(SHPLOADERCONFIG *config, PGresult *result)
static int pgui_copy_end(const int rollback)
static void static void static void pgui_logf(const char *fmt,...) __attribute__((format(printf
static PGconn * pg_connection
static void pgui_raise_error_dialogue(void)
static void static void static void static void static void update_conn_ui_from_conn_config(void)
static int pgui_copy_start(const char *sql)
static GtkWidget * dialog_progress
static int connection_test(void)
GtkListStore * import_file_list_store
#define GUIMSG_LINE_MAXLEN
static int pgui_exec(const char *sql)
static SHPCONNECTIONCONFIG * conn
static GtkWidget * window_conn
char message[SHPLOADERMSGLEN]