PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ validate_remote_loader_columns()

static int validate_remote_loader_columns ( SHPLOADERCONFIG config,
PGresult *  result 
)
static

Definition at line 1153 of file shp2pgsql-gui.c.

1154 {
1155  ExecStatusType status;
1156  SHPLOADERSTATE *state;
1157  int ntuples;
1158  char *pg_fieldname, *pg_fieldtype;
1159  int ret, i, j, found, response = SHPLOADEROK;
1160 
1161  /* Check the status of the result set */
1162  status = PQresultStatus(result);
1163  if (status == PGRES_TUPLES_OK)
1164  {
1165  ntuples = PQntuples(result);
1166 
1167  switch (config->opt)
1168  {
1169  case 'c':
1170  /* If we have a row matching the table given in the config, then it already exists */
1171  if (ntuples > 0)
1172  {
1173  pgui_seterr(_("ERROR: Create mode selected for existing table: %s.%s"), config->schema, config->table);
1174  response = SHPLOADERERR;
1175  }
1176  break;
1177 
1178  case 'p':
1179  /* If we have a row matching the table given in the config, then it already exists */
1180  if (ntuples > 0)
1181  {
1182  pgui_seterr(_("ERROR: Prepare mode selected for existing table: %s.%s"), config->schema, config->table);
1183  response = SHPLOADERERR;
1184  }
1185  break;
1186 
1187  case 'a':
1188  /* If we are trying to append to a table but it doesn't exist, emit a warning */
1189  if (ntuples == 0)
1190  {
1191  pgui_seterr(_("ERROR: Destination table %s.%s could not be found for appending"), config->schema, config->table);
1192  response = SHPLOADERERR;
1193  }
1194  else
1195  {
1196  /* If we have a row then lets do some simple column validation... */
1197  state = ShpLoaderCreate(config);
1198  ret = ShpLoaderOpenShape(state);
1199  if (ret != SHPLOADEROK)
1200  {
1201  pgui_logf(_("Warning: Could not load shapefile %s"), config->shp_file);
1202  ShpLoaderDestroy(state);
1203  }
1204 
1205  /* Find each column based upon its name and then validate type separately... */
1206  for (i = 0; i < state->num_fields; i++)
1207  {
1208  /* Make sure we find a column */
1209  found = 0;
1210  for (j = 0; j < ntuples; j++)
1211  {
1212  pg_fieldname = PQgetvalue(result, j, PQfnumber(result, "field"));
1213  pg_fieldtype = PQgetvalue(result, j, PQfnumber(result, "type"));
1214 
1215  if (!strcmp(state->field_names[i], pg_fieldname))
1216  {
1217  found = -1;
1218 
1219  ret = validate_shape_column_against_pg_column(state->types[i], pg_fieldtype);
1220  if (!ret)
1221  {
1222  pgui_logf(_("Warning: DBF Field '%s' is not compatible with PostgreSQL column '%s' in %s.%s"), state->field_names[i], pg_fieldname, config->schema, config->table);
1223  response = SHPLOADERWARN;
1224  }
1225  }
1226  }
1227 
1228  /* Flag a warning if we can't find a match */
1229  if (!found)
1230  {
1231  pgui_logf(_("Warning: DBF Field '%s' within file %s could not be matched to a column within table %s.%s"),
1232  state->field_names[i], config->shp_file, config->schema, config->table);
1233  response = SHPLOADERWARN;
1234  }
1235  }
1236 
1237  ShpLoaderDestroy(state);
1238  }
1239 
1240  break;
1241  }
1242  }
1243  else
1244  {
1245  pgui_seterr(_("ERROR: unable to process validation response from remote server"));
1246  response = SHPLOADERERR;
1247  }
1248 
1249  return response;
1250 }
void ShpLoaderDestroy(SHPLOADERSTATE *state)
int ShpLoaderOpenShape(SHPLOADERSTATE *state)
SHPLOADERSTATE * ShpLoaderCreate(SHPLOADERCONFIG *config)
#define SHPLOADERWARN
#define SHPLOADERERR
#define SHPLOADEROK
static void pgui_seterr(const char *fmt,...)
static int validate_shape_column_against_pg_column(int dbf_fieldtype, char *pg_fieldtype)
static void pgui_logf(const char *fmt,...)
#define _(String)
Definition: shpcommon.h:24
DBFFieldType * types

References _, shp_loader_state::field_names, shp_loader_state::num_fields, shp_loader_config::opt, pgui_logf(), pgui_seterr(), shp_loader_config::schema, shp_loader_config::shp_file, ShpLoaderCreate(), ShpLoaderDestroy(), SHPLOADERERR, SHPLOADEROK, ShpLoaderOpenShape(), SHPLOADERWARN, shp_loader_config::table, shp_loader_state::types, and validate_shape_column_against_pg_column().

Referenced by pgui_action_import().

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