Update of /cvsroot/monetdb/sql/src/backends/monet5
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv11383/src/backends/monet5
Modified Files:
sql.mx sql_gencode.mx sql_result.mx
Log Message:
added support for copy select .. into 'filename';
Index: sql_result.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_result.mx,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- sql_result.mx 25 Dec 2007 21:34:31 -0000 1.75
+++ sql_result.mx 3 Jan 2008 09:41:17 -0000 1.76
@@ -713,12 +713,10 @@
}
static int
-mvc_export_row(mvc *m, stream *s, res_table *t)
+mvc_export_row(mvc *m, stream *s, res_table *t, str btag, str sep, str rsep,
str ssep)
{
- char *sep = ",\t";
- char *rsep = "\t]\n";
- int seplen= 2;
- int rseplen= 3;
+ int seplen = strlen(sep);
+ int rseplen= strlen(rsep);
char *buf = NULL;
int len = 0;
int i, ok = 1;
@@ -726,7 +724,9 @@
if (!s)
return 0;
- ok = (stream_write(s, "[ ", 2, 1) == 1);
+ (void)ssep;
+ if (btag[0])
+ ok = (stream_write(s, btag, strlen(btag), 1) == 1);
for (i = 0; i < t->nr_cols && ok; i++) {
res_col *c = t->cols + i;
@@ -748,11 +748,8 @@
}
static int
-mvc_export_table(mvc *m, stream *s, res_table *t, BAT *order, size_t offset,
size_t nr)
+mvc_export_table(mvc *m, stream *s, res_table *t, BAT *order, size_t offset,
size_t nr, char *btag, char *sep, char *rsep, char *ssep )
{
- char *sep = ",\t";
- char *rsep = "\t]\n";
-
Tablet as;
Column *fmt;
ssize_t i;
@@ -770,7 +767,7 @@
memset(fmt, 0, (as.nr_attrs + 1) * sizeof(Column));
fmt[0].c = NULL;
- fmt[0].sep = _strdup("[ ");
+ fmt[0].sep = _strdup(btag);
fmt[0].seplen = _strlen(fmt[0].sep);
fmt[0].ws = 0;
@@ -794,6 +791,7 @@
fmt[i].len = 0;
fmt[i].nillen = 0;
fmt[i].ws = 0;
+ fmt[i].quote = ssep?ssep[0]:0;
if (c->type.type->eclass == EC_DEC) {
fmt[i].tostr = &dec_tostr;
fmt[i].frstr = &dec_frstr;
@@ -1016,6 +1014,34 @@
}
int
+mvc_export_file(mvc *m, res_table *t)
+{
+ int res = 0;
+ size_t count;
+ stream *s;
+ BAT *order = NULL;
+
+ s = open_wastream(t->filename);
+ if (!s || stream_errnr(s)) {
+ GDKerror("failed to open %s\n", t->filename);
+ return -1;
+ }
+
+ if (!t->order) {
+ res = mvc_export_row(m, s, t, "", t->tsep, t->rsep, t->ssep);
+ } else {
+ order = BATdescriptor(t->order);
+ count = BATcount(order);
+ res = mvc_export_table(m, s, t, order, 0, count, "", t->tsep,
t->rsep, t->ssep);
+ BBPunfix(order->batCacheid);
+ m->results = res_tables_remove(m->results, t);
+ }
+ stream_close(s);
+ stream_destroy(s);
+ return res;
+}
+
+int
mvc_export_result(mvc *m, stream *s, int res_id, str w)
{
int i, clean = 0, res = 0;
@@ -1028,6 +1054,8 @@
/* we shouldn't have anything else but Q_TABLE here */
assert(t->query_type == Q_TABLE);
+ if (t->filename)
+ return mvc_export_file(m, t);
/* query type: Q_TABLE */
if (!(stream_write(s, "&1 ", 3, 1) == 1))
@@ -1108,14 +1136,14 @@
return export_error(order);
if (!t->order)
- return mvc_export_row(m, s, t);
+ return mvc_export_row(m, s, t, "[ ", ",\t", "\t]\n", "\"");
count = m->reply_size;
if (count == 0 || count >= BATcount(order)) {
count = BATcount(order);
clean = 1;
}
- res = mvc_export_table(m, s, t, order, 0, count);
+ res = mvc_export_table(m, s, t, order, 0, count, "[ ", ",\t", "\t]\n",
"\"");
BBPunfix(order->batCacheid);
if (clean)
m->results = res_tables_remove(m->results, t);
@@ -1171,7 +1199,7 @@
if (stream_write(s, "\n", 1, 1) != 1)
return export_error(order);
- res = mvc_export_table(m, s, t, order, offset, cnt);
+ res = mvc_export_table(m, s, t, order, offset, cnt, "[ ", ",\t",
"\t]\n", "\"");
BBPunfix(order->batCacheid);
return res;
}
Index: sql_gencode.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_gencode.mx,v
retrieving revision 1.261
retrieving revision 1.262
diff -u -d -r1.261 -r1.262
--- sql_gencode.mx 2 Jan 2008 08:25:21 -0000 1.261
+++ sql_gencode.mx 3 Jan 2008 09:41:17 -0000 1.262
@@ -827,6 +827,7 @@
int l = _dumpstmt(sql, mb, s->op1.stval);
int r1 = _dumpstmt(sql, mb, s->op2.stval);
int r2 = _dumpstmt(sql, mb, s->op3.stval);
+ //int ls = 0, hs = 0;
char *cmd =
(s->type == st_select2) ? selectRef :
(s->type == st_uselect2) ? uselectRef :
@@ -846,9 +847,17 @@
break;
}
/* if st_join2 try to convert to bandjoin
- if (s->op2.stval->type == st_binop ||
s->op3.stval->type == st_binop) {
- assert(0);
+ if ((ls = (s->op2.stval->type == st_binop &&
+ strcmp(s->op2.stval->op4.funcval->func->base.name,
"sql_add")==0)) ||
+ (hs = (s->op3.stval->type == st_binop &&
+ strcmp(s->op3.stval->op4.funcval->func->base.name,
"sql_add")==0))) {
+ if (ls)
+ printf("ls\n");
+ if (hs)
+ printf("hs\n");
+
printf("possible bandjoin ?\n");
+ assert(0);
}
*/
@@ -1492,7 +1501,7 @@
s->nr = getDestVar(q);
@:SQLpostlude@
} break;
- case st_bulkinsert:{
+ case st_import:{
char *tname = s->op1.stval->op1.tval->base.name;
node *n = s->op2.lval->h;
char *sep = n->data;
@@ -1576,7 +1585,8 @@
s->nr = getDestVar(q);
@:SQLpostlude@
} break;
- case st_output:{
+ case st_output:
+ case st_export:{
stmt *order = NULL;
stmt *lst = s->op1.stval;
@@ -1587,6 +1597,7 @@
lst = lst->op2.stval;
}
if (lst->type == st_list) {
+ int file = 0;
list *l = lst->op1.lval;
int cnt = list_length(l);
stmt *f;
@@ -1596,7 +1607,8 @@
f = n->data;
/* single value result, has a fast exit */
- if (cnt == 1 && !order && f->nrcols <= 0){
+ if (cnt == 1 && !order && f->nrcols <= 0 &&
+ s->type != st_export){
stmt *c = n->data;
sql_subtype *t = tail_type(c);
char *tname = table_name(c);
@@ -1638,10 +1650,24 @@
order = n->data;
}
}
+ if (s->type == st_export)
+ file = _dumpstmt(sql, mb, s->op4.stval);
k = newStmt2(mb, sqlRef, resultSetRef);
s->nr = getDestVar(k);
k = pushInt(mb, k, cnt);
- k = pushInt(mb, k, sql->mvc->type);
+ if (s->type == st_export) {
+ node *n = s->op2.lval->h;
+ char *sep = n->data;
+ char *rsep = n->next->data;
+ char *ssep =
sql_escape_ident(n->next->next->data);
+ k = pushArgument(mb, k, file);
+ k = pushStr(mb, k, sep);
+ k = pushStr(mb, k, rsep);
+ k = pushStr(mb, k, ssep);
+ _DELETE(ssep);
+ } else {
+ k = pushInt(mb, k, sql->mvc->type);
+ }
k = pushArgument(mb, k, order->nr);
dump_header(mb, s, l);
Index: sql.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql.mx,v
retrieving revision 1.244
retrieving revision 1.245
diff -u -d -r1.244 -r1.245
--- sql.mx 21 Dec 2007 17:02:22 -0000 1.244
+++ sql.mx 3 Jan 2008 09:41:17 -0000 1.245
@@ -149,6 +149,10 @@
The Monet 5 code generator uses several SQL specific wrapper functions.
They are not present in V4
@mal
+command resultSet( nr_cols:int, file:str, sep:str, rsep:str, ssep:str,
order:bat[:oid,:any_1] ) :int
+address mvc_result_file_wrap
+comment "Prepare a file result set";
+
command resultSet( nr_cols:int, qtype:int, order:bat[:oid,:any_1] ) :int
address mvc_result_table_wrap
comment "Prepare a table result set";
@@ -682,6 +686,7 @@
sql5_export str mvc_clear_table_wrap(lng *res, str *sname, str *tname);
sql5_export str mvc_delete_wrap(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci);
sql5_export str mvc_result_row_wrap(int *res_id, int *nr_cols, int *qtype, int
*o);
+sql5_export str mvc_result_file_wrap(int *res_id, int *nr_cols, str *file, str
*sep, str *rsep, str *ssep, bat *order_bid);
sql5_export str mvc_result_table_wrap(int *res_id, int *nr_cols, int *qtype,
bat *order_bid);
sql5_export str mvc_result_column_wrap(int *ret, int *rs, str *tn, str *name,
str *type, int *digits, int *scale, bat *bid);
@= result_value_export
@@ -1499,6 +1504,33 @@
return MAL_SUCCEED;
}
+str
+mvc_result_file_wrap(int *res_id, int *nr_cols, str *file, str *tsep, str
*rsep, str *ssep, bat *order_bid)
+{
+ str res = MAL_SUCCEED;
+ BAT *order;
+ mvc *m = NULL;
+ str msg = getContext(&m, NULL);
+ res_table *t = NULL;
+
+ if (msg)
+ return msg;
+ if ((order = BATdescriptor(*order_bid)) == NULL ) {
+ throw(SQL, "sql.resultSet", "Cannot access descriptor");
+ }
+ t = res_table_create(m->session->tr, m->result_id++, *nr_cols, Q_TABLE,
m->results, order);
+ m->results = t;
+ t->filename = _strdup(*file);
+ t->tsep = _strdup(*tsep);
+ t->rsep = _strdup(*rsep);
+ t->ssep = _strdup(*ssep);
+ *res_id = t->id;
+ if (*res_id < 0)
+ res = createException(SQL, "sql.resultSet", "failed");
+ BBPunfix(order->batCacheid);
+ return res;
+}
+
str
mvc_result_table_wrap(int *res_id, int *nr_cols, int *qtype, bat *order_bid)
{
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins