1418{
1421 gint is_valid;
1422 gpointer gptr;
1423 GtkTreeIter iter;
1424 char *sql_form, *query, *connection_string, *progress_shapefile = NULL;
1426 PGresult *result;
1427
1428 int ret, i = 0;
1429 char *header, *footer, *record;
1430
1431
1433 if (!is_valid)
1434 {
1435 pgui_seterr(
_(
"ERROR: You haven't specified any files to import"));
1437
1438 return;
1439 }
1440
1441
1442
1444 {
1445 pgui_seterr(
_(
"Unable to connect to the database - please check your connection settings"));
1447
1448
1450
1452 return;
1453 }
1454
1455
1456
1457
1460
1461
1462 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";
1463
1464
1465 while (is_valid)
1466 {
1467 size_t sz;
1468
1471
1472
1473
1474 sz = strlen(sql_form) + strlen(loader_file_config->
schema) + strlen(loader_file_config->
table) + 1;
1476 snprintf(query, sz, sql_form, loader_file_config->
table, loader_file_config->
schema);
1478
1479
1482 {
1484
1485 PQclear(result);
1487
1488 return;
1489 }
1490
1491
1492 PQclear(result);
1494
1495
1497 }
1498
1499
1501
1502
1503
1505 while (is_valid)
1506 {
1507
1510
1511 pgui_logf(
"\n==============================");
1512 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);
1513
1514
1515
1516
1518
1519
1521
1522
1523 gtk_widget_set_sensitive(widget,
FALSE);
1524
1525
1526 while (gtk_events_pending())
1527 gtk_main_iteration();
1528
1529
1531
1532
1535 {
1537
1539 goto import_cleanup;
1540 }
1541
1542
1543 for (i = strlen(loader_file_config->
shp_file); i >= 0
1544 && loader_file_config->
shp_file[i - 1] !=
'\\' && loader_file_config->
shp_file[i - 1] !=
'/'; i--);
1545
1546 progress_shapefile =
malloc(strlen(loader_file_config->
shp_file));
1547 strcpy(progress_shapefile, &loader_file_config->
shp_file[i]);
1548
1549
1553 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(
progress), 0.0);
1555
1556
1558 {
1561 }
1562
1563
1566 {
1568
1570 goto import_cleanup;
1571 }
1572
1573
1574
1577
1578 if (!ret)
1579 goto import_cleanup;
1580
1581
1583 {
1585 int records_per_tick = (numrecords / 200) - 1;
1586
1587 if ( records_per_tick < 1 )
1588 records_per_tick = 1;
1589
1590
1592 {
1594
1596 {
1598
1600 goto import_cleanup;
1601 }
1602
1603
1606
1607 if (!ret)
1608 goto import_cleanup;
1609 }
1610
1611
1612 for (i = 0; i < numrecords &&
is_running; i++)
1613 {
1615
1616 switch (ret)
1617 {
1619
1622 else
1624
1625
1626 if (!ret)
1627 pgui_logf(
_(
"Import failed on record number %d"), i);
1628
1630 break;
1631
1633
1635 goto import_cleanup;
1636 break;
1637
1639
1641
1644 else
1646
1647
1648 if (!ret)
1649 pgui_logf(
_(
"Import failed on record number %d"), i);
1650
1652 break;
1653
1655
1656 break;
1657
1659
1660 break;
1661 }
1662
1663
1664 if ( i % records_per_tick == 0 )
1665 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(
progress), (
float)i / numrecords);
1666
1667
1668 while (gtk_events_pending())
1669 gtk_main_iteration();
1670 }
1671
1672
1674 {
1676 goto import_cleanup;
1677
1679 if (PQresultStatus(result) != PGRES_COMMAND_OK)
1680 {
1683 goto import_cleanup;
1684 }
1685 }
1686 }
1687
1688
1690 {
1691
1694 {
1696
1698 goto import_cleanup;
1699 }
1700
1701
1703 {
1704 gtk_label_set_text(GTK_LABEL(
label_progress),
_(
"Creating spatial index..."));
1705
1706
1707 while (gtk_events_pending())
1708 gtk_main_iteration();
1709 }
1710
1711
1714
1715 if (!ret)
1716 goto import_cleanup;
1717 }
1718
1719import_cleanup:
1720
1722
1723
1726
1727
1730 else
1732
1733
1735
1736
1737 if (progress_shapefile)
1738 free(progress_shapefile);
1739
1740
1742 }
1743
1744
1746
1747
1748 gtk_widget_set_sensitive(widget,
TRUE);
1749
1750
1751 gtk_widget_hide(widget);
1752 gtk_widget_show(widget);
1753
1754
1756
1757
1758 while (gtk_events_pending())
1759 gtk_main_iteration();
1760
1761
1762 free(connection_string);
1763
1764 return;
1765}
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 pgui_seterr(const char *fmt,...)
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 PGconn * pg_connection
static void pgui_raise_error_dialogue(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
static void pgui_logf(const char *fmt,...)
char message[SHPLOADERMSGLEN]