Changeset: 9e2acfaae645 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e2acfaae645
Modified Files:
gdk/gdk_logger.h
geom/monetdb5/geom.h
geom/monetdb5/geom_upgrade.c
sql/backends/monet5/sql_upgrades.c
sql/common/sql_types.c
sql/storage/bat/bat_logger.c
Branch: geo
Log Message:
Added a variation of the geom upgrade code so that the server upgrades
automatically a database if the geom module is detected but the database was
created before the installation of the geom module
diffs (truncated from 737 to 300 lines):
diff --git a/gdk/gdk_logger.h b/gdk/gdk_logger.h
--- a/gdk/gdk_logger.h
+++ b/gdk/gdk_logger.h
@@ -139,11 +139,11 @@ gdk_export log_bid logger_add_bat(logger
gdk_export void logger_del_bat(logger *lg, log_bid bid);
gdk_export log_bid logger_find_bat(logger *lg, const char *name);
-typedef int (*geomcatalogfix_fptr)(void*,int,int);
+typedef int (*geomcatalogfix_fptr)(void*,int,int,int);
gdk_export void geomcatalogfix_set(geomcatalogfix_fptr);
gdk_export geomcatalogfix_fptr geomcatalogfix_get(void);
-typedef str (*geomsqlfix_fptr)(void);
+typedef str (*geomsqlfix_fptr)(int);
gdk_export void geomsqlfix_set(geomsqlfix_fptr);
gdk_export geomsqlfix_fptr geomsqlfix_get(void);
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -292,5 +292,5 @@ geom_export str wkbMBR_bat(bat* outBAT_i
geom_export str wkbCoordinateFromWKB_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
geom_export str wkbCoordinateFromMBR_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
-geom_export int geom_catalog_upgrade(void*,int,int);
-geom_export str geom_sql_upgrade(void);
+geom_export int geom_catalog_upgrade(void*,int,int,int);
+geom_export str geom_sql_upgrade(int);
diff --git a/geom/monetdb5/geom_upgrade.c b/geom/monetdb5/geom_upgrade.c
--- a/geom/monetdb5/geom_upgrade.c
+++ b/geom/monetdb5/geom_upgrade.c
@@ -113,7 +113,7 @@ N( char *buf, char *pre, char *schema, c
}
int
-geom_catalog_upgrade(void *lg, int EC_GEOM, int EC_EXTERNAL)
+geom_catalog_upgrade(void *lg, int EC_GEOM, int EC_EXTERNAL, int olddb)
{
/* Do the updates needed for the new geom module */
BAT *ct, *cnt, *cd, *cnd, *cs, *cns, *cn, *ctid, *ti, *tn, *ts, *si,
*sn, *g;
@@ -133,176 +133,179 @@ geom_catalog_upgrade(void *lg, int EC_GE
if ((ul = list_init(32)) == NULL)
return 0;
- /* Update the catalog to use the new geometry types */
- ct = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type")));
- cti = bat_iterator(ct);
- cd = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_digits")));
- cdi = bat_iterator(cd);
- cs = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_scale")));
- csi = bat_iterator(cs);
- cn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_name")));
- cni = bat_iterator(cn);
- ctid = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_table_id")));
- ctidi = bat_iterator(ctid);
- ti = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_id")));
- tn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_name")));
- tni = bat_iterator(tn);
- ts = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_schema_id")));
- tsi = bat_iterator(ts);
- si = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_id")));
- sn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_name")));
- sni = bat_iterator(sn);
+ if (olddb) {
+ /* Update the catalog to use the new geometry types */
+ ct = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type")));
+ cti = bat_iterator(ct);
+ cd = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_digits")));
+ cdi = bat_iterator(cd);
+ cs = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_type_scale")));
+ csi = bat_iterator(cs);
+ cn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_name")));
+ cni = bat_iterator(cn);
+ ctid = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_columns_table_id")));
+ ctidi = bat_iterator(ctid);
+ ti = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_id")));
+ tn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_name")));
+ tni = bat_iterator(tn);
+ ts = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"_tables_schema_id")));
+ tsi = bat_iterator(ts);
+ si = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_id")));
+ sn = BATdescriptor((bat) logger_find_bat(lg, N(n, NULL, s,
"schemas_name")));
+ sni = bat_iterator(sn);
- cnt = BATnew(TYPE_void, TYPE_str, BATcount(ct), PERSISTENT);
- cnd = BATnew(TYPE_void, TYPE_int, BATcount(cd), PERSISTENT);
- cns = BATnew(TYPE_void, TYPE_int, BATcount(cs), PERSISTENT);
+ cnt = BATnew(TYPE_void, TYPE_str, BATcount(ct), PERSISTENT);
+ cnd = BATnew(TYPE_void, TYPE_int, BATcount(cd), PERSISTENT);
+ cns = BATnew(TYPE_void, TYPE_int, BATcount(cs), PERSISTENT);
- if (!cnt || !cnd || !cns || !ct || !cd || !cs ||
- !cn || !ctid || !ti || !tn || !ts || !si || !sn)
- return 0;
- BATseqbase(cnt, ct->hseqbase);
- BATseqbase(cnd, cd->hseqbase);
- BATseqbase(cns, cs->hseqbase);
+ if (!cnt || !cnd || !cns || !ct || !cd || !cs ||
+ !cn || !ctid || !ti || !tn || !ts || !si || !sn)
+ return 0;
+ BATseqbase(cnt, ct->hseqbase);
+ BATseqbase(cnd, cd->hseqbase);
+ BATseqbase(cns, cs->hseqbase);
- for(p=BUNfirst(ct), q=BUNlast(ct); p<q; p++) {
- bte isGeom = 0;
- char *type = BUNtail(cti, p);
- int digits = *(int*)BUNtail(cdi, p);
- int scale = *(int*)BUNtail(csi, p);
- char* colname = BUNtail(cni, p);
-
- if (strcmp(toLower(type), "point") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbPoint;
- scale = 0; // in the past we did not save the srid
- } else if (strcmp(toLower(type), "linestring") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbLineString;
- scale = 0;
- } else if (strcmp(toLower(type), "curve") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbLineString;
- scale = 0;
- } else if (strcmp(toLower(type), "linearring") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbLinearRing;
- scale = 0;
- } else if (strcmp(toLower(type), "polygon") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbPolygon;
- scale = 0;
- } else if (strcmp(toLower(type), "surface") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbPolygon;
- scale = 0;
- } else if (strcmp(toLower(type), "multipoint") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbMultiPoint;
- scale = 0;
- } else if (strcmp(toLower(type), "multilinestring") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbMultiLineString;
- scale = 0;
- } else if (strcmp(toLower(type), "multicurve") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbMultiLineString;
- scale = 0;
- } else if (strcmp(toLower(type), "multipolygon") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbMultiPolygon;
- scale = 0;
- } else if (strcmp(toLower(type), "multisurface") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbMultiPolygon;
- scale = 0;
- } else if (strcmp(toLower(type), "geomcollection") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbGeometryCollection;
- scale = 0;
- } else if (strcmp(toLower(type), "geometrycollection") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = wkbGeometryCollection;
- scale = 0;
- } else if (strcmp(toLower(type), "geometry") == 0) {
- type = "geometry";
- isGeom = 1;
- digits = 0;
- scale = 0;
- }
+ for(p=BUNfirst(ct), q=BUNlast(ct); p<q; p++) {
+ bte isGeom = 0;
+ char *type = BUNtail(cti, p);
+ int digits = *(int*)BUNtail(cdi, p);
+ int scale = *(int*)BUNtail(csi, p);
+ char* colname = BUNtail(cni, p);
+
+ if (strcmp(toLower(type), "point") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbPoint;
+ scale = 0; // in the past we did not save the
srid
+ } else if (strcmp(toLower(type), "linestring") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbLineString;
+ scale = 0;
+ } else if (strcmp(toLower(type), "curve") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbLineString;
+ scale = 0;
+ } else if (strcmp(toLower(type), "linearring") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbLinearRing;
+ scale = 0;
+ } else if (strcmp(toLower(type), "polygon") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbPolygon;
+ scale = 0;
+ } else if (strcmp(toLower(type), "surface") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbPolygon;
+ scale = 0;
+ } else if (strcmp(toLower(type), "multipoint") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbMultiPoint;
+ scale = 0;
+ } else if (strcmp(toLower(type), "multilinestring") ==
0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbMultiLineString;
+ scale = 0;
+ } else if (strcmp(toLower(type), "multicurve") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbMultiLineString;
+ scale = 0;
+ } else if (strcmp(toLower(type), "multipolygon") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbMultiPolygon;
+ scale = 0;
+ } else if (strcmp(toLower(type), "multisurface") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbMultiPolygon;
+ scale = 0;
+ } else if (strcmp(toLower(type), "geomcollection") ==
0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbGeometryCollection;
+ scale = 0;
+ } else if (strcmp(toLower(type), "geometrycollection")
== 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = wkbGeometryCollection;
+ scale = 0;
+ } else if (strcmp(toLower(type), "geometry") == 0) {
+ type = "geometry";
+ isGeom = 1;
+ digits = 0;
+ scale = 0;
+ }
- BUNappend(cnt, type, TRUE);
- BUNappend(cnd, &digits, TRUE);
- BUNappend(cns, &scale, TRUE);
+ BUNappend(cnt, type, TRUE);
+ BUNappend(cnd, &digits, TRUE);
+ BUNappend(cns, &scale, TRUE);
- /* The wkb struct has changed. Update the respective BATs */
- if (isGeom) {
- typedef struct wkb_old {int len; char data[1];} wkb_old;
- BAT *gn;
- BUN k,l;
- int table_id, schema_id;
- char *sn, *tblname;
+ /* The wkb struct has changed. Update the respective
BATs */
+ if (isGeom) {
+ typedef struct wkb_old {int len; char data[1];}
wkb_old;
+ BAT *gn;
+ BUN k,l;
+ int table_id, schema_id;
+ char *sn, *tblname;
- table_id = *(int*)BUNtail(ctidi, p);
- if ((k = BUNfnd(ti, &table_id)) == BUN_NONE)
- return 0;
- tblname = BUNtail(tni, k);
- schema_id = *(int*)BUNtail(tsi, k);
- if ((k = BUNfnd(si, &schema_id)) == BUN_NONE)
- return 0;
- sn = BUNtail(sni, k);
- g = BATdescriptor((bat) logger_find_bat(lg, N(n, sn,
tblname, colname)));
- gi = bat_iterator(g);
- gn = BATnew(TYPE_void, ATOMindex("wkb"), BATcount(g),
PERSISTENT);
- if (!gn)
- return 0;
- BATseqbase(gn, g->hseqbase);
- for(k=BUNfirst(g), l=BUNlast(g); k<l; k++) {
- wkb_old *wo = (wkb_old*)BUNtail(gi, k);
- wkb *wn;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list