Update of /cvsroot/monetdb/sql/src/server
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv23422/src/server

Modified Files:
        sql_statement.mx sql_updates.mx 
Log Message:
Finished the implementation of the SQL side of binary file import
(attach).
The implementation  reuses the st_import statement type and  uses the
separator (or lack thereof) to distinguish between  binary and CSV.
It binary, op4 is a list of files instead of a single file (i.e. a
list instead of stmt).

Niels, there is a question in sql_gencode.mx for you (look  for XXX).


U sql_statement.mx
Index: sql_statement.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_statement.mx,v
retrieving revision 1.180
retrieving revision 1.181
diff -u -d -r1.180 -r1.181
--- sql_statement.mx    21 Jan 2009 20:30:51 -0000      1.180
+++ sql_statement.mx    26 Jan 2009 16:09:42 -0000      1.181
@@ -681,10 +681,14 @@
                case st_export:
                        if (s->op1.stval)
                                stmt_destroy(s->op1.stval);
+                       if (s->op4.stval) {
+                               if (s->op2.lval == NULL || s->op2.lval->h->data)
+                                       stmt_destroy(s->op4.stval);
+                               else
+                                       list_destroy(s->op4.lval);
+                       }
                        if (s->op2.lval)
                                list_destroy(s->op2.lval);
-                       if (s->op4.stval)
-                               stmt_destroy(s->op4.stval);
                        break;
 
                case st_aggr:

U sql_updates.mx
Index: sql_updates.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/server/sql_updates.mx,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- sql_updates.mx      22 Jan 2009 21:58:06 -0000      1.162
+++ sql_updates.mx      26 Jan 2009 16:09:42 -0000      1.163
@@ -598,7 +598,8 @@
        }
        if (!t) {
                return sql_error(sql, 02, "COPY INTO: no such table '%s'", 
tname);
-       } else if (files) {
+       }
+       if (files) {
                dnode *n = files->h;
 
                for (slist = create_stmt_list(); n; n = n->next) {
@@ -619,11 +620,13 @@
        list *ops;
        char *sname = qname_schema(qname);
        char *tname = qname_table(qname);
-       sql_schema *sys = mvc_bind_schema(sql, "sys");
        sql_schema *s = NULL;
        sql_table *t = NULL;
-       sql_subfunc *import = NULL;
        list *slist;
+       dnode *dn;
+       node *n;
+       stmt *rs, **inserts;
+       int i, len = 0;
 
        if (sname && !(s=mvc_bind_schema(sql, sname))) {
                (void) sql_error(sql, 02, "COPY INTO: no such schema '%s'", 
sname);
@@ -643,18 +646,25 @@
        }
        if (!t) {
                return sql_error(sql, 02, "COPY INTO: no such table '%s'", 
tname);
-       } 
+       }
+       if (files == NULL)
+               return sql_error(sql, 02, "COPY INTO: must specify files");
+
        ops = create_stmt_list();
-       list_append(ops, stmt_atom_string(_strdup(s->base.name)));
-       list_append(ops, stmt_atom_string(_strdup(t->base.name)));
-       if (files) {
-               dnode *n = files->h;
-               for (; n; n = n->next)
-                       list_append(ops, 
stmt_atom_string(_strdup(n->data.sval)));
+       for (dn = files->h; dn; dn = dn->next)
+               list_append(ops, stmt_atom_string(_strdup(dn->data.sval)));
+       rs = stmt_import(stmt_basetable(t, t->base.name), NULL, NULL, NULL, 
NULL, (stmt *) ops, 0, 0);
+       inserts = table_update_array(t, &len);
+       for (n = t->columns.set->h, i = 0; n; n = n->next, i++) {
+               sql_column *c = n->data;
+
+               inserts[i] = stmt_append_col(c, stmt_rs_column(stmt_dup(rs), 
stmt_atom_string(_strdup(c->base.name)), &c->type));
        }
+       stmt_destroy(rs);
+       rs = sql_insert(sql, t, inserts, len, 1);
+       
        slist = create_stmt_list();
-       import = sql_find_func(sys, "import", 2); /* TODO later we need true 
varargs */
-       list_append(slist, stmt_Nop(stmt_list(ops), import));
+       list_append(slist, rs);
        return stmt_list(slist);
 }
 


------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to