Changeset: ac9358579737 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/ac9358579737 Modified Files: clients/mapiclient/dump.c Branch: Aug2024 Log Message:
Don't call sys.check_constraint on older servers. diffs (91 lines): diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c --- a/clients/mapiclient/dump.c +++ b/clients/mapiclient/dump.c @@ -452,6 +452,45 @@ bailout: return false; } +static bool +has_check_constraint(Mapi mid) +{ + MapiHdl hdl; + bool ret; + static int answer = -1; + + if (answer >= 0) + return answer; + + if ((hdl = mapi_query(mid, + "select id from sys.functions" + " where schema_id = 2000" + " and name = 'check_constraint'")) == NULL || + mapi_error(mid)) + goto bailout; + ret = mapi_get_row_count(hdl) == 1; + while ((mapi_fetch_row(hdl)) != 0) { + if (mapi_error(mid)) + goto bailout; + } + if (mapi_error(mid)) + goto bailout; + mapi_close_handle(hdl); + answer = ret; + return ret; + +bailout: + if (hdl) { + if (mapi_result_error(hdl)) + mapi_explain_result(hdl, stderr); + else + mapi_explain_query(hdl, stderr); + mapi_close_handle(hdl); + } else + mapi_explain(mid, stderr); + return false; +} + static int dump_foreign_keys(Mapi mid, const char *schema, const char *tname, const char *tid, stream *sqlf) { @@ -1114,6 +1153,7 @@ dump_column_definition(Mapi mid, stream mapi_close_handle(hdl); hdl = NULL; + const char *cc = has_check_constraint(mid) ? "case when k.type = 4 then sys.check_constraint(s.name, k.name) else null end" : "cast(null as varchar(10))"; if (tid) snprintf(query, maxquerylen, "SELECT kc.name, " /* 0 */ @@ -1121,13 +1161,13 @@ dump_column_definition(Mapi mid, stream "k.name, " /* 2 */ "kc.id, " /* 3 */ "k.type, " /* 4 */ - "case when k.type = 4 then sys.check_constraint(s.name, k.name) else null end " /* 5 */ + "%s " /* 5 */ "FROM sys.objects kc, " "sys.keys k " "WHERE kc.id = k.id " "AND k.table_id = %s " "AND k.type = 1 " - "ORDER BY kc.id, kc.nr", tid); + "ORDER BY kc.id, kc.nr", cc, tid); else snprintf(query, maxquerylen, "SELECT kc.name, " /* 0 */ @@ -1135,7 +1175,7 @@ dump_column_definition(Mapi mid, stream "k.name, " /* 2 */ "kc.id, " /* 3 */ "k.type, " /* 4 */ - "case when k.type = 4 then sys.check_constraint(s.name, k.name) else null end " /* 5 */ + "%s " /* 5 */ "FROM sys.objects kc, " "sys.keys k, " "sys.schemas s, " @@ -1146,7 +1186,7 @@ dump_column_definition(Mapi mid, stream "AND t.schema_id = s.id " "AND s.name = '%s' " "AND t.name = '%s' " - "ORDER BY kc.id, kc.nr", s, t); + "ORDER BY kc.id, kc.nr", cc, s, t); if ((hdl = mapi_query(mid, query)) == NULL || mapi_error(mid)) goto bailout; cnt = 0; _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org