PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ add_overview_constraints()

static int add_overview_constraints ( const char *  ovschema,
const char *  ovtable,
const char *  ovcolumn,
const char *  schema,
const char *  table,
const char *  column,
const int  factor,
STRINGBUFFER buffer 
)
static

Definition at line 1244 of file raster2pgsql.c.

References _, append_sql_to_buffer(), chartrim(), MAXOVFACTOR, MINOVFACTOR, rtalloc(), rtdealloc(), rterror(), rtgdalraster::sql, and strreplace().

Referenced by process_rasters().

1249  {
1250  char *sql = NULL;
1251  uint32_t len = 0;
1252 
1253  char *_tmp = NULL;
1254 
1255  char *_ovschema = NULL;
1256  char *_ovtable = NULL;
1257  char *_ovcolumn = NULL;
1258 
1259  char *_schema = NULL;
1260  char *_table = NULL;
1261  char *_column = NULL;
1262 
1263  assert(ovtable != NULL);
1264  assert(ovcolumn != NULL);
1265  assert(table != NULL);
1266  assert(column != NULL);
1267  assert(factor >= MINOVFACTOR && factor <= MAXOVFACTOR);
1268 
1269  /* overview schema */
1270  if (ovschema != NULL) {
1271  _tmp = chartrim(ovschema, ".");
1272  _ovschema = chartrim(_tmp, "\"");
1273  rtdealloc(_tmp);
1274  _tmp = strreplace(_ovschema, "'", "''", NULL);
1275  rtdealloc(_ovschema);
1276  _ovschema = _tmp;
1277  }
1278 
1279  /* overview table */
1280  _tmp = chartrim(ovtable, "\"");
1281  _ovtable = strreplace(_tmp, "'", "''", NULL);
1282  rtdealloc(_tmp);
1283 
1284  /* overview column*/
1285  _tmp = chartrim(ovcolumn, "\"");
1286  _ovcolumn = strreplace(_tmp, "'", "''", NULL);
1287  rtdealloc(_tmp);
1288 
1289  /* schema */
1290  if (schema != NULL) {
1291  _tmp = chartrim(schema, ".");
1292  _schema = chartrim(_tmp, "\"");
1293  rtdealloc(_tmp);
1294  _tmp = strreplace(_schema, "'", "''", NULL);
1295  rtdealloc(_schema);
1296  _schema = _tmp;
1297  }
1298 
1299  /* table */
1300  _tmp = chartrim(table, "\"");
1301  _table = strreplace(_tmp, "'", "''", NULL);
1302  rtdealloc(_tmp);
1303 
1304  /* column */
1305  _tmp = chartrim(column, "\"");
1306  _column = strreplace(_tmp, "'", "''", NULL);
1307  rtdealloc(_tmp);
1308 
1309  len = strlen("SELECT AddOverviewConstraints('','','','','','',);") + 5;
1310  if (_ovschema != NULL)
1311  len += strlen(_ovschema);
1312  len += strlen(_ovtable);
1313  len += strlen(_ovcolumn);
1314  if (_schema != NULL)
1315  len += strlen(_schema);
1316  len += strlen(_table);
1317  len += strlen(_column);
1318 
1319  sql = rtalloc(sizeof(char) * len);
1320  if (sql == NULL) {
1321  rterror(_("add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
1322  return 0;
1323  }
1324  sprintf(sql, "SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
1325  (_ovschema != NULL ? _ovschema : ""),
1326  _ovtable,
1327  _ovcolumn,
1328  (_schema != NULL ? _schema : ""),
1329  _table,
1330  _column,
1331  factor
1332  );
1333 
1334  if (_ovschema != NULL)
1335  rtdealloc(_ovschema);
1336  rtdealloc(_ovtable);
1337  rtdealloc(_ovcolumn);
1338 
1339  if (_schema != NULL)
1340  rtdealloc(_schema);
1341  rtdealloc(_table);
1342  rtdealloc(_column);
1343 
1344  append_sql_to_buffer(buffer, sql);
1345 
1346  return 1;
1347 }
#define _(String)
Definition: shpcommon.h:24
static char * chartrim(const char *input, char *remove)
Definition: raster2pgsql.c:293
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
static char * strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
Definition: raster2pgsql.c:141
static int append_sql_to_buffer(STRINGBUFFER *buffer, const char *str)
Definition: raster2pgsql.c:822
#define MINOVFACTOR
Definition: raster2pgsql.h:58
void rtdealloc(void *mem)
Definition: rt_context.c:186
#define MAXOVFACTOR
Definition: raster2pgsql.h:59
Here is the call graph for this function:
Here is the caller graph for this function: