Changeset: f7e93e148838 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f7e93e148838
Modified Files:
        monetdb5/modules/mal/tablet_sql.c
Branch: headless
Log Message:

Get the last bit from tablet.c
Tablet_sql is now self contained and we can ditch the tablet code.


diffs (80 lines):

diff --git a/monetdb5/modules/mal/tablet_sql.c 
b/monetdb5/modules/mal/tablet_sql.c
--- a/monetdb5/modules/mal/tablet_sql.c
+++ b/monetdb5/modules/mal/tablet_sql.c
@@ -83,6 +83,27 @@
        char ***fields;
 } READERtask;
 
+static char *
+SQL_skip_string(char *s, char quote)
+{
+       while (*s) {
+               if (*s == '\\' && s[1] != '\0')
+                       s++;
+               else if (*s == quote) {
+                       if (s[1] == quote)
+                               *s++ = '\\';    /* sneakily replace "" with \" 
*/
+                       else
+                               break;
+               }
+               s++;
+       }
+       assert(*s == quote || *s == '\0');
+       if (*s)
+               s++;
+       else
+               return NULL;
+       return s;
+}
 /*
  * The line is broken into pieces directly on their field separators. It 
assumes that we have
  * the record in the cache already, so we can do most work quickly.
@@ -264,7 +285,7 @@
                task->fields[i][idx] = line;
                /* recognize fields starting with a quote, keep them */
                if ( task->quote && *line == task->quote ){
-                       line = tablet_skip_string(line + 1, task->quote);
+                       line = SQL_skip_string(line + 1, task->quote);
                        if (!line) {
                                str errline = SQLload_error(task,task->next);
                                snprintf(errmsg,BUFSIZ, "End of string (%c) 
missing "
@@ -423,6 +444,30 @@
                task->time[i] = 0;
        GDKfree(loc);
 }
+
+static int
+SQL_read_more(bstream *in, stream *out, size_t n)
+{
+       if (out) {
+               do {
+                       /* query is not finished ask for more */
+                       /* we need more query text */
+                       if (bstream_next(in) < 0)
+                               return EOF;
+                       if (in->eof) {
+                               if (out && mnstr_write(out, PROMPT2, 
sizeof(PROMPT2) - 1, 1) == 1)
+                                       mnstr_flush(out);
+                               in->eof = 0;
+                               /* we need more query text */
+                               if (bstream_next(in) <= 0)
+                                       return EOF;
+                       }
+               } while (in->len <= in->pos);
+       } else if(bstream_read(in, n) <= 0) {
+               return EOF;
+       }
+       return 1;
+}
 /*
  * Reading is handled by a separate task as a preparation for
  * mode parallelism
@@ -442,7 +487,7 @@
 #endif
                if ( task->ateof )      /* forced exit received*/
                        break;
-               task->ateof = tablet_read_more(task->b, task->out, 
task->b->size - (task->b->len - task->b->pos)) == EOF;
+               task->ateof = SQL_read_more(task->b, task->out, task->b->size - 
(task->b->len - task->b->pos)) == EOF;
                MT_sema_up(&task->consumer, "tablet loader");
        }
        MT_exit_thread(0);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to