PostGIS  2.5.0beta1dev-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 1247 of file raster2pgsql.c.

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

Referenced by process_rasters().

1252  {
1253  char *sql = NULL;
1254  uint32_t len = 0;
1255 
1256  char *_tmp = NULL;
1257 
1258  char *_ovschema = NULL;
1259  char *_ovtable = NULL;
1260  char *_ovcolumn = NULL;
1261 
1262  char *_schema = NULL;
1263  char *_table = NULL;
1264  char *_column = NULL;
1265 
1266  assert(ovtable != NULL);
1267  assert(ovcolumn != NULL);
1268  assert(table != NULL);
1269  assert(column != NULL);
1270  assert(factor >= MINOVFACTOR && factor <= MAXOVFACTOR);
1271 
1272  /* overview schema */
1273  if (ovschema != NULL) {
1274  _tmp = chartrim(ovschema, ".");
1275  _ovschema = chartrim(_tmp, "\"");
1276  rtdealloc(_tmp);
1277  _tmp = strreplace(_ovschema, "'", "''", NULL);
1278  rtdealloc(_ovschema);
1279  _ovschema = _tmp;
1280  }
1281 
1282  /* overview table */
1283  _tmp = chartrim(ovtable, "\"");
1284  _ovtable = strreplace(_tmp, "'", "''", NULL);
1285  rtdealloc(_tmp);
1286 
1287  /* overview column*/
1288  _tmp = chartrim(ovcolumn, "\"");
1289  _ovcolumn = strreplace(_tmp, "'", "''", NULL);
1290  rtdealloc(_tmp);
1291 
1292  /* schema */
1293  if (schema != NULL) {
1294  _tmp = chartrim(schema, ".");
1295  _schema = chartrim(_tmp, "\"");
1296  rtdealloc(_tmp);
1297  _tmp = strreplace(_schema, "'", "''", NULL);
1298  rtdealloc(_schema);
1299  _schema = _tmp;
1300  }
1301 
1302  /* table */
1303  _tmp = chartrim(table, "\"");
1304  _table = strreplace(_tmp, "'", "''", NULL);
1305  rtdealloc(_tmp);
1306 
1307  /* column */
1308  _tmp = chartrim(column, "\"");
1309  _column = strreplace(_tmp, "'", "''", NULL);
1310  rtdealloc(_tmp);
1311 
1312  len = strlen("SELECT AddOverviewConstraints('','','','','','',);") + 5;
1313  if (_ovschema != NULL)
1314  len += strlen(_ovschema);
1315  len += strlen(_ovtable);
1316  len += strlen(_ovcolumn);
1317  if (_schema != NULL)
1318  len += strlen(_schema);
1319  len += strlen(_table);
1320  len += strlen(_column);
1321 
1322  sql = rtalloc(sizeof(char) * len);
1323  if (sql == NULL) {
1324  rterror(_("add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
1325  return 0;
1326  }
1327  sprintf(sql, "SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
1328  (_ovschema != NULL ? _ovschema : ""),
1329  _ovtable,
1330  _ovcolumn,
1331  (_schema != NULL ? _schema : ""),
1332  _table,
1333  _column,
1334  factor
1335  );
1336 
1337  if (_ovschema != NULL)
1338  rtdealloc(_ovschema);
1339  rtdealloc(_ovtable);
1340  rtdealloc(_ovcolumn);
1341 
1342  if (_schema != NULL)
1343  rtdealloc(_schema);
1344  rtdealloc(_table);
1345  rtdealloc(_column);
1346 
1347  append_sql_to_buffer(buffer, sql);
1348 
1349  return 1;
1350 }
#define _(String)
Definition: shpcommon.h:24
static char * chartrim(const char *input, char *remove)
Definition: raster2pgsql.c:294
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
unsigned int uint32_t
Definition: uthash.h:78
static int append_sql_to_buffer(STRINGBUFFER *buffer, const char *str)
Definition: raster2pgsql.c:825
#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: