PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ add_raster_constraints()

static int add_raster_constraints ( const char *  schema,
const char *  table,
const char *  column,
int  regular_blocking,
int  max_extent,
STRINGBUFFER buffer 
)
static

Definition at line 1178 of file raster2pgsql.c.

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

Referenced by process_rasters().

1182  {
1183  char *sql = NULL;
1184  uint32_t len = 0;
1185 
1186  char *_tmp = NULL;
1187  char *_schema = NULL;
1188  char *_table = NULL;
1189  char *_column = NULL;
1190 
1191  assert(table != NULL);
1192  assert(column != NULL);
1193 
1194  /* schema */
1195  if (schema != NULL) {
1196  _tmp = chartrim(schema, ".");
1197  _schema = chartrim(_tmp, "\"");
1198  rtdealloc(_tmp);
1199  _tmp = strreplace(_schema, "'", "''", NULL);
1200  rtdealloc(_schema);
1201  _schema = _tmp;
1202  }
1203 
1204  /* table */
1205  _tmp = chartrim(table, "\"");
1206  _table = strreplace(_tmp, "'", "''", NULL);
1207  rtdealloc(_tmp);
1208 
1209  /* column */
1210  _tmp = chartrim(column, "\"");
1211  _column = strreplace(_tmp, "'", "''", NULL);
1212  rtdealloc(_tmp);
1213 
1214  len = strlen("SELECT AddRasterConstraints('','','',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE);") + 1;
1215  if (_schema != NULL)
1216  len += strlen(_schema);
1217  len += strlen(_table);
1218  len += strlen(_column);
1219 
1220  sql = rtalloc(sizeof(char) * len);
1221  if (sql == NULL) {
1222  rterror(_("add_raster_constraints: Could not allocate memory for AddRasterConstraints statement"));
1223  return 0;
1224  }
1225  sprintf(sql, "SELECT AddRasterConstraints('%s','%s','%s',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,%s,TRUE,TRUE,TRUE,TRUE,%s);",
1226  (_schema != NULL ? _schema : ""),
1227  _table,
1228  _column,
1229  (regular_blocking ? "TRUE" : "FALSE"),
1230  (max_extent ? "TRUE" : "FALSE")
1231  );
1232 
1233  if (_schema != NULL)
1234  rtdealloc(_schema);
1235  rtdealloc(_table);
1236  rtdealloc(_column);
1237 
1238  append_sql_to_buffer(buffer, sql);
1239 
1240  return 1;
1241 }
#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
void rtdealloc(void *mem)
Definition: rt_context.c:186
Here is the call graph for this function:
Here is the caller graph for this function: