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

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

Referenced by process_rasters().

1162  {
1163  char *sql = NULL;
1164  uint32_t len = 0;
1165 
1166  char *_tmp = NULL;
1167  char *_schema = NULL;
1168  char *_table = NULL;
1169  char *_column = NULL;
1170 
1171  assert(table != NULL);
1172  assert(column != NULL);
1173 
1174  /* schema */
1175  if (schema != NULL) {
1176  _tmp = chartrim(schema, ".");
1177  _schema = chartrim(_tmp, "\"");
1178  rtdealloc(_tmp);
1179  _tmp = strreplace(_schema, "'", "''", NULL);
1180  rtdealloc(_schema);
1181  _schema = _tmp;
1182  }
1183 
1184  /* table */
1185  _tmp = chartrim(table, "\"");
1186  _table = strreplace(_tmp, "'", "''", NULL);
1187  rtdealloc(_tmp);
1188 
1189  /* column */
1190  _tmp = chartrim(column, "\"");
1191  _column = strreplace(_tmp, "'", "''", NULL);
1192  rtdealloc(_tmp);
1193 
1194  len = strlen("SELECT AddRasterConstraints('','','',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE);") + 1;
1195  if (_schema != NULL)
1196  len += strlen(_schema);
1197  len += strlen(_table);
1198  len += strlen(_column);
1199 
1200  sql = rtalloc(sizeof(char) * len);
1201  if (sql == NULL) {
1202  rterror(_("add_raster_constraints: Could not allocate memory for AddRasterConstraints statement"));
1203  return 0;
1204  }
1205  sprintf(sql, "SELECT AddRasterConstraints('%s','%s','%s',TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,%s,TRUE,TRUE,TRUE,TRUE,%s);",
1206  (_schema != NULL ? _schema : ""),
1207  _table,
1208  _column,
1209  (regular_blocking ? "TRUE" : "FALSE"),
1210  (max_extent ? "TRUE" : "FALSE")
1211  );
1212 
1213  if (_schema != NULL)
1214  rtdealloc(_schema);
1215  rtdealloc(_table);
1216  rtdealloc(_column);
1217 
1218  append_sql_to_buffer(buffer, sql);
1219  rtdealloc(sql);
1220 
1221  return 1;
1222 }
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
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

Here is the call graph for this function:

Here is the caller graph for this function: