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 1155 of file shp2pgsql-gui.c.

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