The R Project SVN R-packages

Rev

Rev 3456 | Rev 3471 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3456 Rev 3458
Line 670... Line 670...
670
            }
670
            }
671
 
671
 
672
        } else if (IS_INTEGER(op2) || IS_LOGICAL(op2)) { /* I N T E G E R */
672
        } else if (IS_INTEGER(op2) || IS_LOGICAL(op2)) { /* I N T E G E R */
673
            /* we are taking advantage of the fact that logicals are stored as int.
673
            /* we are taking advantage of the fact that logicals are stored as int.
674
             * if this becomes untrue in the future, then this is a bug */
674
             * if this becomes untrue in the future, then this is a bug */
-
 
675
            /* we are binding double because ___ (?) */
675
            op2_len = LENGTH(op2);
676
            op2_len = LENGTH(op2);
676
 
677
 
677
            if (op2_len == 1) {
678
            if (op2_len == 1) {
678
                if (funcname[0] == '%') {
679
                if (funcname[0] == '%') {
679
                    sprintf(g_sql_buf[2], insert_fmt_string1c, iname, 
680
                    sprintf(g_sql_buf[2], insert_fmt_string1c, iname, 
Line 691... Line 692...
691
                        varname_src, iname_src);
692
                        varname_src, iname_src);
692
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
693
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
693
                _sqlite_error(res);
694
                _sqlite_error(res);
694
 
695
 
695
                if (funcname[0] == '%') {
696
                if (funcname[0] == '%') {
696
                    /* sqlite does int div with "/" if both args are int. mod is % also.
-
 
697
                     * fortunately, in both cases the sqlite op is 2nd char of funcname */
-
 
698
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, 
697
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, 
699
                            (funcname[1] == '%') ? "r_mod" : "r_intdiv");
698
                            (funcname[1] == '%') ? "r_mod" : "r_intdiv");
700
                    _sqlite_begin;
699
                    _sqlite_begin;
701
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
700
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
702
                    _sqlite_error(res);
701
                    _sqlite_error(res);
Line 708... Line 707...
708
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
707
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
709
                        sqlite3_bind_int(stmt, sdf_idx, sqlite3_column_int(stmt2, 1));
708
                        sqlite3_bind_int(stmt, sdf_idx, sqlite3_column_int(stmt2, 1));
710
                        sqlite3_bind_int(stmt, vec_idx, INTEGER(op2)[i % op2_len]);
709
                        sqlite3_bind_int(stmt, vec_idx, INTEGER(op2)[i % op2_len]);
711
                        sqlite3_step(stmt);
710
                        sqlite3_step(stmt);
712
                    }
711
                    }
-
 
712
                    sqlite3_finalize(stmt);
-
 
713
                    sqlite3_finalize(stmt2);
713
                    _sqlite_commit;
714
                    _sqlite_commit;
714
                } else {
715
                } else {
715
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
716
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
716
                    _sqlite_begin;
717
                    _sqlite_begin;
717
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
718
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
Line 724... Line 725...
724
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
725
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
725
                        sqlite3_bind_double(stmt, sdf_idx, sqlite3_column_double(stmt2, 1));
726
                        sqlite3_bind_double(stmt, sdf_idx, sqlite3_column_double(stmt2, 1));
726
                        sqlite3_bind_double(stmt, vec_idx, (double)INTEGER(op2)[i % op2_len]);
727
                        sqlite3_bind_double(stmt, vec_idx, (double)INTEGER(op2)[i % op2_len]);
727
                        sqlite3_step(stmt);
728
                        sqlite3_step(stmt);
728
                    }
729
                    }
-
 
730
                    sqlite3_finalize(stmt);
-
 
731
                    sqlite3_finalize(stmt2);
729
                    _sqlite_commit;
732
                    _sqlite_commit;
730
                }
733
                }
731
                sqlite3_finalize(stmt2);
-
 
732
            } else {
734
            } else {
733
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
735
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
734
                        varname_src, iname_src);
736
                        varname_src, iname_src);
735
 
737
 
736
                if (funcname[0] == '%') {
738
                if (funcname[0] == '%') {
Line 774... Line 776...
774
                    }
776
                    }
775
 
777
 
776
                    /* recycle on svec if we loop again */
778
                    /* recycle on svec if we loop again */
777
                    sqlite3_finalize(stmt2);
779
                    sqlite3_finalize(stmt2);
778
                }
780
                }
-
 
781
                sqlite3_finalize(stmt);
779
                _sqlite_commit;
782
                _sqlite_commit;
780
            }
783
            }
781
 
784
 
-
 
785
        } else if (IS_CHARACTER(op2)) {
-
 
786
            if (functype != 2) error("not supported");
-
 
787
 
-
 
788
            op2_len = LENGTH(op2);
-
 
789
 
-
 
790
            if (op2_len == 1) {
-
 
791
                sprintf(g_sql_buf[2], insert_fmt_string1s, iname,
-
 
792
                            varname_src, funcname, iname_src);
-
 
793
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
-
 
794
                _sqlite_error(res);
-
 
795
                sqlite3_bind_text(stmt, 1, CHAR_ELT(op2, 0), -1, SQLITE_STATIC);
-
 
796
                sqlite3_step(stmt);
-
 
797
            } else if (op2_len <= svec_len) {
-
 
798
                sprintf(g_sql_buf[2], "select [row name], [%s] from [%s].sdf_data",
-
 
799
                        varname_src, iname_src);
-
 
800
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
-
 
801
                _sqlite_error(res);
-
 
802
 
-
 
803
                sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
-
 
804
                _sqlite_begin;
-
 
805
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
-
 
806
                _sqlite_error(res);
-
 
807
 
-
 
808
                for (i = 0; i < svec_len; i++) {
-
 
809
                    sqlite3_step(stmt2);
-
 
810
 
-
 
811
                    sqlite3_reset(stmt);
-
 
812
                    sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
-
 
813
                    sqlite3_bind_text(stmt, sdf_idx, (char *)sqlite3_column_text(stmt2, 1), -1, SQLITE_STATIC);
-
 
814
                    sqlite3_bind_text(stmt, vec_idx, CHAR_ELT(op2, i % op2_len), -1 , SQLITE_STATIC);
-
 
815
                    sqlite3_step(stmt);
-
 
816
                }
-
 
817
                sqlite3_finalize(stmt2);
-
 
818
                _sqlite_commit;
-
 
819
            } else {
-
 
820
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
-
 
821
                        varname_src, iname_src);
-
 
822
 
-
 
823
                sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
-
 
824
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
-
 
825
                _sqlite_error(res);
-
 
826
               
-
 
827
                i = 0; _sqlite_begin; 
-
 
828
                while (i < op2_len) {
-
 
829
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
-
 
830
                    _sqlite_error(res);
-
 
831
 
-
 
832
                    for ( ; i < op2_len && sqlite3_step(stmt) == SQLITE_ROW ; i++) {
-
 
833
                        sqlite3_step(stmt2);
-
 
834
 
-
 
835
                        sqlite3_reset(stmt);
-
 
836
                        sqlite3_bind_int(stmt, 1, i);
-
 
837
                        sqlite3_bind_text(stmt, sdf_idx, (char *)sqlite3_column_text(stmt2, 1), -1, SQLITE_STATIC);
-
 
838
                        sqlite3_bind_text(stmt, vec_idx, CHAR_ELT(op2, i % op2_len), -1 , SQLITE_STATIC);
-
 
839
                        sqlite3_step(stmt);
-
 
840
                    }
-
 
841
 
-
 
842
                    /* recycle on svec if we loop again */
-
 
843
                    sqlite3_finalize(stmt2);
-
 
844
                }
782
            sqlite3_finalize(stmt);
845
                sqlite3_finalize(stmt);
-
 
846
                _sqlite_commit;
-
 
847
            }
-
 
848
        
783
        } else if (inherits(op2, "sqlite.vector")) { 
849
        } else if (inherits(op2, "sqlite.vector")) { 
784
            /* op2 is surely not a factor, as handled by the R wrapper */
850
            /* op2 is surely not a factor, as handled by the R wrapper */
785
            /* even though it is impossible for reversed to be FALSE, still use
851
            /* even though it is impossible for reversed to be FALSE, still use
786
             * sdf_idx and vec_idx so that code would be less confusing */
852
             * sdf_idx and vec_idx so that code would be less confusing */
787
            char *iname_op2, *varname_op2;
853
            char *iname_op2, *varname_op2;
Line 789... Line 855...
789
            iname_op2 = SDF_INAME(op2);
855
            iname_op2 = SDF_INAME(op2);
790
            varname_op2 = SVEC_VARNAME(op2);
856
            varname_op2 = SVEC_VARNAME(op2);
791
 
857
 
792
            if (!USE_SDF1(iname_op2, TRUE, TRUE)) {
858
            if (!USE_SDF1(iname_op2, TRUE, TRUE)) {
793
                /* delete created sqlite.vector */
859
                /* delete created sqlite.vector */
794
                Rprintf("Warning: detaching created result SDF %s\n", iname);
860
                warning("detaching created result SDF %s\n", iname);
795
                sdf_detach_sdf(mkString(iname));
861
                sdf_detach_sdf(mkString(iname));
796
                return R_NilValue;
862
                return R_NilValue;
797
            }
863
            }
798
            _sqlite_begin;
864
            _sqlite_begin;
799
 
865