888 assert(table != NULL);
889 assert(column != NULL);
892 if (copy_statements) {
895 schema, table, column,
896 (file_column_name ? filename : NULL), file_column_name,
899 rterror(
_(
"insert_records: Could not add COPY statement to string buffer"));
905 if (filename != NULL)
909 for (x = 0; x < tileset->
length; x++) {
910 len = strlen(tileset->
line[x]) + 1;
912 if (filename != NULL)
913 len += strlen(fn) + 1;
915 sql =
rtalloc(
sizeof(
char) * len);
917 rterror(
_(
"insert_records: Could not allocate memory for COPY statement"));
920 sprintf(sql,
"%s%s%s",
922 (filename != NULL ?
"\t" :
""),
923 (filename != NULL ? fn :
"")
931 rterror(
_(
"process_rasters: Could not add COPY end statement to string buffer"));
938 len = strlen(
"INSERT INTO () VALUES (ST_Transform(''::raster,xxxxxxxxx));") + 1;
940 len += strlen(schema);
941 len += strlen(table);
942 len += strlen(column);
943 if (filename != NULL)
944 len += strlen(
",") + strlen(file_column_name);
947 if (filename != NULL)
950 for (x = 0; x < tileset->
length; x++) {
954 sqllen += strlen(tileset->
line[x]);
955 if (filename != NULL)
956 sqllen += strlen(
",''") + strlen(fn);
958 sql =
rtalloc(
sizeof(
char) * sqllen);
960 rterror(
_(
"insert_records: Could not allocate memory for INSERT statement"));
964 ptr += sprintf(sql,
"INSERT INTO %s%s (%s%s%s) VALUES (",
965 (schema != NULL ? schema :
""),
968 (filename != NULL ?
"," :
""),
969 (filename != NULL ? file_column_name :
"")
972 ptr += sprintf(ptr,
"ST_Transform(");
974 ptr += sprintf(ptr,
"'%s'::raster",
978 ptr += sprintf(ptr,
", %d)", out_srid);
980 if (filename != NULL) {
981 ptr += sprintf(ptr,
",'%s'", fn);
983 ptr += sprintf(ptr,
");");
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
static char * strreplace(const char *str, const char *oldstr, const char *newstr, int *count)
static int append_sql_to_buffer(STRINGBUFFER *buffer, const char *str)
#define SRID_UNKNOWN
Unknown SRID value.
void rtdealloc(void *mem)
static int copy_from(const char *schema, const char *table, const char *column, const char *filename, const char *file_column_name, STRINGBUFFER *buffer)
static int copy_from_end(STRINGBUFFER *buffer)