PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ validate_remote_loader_columns()

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

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

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