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

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

Referenced by process_rasters().

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