Update of /cvsroot/monetdb/sql/src/backends/monet5
In directory sfp-cvsdas-1.v30.ch3.sourceforge.com:/tmp/cvs-serv19483

Modified Files:
        sql.mx 
Log Message:
There are more more-or-less similar coercion macros. This code could (should) be
squeezed in the future.


Index: sql.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql.mx,v
retrieving revision 1.383
retrieving revision 1.384
diff -u -d -r1.383 -r1.384
--- sql.mx      31 Dec 2009 14:43:49 -0000      1.383
+++ sql.mx      2 Jan 2010 15:13:44 -0000       1.384
@@ -3412,6 +3412,7 @@
                for (; p<q; p++)
                        *o = (@1) ((*p +  (*p<0)?-5:5) / scales[scale]);
        } else{
+               for (; p<q; p++)
                if (*p == @2_nil) {
                        *o = @1_nil;
                        bn->T->nonil= FALSE;
@@ -3720,27 +3721,48 @@
 
 str b...@2_dec2_@1( int *res, int *s1, int *bid )
 {
-       BAT *b, *dst;
-       BATiter bi;
-       BUN p,q;
+       BAT *b, *bn;
+       @2 *p,*q;
        char *msg = NULL;
+       int scale = *s1;
+       @1 *o;
 
        if( (b = BATdescriptor(*bid)) == NULL ){
                throw(SQL, "batca...@2_dec2_@1", "Cannot access descriptor");
        }
-       bi = bat_iterator(b);
-       dst = BATnew(b->htype, ty...@1, BATcount(b));
-       BATseqbase(dst, b->hseqbase);
-       BATloop(b,p,q) {
-               @2 *v = (@2*)BUNtail(bi,p);
-               @1 r;
-               msg = @2_de...@1( &r, s1, v );
-               if (msg)
-                       break;
-               BUNins(dst, BUNhead(bi,p), &r, FALSE);
+       bn = BATnew(TYPE_void, ty...@1, BATcount(b));
+       bn->hsorted = b->hsorted;
+       BATseqbase(bn, b->hseqbase);
+       o = (@1*) Tloc(bn,BUNfirst(bn));
+       p = (@2*) Tloc(b, BUNfirst(b));
+       q = (@2*) Tloc(b, BUNlast(b));
+       bn->T->nonil= b->T->nonil;
+       if ( b->T->nonil){
+               for (; p<q; p++) 
+                       *o = *p/scales[scale];
+       } else{
+               for (; p<q; p++) {
+                       if (*p == @2_nil) {
+                               *o = @1_nil;
+                               bn->T->nonil= FALSE;
+                       } else 
+                               *o = *p/scales[scale];
+               }
        }
-       BBPkeepref( *res = dst->batCacheid);
-       BBPunfix(b->batCacheid);
+       BATsetcount(bn, BATcount(b));
+       bn->tsorted = 0;
+       BATkey(BATmirror(bn),FALSE);
+
+       if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
+
+       if (b->htype != bn->htype) {
+               BAT *r = VIEWcreate(b,bn);
+
+               BBPreleaseref(bn->batCacheid);
+               bn = r;
+       }
+       BBPkeepref(*res = bn->batCacheid);
+       BBPreleaseref(b->batCacheid);
        return msg;
 }
 
@@ -3884,27 +3906,67 @@
 
 str b...@2_dec2_@1( int *res, int *s1, int *bid )
 {
-       BAT *b, *dst;
-       BATiter bi;
-       BUN p,q;
+       BAT *b, *bn;
+       @2 *p,*q;
        char *msg = NULL;
+       int scale = *s1;
+       @1 *o;
+       @2 val;
 
        if( (b = BATdescriptor(*bid)) == NULL ){
                throw(SQL, "batca...@2_dec2_@1", "Cannot access descriptor");
        }
-       bi = bat_iterator(b);
-       dst = BATnew(b->htype, ty...@1, BATcount(b));
-       BATseqbase(dst, b->hseqbase);
-       BATloop(b,p,q) {
-               @2 *v = (@2*)BUNtail(bi,p);
-               @1 r;
-               msg = @2_de...@1( &r, s1, v );
-               if (msg)
-                       break;
-               BUNins(dst, BUNhead(bi,p), &r, FALSE);
+       bn = BATnew(TYPE_void, ty...@1, BATcount(b));
+       bn->hsorted = b->hsorted;
+       BATseqbase(bn, b->hseqbase);
+       o = (@1*) Tloc(bn,BUNfirst(bn));
+       p = (@2*) Tloc(b, BUNfirst(b));
+       q = (@2*) Tloc(b, BUNlast(b));
+       bn->T->nonil= b->T->nonil;
+       if ( b->T->nonil){
+               for (; p<q; p++) {
+                       val = (*p+ (*p<0)?-5:5)/scales[scale];
+                       /* see if the number fits in the data type */
+                       if (val > g...@1_min && val <= g...@1_max)
+                               *o = (@1)val;
+                       else {
+                               BBPreleaseref(b->batCacheid);
+                               BBPreleaseref(bn->batCacheid);
+                               throw(SQL, "convert", "value (" LLFMT ") 
exceeds limits of type @1", val);
+                       }
+               }
+       } else{
+               for (; p<q; p++) {
+                       if (*p == @2_nil) {
+                               *o = @1_nil;
+                               bn->T->nonil= FALSE;
+                       } else {
+                               val = ( *p + ( *p<0)?-5:5)/scales[scale];
+                               /* see if the number fits in the data type */
+                               if (val > g...@1_min && val <= g...@1_max)
+                                       *o = (@1)val;
+                               else {
+                                       BBPreleaseref(b->batCacheid);
+                                       BBPreleaseref(bn->batCacheid);
+                                       throw(SQL, "convert", "value (" LLFMT 
") exceeds limits of type @1", val);
+                               }
+                       }
+               }
        }
-       BBPkeepref( *res = dst->batCacheid);
-       BBPunfix(b->batCacheid);
+       BATsetcount(bn, BATcount(b));
+       bn->tsorted = 0;
+       BATkey(BATmirror(bn),FALSE);
+
+       if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);
+
+       if (b->htype != bn->htype) {
+               BAT *r = VIEWcreate(b,bn);
+
+               BBPreleaseref(bn->batCacheid);
+               bn = r;
+       }
+       BBPkeepref(*res = bn->batCacheid);
+       BBPreleaseref(b->batCacheid);
        return msg;
 }
 


------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to