PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 1225 of file raster2pgsql.c.

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

Referenced by process_rasters().

1230  {
1231  char *sql = NULL;
1232  uint32_t len = 0;
1233 
1234  char *_tmp = NULL;
1235 
1236  char *_ovschema = NULL;
1237  char *_ovtable = NULL;
1238  char *_ovcolumn = NULL;
1239 
1240  char *_schema = NULL;
1241  char *_table = NULL;
1242  char *_column = NULL;
1243 
1244  assert(ovtable != NULL);
1245  assert(ovcolumn != NULL);
1246  assert(table != NULL);
1247  assert(column != NULL);
1248  assert(factor >= MINOVFACTOR && factor <= MAXOVFACTOR);
1249 
1250  /* overview schema */
1251  if (ovschema != NULL) {
1252  _tmp = chartrim(ovschema, ".");
1253  _ovschema = chartrim(_tmp, "\"");
1254  rtdealloc(_tmp);
1255  _tmp = strreplace(_ovschema, "'", "''", NULL);
1256  rtdealloc(_ovschema);
1257  _ovschema = _tmp;
1258  }
1259 
1260  /* overview table */
1261  _tmp = chartrim(ovtable, "\"");
1262  _ovtable = strreplace(_tmp, "'", "''", NULL);
1263  rtdealloc(_tmp);
1264 
1265  /* overview column*/
1266  _tmp = chartrim(ovcolumn, "\"");
1267  _ovcolumn = strreplace(_tmp, "'", "''", NULL);
1268  rtdealloc(_tmp);
1269 
1270  /* schema */
1271  if (schema != NULL) {
1272  _tmp = chartrim(schema, ".");
1273  _schema = chartrim(_tmp, "\"");
1274  rtdealloc(_tmp);
1275  _tmp = strreplace(_schema, "'", "''", NULL);
1276  rtdealloc(_schema);
1277  _schema = _tmp;
1278  }
1279 
1280  /* table */
1281  _tmp = chartrim(table, "\"");
1282  _table = strreplace(_tmp, "'", "''", NULL);
1283  rtdealloc(_tmp);
1284 
1285  /* column */
1286  _tmp = chartrim(column, "\"");
1287  _column = strreplace(_tmp, "'", "''", NULL);
1288  rtdealloc(_tmp);
1289 
1290  len = strlen("SELECT AddOverviewConstraints('','','','','','',);") + 5;
1291  if (_ovschema != NULL)
1292  len += strlen(_ovschema);
1293  len += strlen(_ovtable);
1294  len += strlen(_ovcolumn);
1295  if (_schema != NULL)
1296  len += strlen(_schema);
1297  len += strlen(_table);
1298  len += strlen(_column);
1299 
1300  sql = rtalloc(sizeof(char) * len);
1301  if (sql == NULL) {
1302  rterror(_("add_overview_constraints: Could not allocate memory for AddOverviewConstraints statement"));
1303  return 0;
1304  }
1305  sprintf(sql, "SELECT AddOverviewConstraints('%s','%s','%s','%s','%s','%s',%d);",
1306  (_ovschema != NULL ? _ovschema : ""),
1307  _ovtable,
1308  _ovcolumn,
1309  (_schema != NULL ? _schema : ""),
1310  _table,
1311  _column,
1312  factor
1313  );
1314 
1315  if (_ovschema != NULL)
1316  rtdealloc(_ovschema);
1317  rtdealloc(_ovtable);
1318  rtdealloc(_ovcolumn);
1319 
1320  if (_schema != NULL)
1321  rtdealloc(_schema);
1322  rtdealloc(_table);
1323  rtdealloc(_column);
1324 
1325  append_sql_to_buffer(buffer, sql);
1326  rtdealloc(sql);
1327 
1328  return 1;
1329 }
void rtdealloc(void *mem)
Definition: rt_api.c:882
#define _(String)
Definition: shpcommon.h:23
static char * chartrim(const char *input, char *remove)
Definition: raster2pgsql.c:294
static char * strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
Definition: raster2pgsql.c:142
static int append_sql_to_buffer(STRINGBUFFER *buffer, const char *str)
Definition: raster2pgsql.c:820
#define MINOVFACTOR
Definition: raster2pgsql.h:56
void * rtalloc(size_t size)
Raster core memory management functions.
Definition: rt_api.c:867
void rterror(const char *fmt,...)
Raster core error and info handlers.
Definition: rt_api.c:895
#define MAXOVFACTOR
Definition: raster2pgsql.h:57

Here is the call graph for this function:

Here is the caller graph for this function: