Changeset: 81d2314d7269 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/81d2314d7269
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_result.h
sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:
Give a more detailed error message when an export operation fails. Cleaned
error codes
diffs (truncated from 1535 to 300 lines):
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -2402,7 +2402,7 @@ mvc_result_set_wrap( Client cntxt, MalBl
bat lenId= *getArgReference_bat(stk, pci,4);
bat scaleId= *getArgReference_bat(stk, pci,5);
bat bid;
- int i,res;
+ int i, res, ok;
str tblname, colname, tpename, msg= MAL_SUCCEED;
int *digits, *scaledigits;
oid o = 0;
@@ -2414,12 +2414,16 @@ mvc_result_set_wrap( Client cntxt, MalBl
return msg;
bid = *getArgReference_bat(stk,pci,6);
b = BATdescriptor(bid);
- if ( b == NULL)
- throw(MAL,"sql.resultset", SQLSTATE(HY005) "Cannot access
column descriptor");
+ if ( b == NULL) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY005)
"Cannot access column descriptor");
+ goto wrapup_result_set;
+ }
res = *res_id = mvc_result_table(be, mb->tag, pci->argc - (pci->retc +
5), Q_TABLE, b);
- if (res < 0)
- msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result table construction failed");
BBPunfix(b->batCacheid);
+ if (res < 0) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ goto wrapup_result_set;
+ }
tbl = BATdescriptor(tblId);
atr = BATdescriptor(atrId);
@@ -2444,9 +2448,9 @@ mvc_result_set_wrap( Client cntxt, MalBl
tpename = BUNtvar(itertpe,o);
b = BATdescriptor(bid);
if ( b == NULL)
- msg=
createException(MAL,"sql.resultset",SQLSTATE(HY005) "Cannot access column
descriptor ");
+ msg = createException(SQL, "sql.resultSet",
SQLSTATE(HY005) "Cannot access column descriptor");
else if (mvc_result_column(be, tblname, colname, tpename,
*digits++, *scaledigits++, b))
- msg = createException(SQL, "sql.resultset",
SQLSTATE(42000) "Cannot access column descriptor %s.%s",tblname,colname);
+ msg = createException(SQL, "sql.resultSet",
SQLSTATE(42000) "Cannot access column descriptor %s.%s",tblname,colname);
if( b)
BBPunfix(bid);
}
@@ -2456,11 +2460,11 @@ mvc_result_set_wrap( Client cntxt, MalBl
bat_iterator_end(&iterdig);
bat_iterator_end(&iterscl);
/* now send it to the channel cntxt->fdout */
- if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res, true,
mb->starttime, mb->optimize))
- msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
+ if (!msg && (ok = mvc_export_result(cntxt->sqlcontext, cntxt->fdout,
res, true, mb->starttime, mb->optimize)) < 0)
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(cntxt->sqlcontext,
cntxt->fdout, ok));
+ wrapup_result_set:
mb->starttime = 0;
mb->optimize = 0;
- wrapup_result_set:
if( tbl) BBPunfix(tblId);
if( atr) BBPunfix(atrId);
if( tpe) BBPunfix(tpeId);
@@ -2487,9 +2491,9 @@ mvc_export_table_wrap( Client cntxt, Mal
bat tpeId= *getArgReference_bat(stk, pci,10);
bat lenId= *getArgReference_bat(stk, pci,11);
bat scaleId= *getArgReference_bat(stk, pci,12);
- stream *s;
+ stream *s = NULL;
bat bid;
- int i,res;
+ int i, res, ok;
str tblname, colname, tpename, msg= MAL_SUCCEED;
int *digits, *scaledigits;
oid o = 0;
@@ -2509,17 +2513,20 @@ mvc_export_table_wrap( Client cntxt, Mal
m = be->mvc;
if (onclient && !cntxt->filetrans) {
- throw(MAL, "sql.resultSet", "cannot transfer files to client");
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(42000)
"Cannot transfer files to client");
+ goto wrapup_result_set1;
}
bid = *getArgReference_bat(stk,pci,13);
order = BATdescriptor(bid);
- if ( order == NULL)
- throw(MAL,"sql.resultset", SQLSTATE(HY005) "Cannot access
column descriptor");
+ if ( order == NULL) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY005)
"Cannot access column descriptor");
+ goto wrapup_result_set1;
+ }
res = *res_id = mvc_result_table(be, mb->tag, pci->argc - (pci->retc +
12), Q_TABLE, order);
t = be->results;
- if (res < 0){
- msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed");
+ if (res < 0) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
goto wrapup_result_set1;
}
@@ -2551,9 +2558,9 @@ mvc_export_table_wrap( Client cntxt, Mal
tpename = BUNtvar(itertpe,o);
b = BATdescriptor(bid);
if ( b == NULL)
- msg=
createException(MAL,"sql.resultset",SQLSTATE(HY005) "Cannot access column
descriptor");
+ msg = createException(SQL, "sql.resultSet",
SQLSTATE(HY005) "Cannot access column descriptor");
else if (mvc_result_column(be, tblname, colname, tpename,
*digits++, *scaledigits++, b))
- msg = createException(SQL, "sql.resultset",
SQLSTATE(42000) "Cannot access column descriptor %s.%s",tblname,colname);
+ msg = createException(SQL, "sql.resultSet",
SQLSTATE(42000) "Cannot access column descriptor %s.%s",tblname,colname);
if( b)
BBPunfix(bid);
}
@@ -2592,10 +2599,12 @@ mvc_export_table_wrap( Client cntxt, Mal
goto wrapup_result_set1;
}
}
- if (mvc_export_result(cntxt->sqlcontext, s, res, tostdout,
mb->starttime, mb->optimize))
- msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
- mb->starttime = 0;
- mb->optimize = 0;
+ if ((ok = mvc_export_result(cntxt->sqlcontext, s, res, tostdout,
mb->starttime, mb->optimize)) < 0) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(cntxt->sqlcontext, s,
ok));
+ if (!tostdout)
+ close_stream(s);
+ goto wrapup_result_set1;
+ }
if (onclient) {
mnstr_flush(s, MNSTR_FLUSH_DATA);
if ((sz = mnstr_readline(m->scanner.rs->s, buf, sizeof(buf))) >
1) {
@@ -2607,7 +2616,9 @@ mvc_export_table_wrap( Client cntxt, Mal
close_stream(s);
}
wrapup_result_set1:
- BBPunfix(order->batCacheid);
+ mb->starttime = 0;
+ mb->optimize = 0;
+ if( order) BBPunfix(order->batCacheid);
if( tbl) BBPunfix(tblId);
if( atr) BBPunfix(atrId);
if( tpe) BBPunfix(tpeId);
@@ -2626,7 +2637,7 @@ mvc_row_result_wrap( Client cntxt, MalBl
bat tpeId= *getArgReference_bat(stk, pci,3);
bat lenId= *getArgReference_bat(stk, pci,4);
bat scaleId= *getArgReference_bat(stk, pci,5);
- int i, res;
+ int i, res, ok;
str tblname, colname, tpename, msg= MAL_SUCCEED;
int *digits, *scaledigits;
oid o = 0;
@@ -2639,8 +2650,10 @@ mvc_row_result_wrap( Client cntxt, MalBl
if ((msg = getBackendContext(cntxt, &be)) != NULL)
return msg;
res = *res_id = mvc_result_table(be, mb->tag, pci->argc - (pci->retc +
5), Q_TABLE, NULL);
- if (res < 0)
- throw(SQL, "sql.resultset", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+ if (res < 0) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
+ goto wrapup_result_set;
+ }
tbl = BATdescriptor(tblId);
atr = BATdescriptor(atrId);
@@ -2667,19 +2680,26 @@ mvc_row_result_wrap( Client cntxt, MalBl
mtype = getArgType(mb, pci, i);
if (ATOMextern(mtype))
v = *(ptr *) v;
- if (mvc_result_value(be, tblname, colname, tpename, *digits++,
*scaledigits++, v, mtype))
- throw(SQL, "sql.rsColumn", SQLSTATE(45000) "Result set
construction failed");
+ if ((ok = mvc_result_value(be, tblname, colname, tpename,
*digits++, *scaledigits++, v, mtype) < 0)) {
+ msg = createException(SQL, "sql.rsColumn",
SQLSTATE(45000) "Result set construction failed: %s", mvc_export_error(be,
be->out, ok));
+ bat_iterator_end(&itertbl);
+ bat_iterator_end(&iteratr);
+ bat_iterator_end(&itertpe);
+ bat_iterator_end(&iterdig);
+ bat_iterator_end(&iterscl);
+ goto wrapup_result_set;
+ }
}
bat_iterator_end(&itertbl);
bat_iterator_end(&iteratr);
bat_iterator_end(&itertpe);
bat_iterator_end(&iterdig);
bat_iterator_end(&iterscl);
- if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res, true,
mb->starttime, mb->optimize))
- msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
+ if (!msg && (ok = mvc_export_result(cntxt->sqlcontext, cntxt->fdout,
res, true, mb->starttime, mb->optimize)) < 0)
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(cntxt->sqlcontext,
cntxt->fdout, ok));
+ wrapup_result_set:
mb->starttime = 0;
mb->optimize = 0;
- wrapup_result_set:
if( tbl) BBPunfix(tblId);
if( atr) BBPunfix(atrId);
if( tpe) BBPunfix(tpeId);
@@ -2706,8 +2726,8 @@ mvc_export_row_wrap( Client cntxt, MalBl
bat lenId= *getArgReference_bat(stk, pci,11);
bat scaleId= *getArgReference_bat(stk, pci,12);
- int i, res;
- stream *s;
+ int i, res, ok;
+ stream *s = NULL;
str tblname, colname, tpename, msg= MAL_SUCCEED;
int *digits, *scaledigits;
oid o = 0;
@@ -2727,14 +2747,15 @@ mvc_export_row_wrap( Client cntxt, MalBl
return msg;
m = be->mvc;
if (onclient && !cntxt->filetrans) {
- throw(MAL, "sql.resultSet", "cannot transfer files to client");
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(42000)
"Cannot transfer files to client");
+ goto wrapup_result_set;
}
res = *res_id = mvc_result_table(be, mb->tag, pci->argc - (pci->retc +
12), Q_TABLE, NULL);
t = be->results;
if (res < 0){
- msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed");
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
goto wrapup_result_set;
}
@@ -2768,8 +2789,15 @@ mvc_export_row_wrap( Client cntxt, MalBl
mtype = getArgType(mb, pci, i);
if (ATOMextern(mtype))
v = *(ptr *) v;
- if (mvc_result_value(be, tblname, colname, tpename, *digits++,
*scaledigits++, v, mtype))
- throw(SQL, "sql.rsColumn", SQLSTATE(45000) "Result set
construction failed");
+ if ((ok = mvc_result_value(be, tblname, colname, tpename,
*digits++, *scaledigits++, v, mtype)) < 0) {
+ msg = createException(SQL, "sql.rsColumn",
SQLSTATE(45000) "Result set construction failed: %s", mvc_export_error(be, s,
ok));
+ bat_iterator_end(&itertbl);
+ bat_iterator_end(&iteratr);
+ bat_iterator_end(&itertpe);
+ bat_iterator_end(&iterdig);
+ bat_iterator_end(&iterscl);
+ goto wrapup_result_set;
+ }
}
bat_iterator_end(&itertbl);
bat_iterator_end(&iteratr);
@@ -2802,12 +2830,12 @@ mvc_export_row_wrap( Client cntxt, MalBl
goto wrapup_result_set;
}
}
- if (mvc_export_result(cntxt->sqlcontext, s, res, strcmp(filename,
"stdout") == 0, mb->starttime, mb->optimize)){
- msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
+ if ((ok = mvc_export_result(cntxt->sqlcontext, s, res, strcmp(filename,
"stdout") == 0, mb->starttime, mb->optimize)) < 0) {
+ msg = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed: %s", mvc_export_error(cntxt->sqlcontext, s,
ok));
+ if (!tostdout)
+ close_stream(s);
goto wrapup_result_set;
}
- mb->starttime = 0;
- mb->optimize = 0;
if (onclient) {
mnstr_flush(s, MNSTR_FLUSH_DATA);
if ((sz = mnstr_readline(m->scanner.rs->s, buf, sizeof(buf))) >
1) {
@@ -2819,6 +2847,8 @@ mvc_export_row_wrap( Client cntxt, MalBl
close_stream(s);
}
wrapup_result_set:
+ mb->starttime = 0;
+ mb->optimize = 0;
if( tbl) BBPunfix(tblId);
if( atr) BBPunfix(atrId);
if( tpe) BBPunfix(tpeId);
@@ -2849,12 +2879,11 @@ mvc_table_result_wrap(Client cntxt, MalB
if ((msg = getBackendContext(cntxt, &be)) != NULL)
return msg;
- if ((order = BATdescriptor(order_bid)) == NULL) {
+ if ((order = BATdescriptor(order_bid)) == NULL)
throw(SQL, "sql.resultSet", SQLSTATE(HY005) "Cannot access
column descriptor");
- }
*res_id = mvc_result_table(be, mb->tag, nr_cols, qtype, order);
if (*res_id < 0)
- res = createException(SQL, "sql.resultSet", SQLSTATE(45000)
"Result set construction failed");
+ res = createException(SQL, "sql.resultSet", SQLSTATE(HY013)
MAL_MALLOC_FAIL);
BBPunfix(order->batCacheid);
return res;
}
@@ -2864,7 +2893,7 @@ str
mvc_affected_rows_wrap(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
backend *b = NULL;
- int *res = getArgReference_int(stk, pci, 0), error;
+ int *res = getArgReference_int(stk, pci, 0), ok;
#ifndef NDEBUG
int mtype = getArgType(mb, pci, 2);
#endif
@@ -2878,11 +2907,11 @@ mvc_affected_rows_wrap(Client cntxt, Mal
assert(mtype == TYPE_lng);
nr = *getArgReference_lng(stk, pci, 2);
b = cntxt->sqlcontext;
- error = mvc_export_affrows(b, b->out, nr, "", mb->tag, mb->starttime,
mb->optimize);
+ ok = mvc_export_affrows(b, b->out, nr, "", mb->tag, mb->starttime,
mb->optimize);
mb->starttime = 0;
mb->optimize = 0;
- if (error)
- throw(SQL, "sql.affectedRows", SQLSTATE(45000) "Result set
construction failed");
+ if (ok < 0)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list