The R Project SVN R-packages

Rev

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

Rev 3358 Rev 3397
Line 483... Line 483...
483
 
483
 
484
                if (funcname[0] == '%') {
484
                if (funcname[0] == '%') {
485
                    /* sqlite does int div with "/" if both args are int. mod is % also.
485
                    /* sqlite does int div with "/" if both args are int. mod is % also.
486
                     * fortunately, in both cases the sqlite op is 2nd char of funcname */
486
                     * fortunately, in both cases the sqlite op is 2nd char of funcname */
487
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);  
487
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);  
-
 
488
                    _sqlite_exec("begin");
488
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
489
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
489
                    _sqlite_error(res);
490
                    _sqlite_error(res);
490
 
491
 
491
                    for (i = 0; i < svec_len; i++) {
492
                    for (i = 0; i < svec_len; i++) {
492
                        sqlite3_step(stmt2);
493
                        sqlite3_step(stmt2);
Line 495... Line 496...
495
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
496
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
496
                        sqlite3_bind_int(stmt, 2, (int)sqlite3_column_double(stmt2, 1));
497
                        sqlite3_bind_int(stmt, 2, (int)sqlite3_column_double(stmt2, 1));
497
                        sqlite3_bind_int(stmt, 3, (int)REAL(op2)[i % op2_len]);
498
                        sqlite3_bind_int(stmt, 3, (int)REAL(op2)[i % op2_len]);
498
                        sqlite3_step(stmt);
499
                        sqlite3_step(stmt);
499
                    }
500
                    }
-
 
501
                    _sqlite_exec("commit");
500
                } else { /* non-integer binary operation */
502
                } else { /* non-integer binary operation */
501
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
503
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
-
 
504
                    _sqlite_exec("begin");
502
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
505
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
503
                    _sqlite_error(res);
506
                    _sqlite_error(res);
504
 
507
 
505
                    for (i = 0; i < svec_len; i++) {
508
                    for (i = 0; i < svec_len; i++) {
506
                        sqlite3_step(stmt2);
509
                        sqlite3_step(stmt2);
Line 509... Line 512...
509
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
512
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
510
                        sqlite3_bind_double(stmt, 2, sqlite3_column_double(stmt2, 1));
513
                        sqlite3_bind_double(stmt, 2, sqlite3_column_double(stmt2, 1));
511
                        sqlite3_bind_double(stmt, 3, REAL(op2)[i % op2_len]);
514
                        sqlite3_bind_double(stmt, 3, REAL(op2)[i % op2_len]);
512
                        sqlite3_step(stmt);
515
                        sqlite3_step(stmt);
513
                    }
516
                    }
-
 
517
                    _sqlite_exec("commit");
514
                }
518
                }
515
                sqlite3_finalize(stmt2);
519
                sqlite3_finalize(stmt2);
516
            } else { /* op2_len > svec_len, recycle svec */
520
            } else { /* op2_len > svec_len, recycle svec */
517
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
521
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
518
                        varname_src, iname_src);
522
                        varname_src, iname_src);
Line 525... Line 529...
525
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
529
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
526
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
530
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
527
                    _sqlite_error(res);
531
                    _sqlite_error(res);
528
                }
532
                }
529
               
533
               
530
                i = 0;
534
                i = 0; _sqlite_exec("begin");
531
                while (i < op2_len) {
535
                while (i < op2_len) {
532
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
536
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
533
                    _sqlite_error(res);
537
                    _sqlite_error(res);
534
 
538
 
535
                    if (funcname[0] == '%') {
539
                    if (funcname[0] == '%') {
Line 557... Line 561...
557
                    }
561
                    }
558
 
562
 
559
                    /* recycle on svec if we loop again */
563
                    /* recycle on svec if we loop again */
560
                    sqlite3_finalize(stmt2);
564
                    sqlite3_finalize(stmt2);
561
                }
565
                }
-
 
566
 
-
 
567
                _sqlite_exec("commit");
562
            }
568
            }
563
 
569
 
564
            sqlite3_finalize(stmt);
570
            sqlite3_finalize(stmt);
565
        } else if (IS_INTEGER(op2) || IS_LOGICAL(op2)) { /* I N T E G E R */
571
        } else if (IS_INTEGER(op2) || IS_LOGICAL(op2)) { /* I N T E G E R */
566
            /* we are taking advantage of the fact that logicals are stored as int.
572
            /* we are taking advantage of the fact that logicals are stored as int.
Line 587... Line 593...
587
 
593
 
588
                if (funcname[0] == '%') {
594
                if (funcname[0] == '%') {
589
                    /* sqlite does int div with "/" if both args are int. mod is % also.
595
                    /* sqlite does int div with "/" if both args are int. mod is % also.
590
                     * fortunately, in both cases the sqlite op is 2nd char of funcname */
596
                     * fortunately, in both cases the sqlite op is 2nd char of funcname */
591
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);  
597
                    sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);  
-
 
598
                    _sqlite_exec("begin");
592
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
599
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
593
                    _sqlite_error(res);
600
                    _sqlite_error(res);
594
 
601
 
595
                    for (i = 0; i < svec_len; i++) {
602
                    for (i = 0; i < svec_len; i++) {
596
                        sqlite3_step(stmt2);
603
                        sqlite3_step(stmt2);
Line 599... Line 606...
599
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
606
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
600
                        sqlite3_bind_int(stmt, 2, sqlite3_column_int(stmt2, 1));
607
                        sqlite3_bind_int(stmt, 2, sqlite3_column_int(stmt2, 1));
601
                        sqlite3_bind_int(stmt, 3, INTEGER(op2)[i % op2_len]);
608
                        sqlite3_bind_int(stmt, 3, INTEGER(op2)[i % op2_len]);
602
                        sqlite3_step(stmt);
609
                        sqlite3_step(stmt);
603
                    }
610
                    }
-
 
611
                    _sqlite_exec("commit");
604
                } else {
612
                } else {
605
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
613
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
-
 
614
                    _sqlite_exec("begin");
606
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
615
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
607
                    _sqlite_error(res);
616
                    _sqlite_error(res);
608
 
617
 
609
                    for (i = 0; i < svec_len; i++) {
618
                    for (i = 0; i < svec_len; i++) {
610
                        sqlite3_step(stmt2);
619
                        sqlite3_step(stmt2);
Line 613... Line 622...
613
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
622
                        sqlite3_bind_text(stmt, 1, (char *)sqlite3_column_text(stmt2, 0), -1, SQLITE_STATIC);
614
                        sqlite3_bind_double(stmt, 2, sqlite3_column_double(stmt2, 1));
623
                        sqlite3_bind_double(stmt, 2, sqlite3_column_double(stmt2, 1));
615
                        sqlite3_bind_double(stmt, 3, (double)INTEGER(op2)[i % op2_len]);
624
                        sqlite3_bind_double(stmt, 3, (double)INTEGER(op2)[i % op2_len]);
616
                        sqlite3_step(stmt);
625
                        sqlite3_step(stmt);
617
                    }
626
                    }
-
 
627
                    _sqlite_exec("commit");
618
                }
628
                }
619
                sqlite3_finalize(stmt2);
629
                sqlite3_finalize(stmt2);
620
            } else {
630
            } else {
621
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
631
                sprintf(g_sql_buf[1], "select [%s] from [%s].sdf_data",
622
                        varname_src, iname_src);
632
                        varname_src, iname_src);
Line 629... Line 639...
629
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
639
                    sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
630
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
640
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
631
                    _sqlite_error(res);
641
                    _sqlite_error(res);
632
                }
642
                }
633
               
643
               
634
                i = 0;
644
                i = 0; _sqlite_exec("begin");
635
                while (i < op2_len) {
645
                while (i < op2_len) {
636
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
646
                    res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt2, 0);
637
                    _sqlite_error(res);
647
                    _sqlite_error(res);
638
 
648
 
639
                    if (funcname[0] == '%') {
649
                    if (funcname[0] == '%') {
Line 661... Line 671...
661
                    }
671
                    }
662
 
672
 
663
                    /* recycle on svec if we loop again */
673
                    /* recycle on svec if we loop again */
664
                    sqlite3_finalize(stmt2);
674
                    sqlite3_finalize(stmt2);
665
                }
675
                }
-
 
676
                _sqlite_exec("commit");
666
            }
677
            }
667
 
678
 
668
            sqlite3_finalize(stmt);
679
            sqlite3_finalize(stmt);
669
        } else if (inherits(op2, "sqlite.vector")) { 
680
        } else if (inherits(op2, "sqlite.vector")) { 
670
            /* op2 is surely not a factor, as handled by the R wrapper */
681
            /* op2 is surely not a factor, as handled by the R wrapper */
Line 690... Line 701...
690
            res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt3, 0);
701
            res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt3, 0);
691
            _sqlite_error(res);
702
            _sqlite_error(res);
692
 
703
 
693
            if (funcname[0] == '%') {
704
            if (funcname[0] == '%') {
694
                sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);
705
                sprintf(g_sql_buf[2], insert_fmt_string2c, iname, funcname[1]);
-
 
706
                _sqlite_exec("begin");
695
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
707
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
696
                _sqlite_error(res);
708
                _sqlite_error(res);
697
 
709
 
698
                if (svec_len == op2_len) {
710
                if (svec_len == op2_len) {
699
                    for (i = 0; i < svec_len; i++) {
711
                    for (i = 0; i < svec_len; i++) {
Line 732... Line 744...
732
                            sqlite3_step(stmt);
744
                            sqlite3_step(stmt);
733
                        }
745
                        }
734
                        sqlite3_reset(stmt3);
746
                        sqlite3_reset(stmt3);
735
                    }
747
                    }
736
                }
748
                }
-
 
749
                _sqlite_exec("commit");
737
            } else { /* not an integer op %% or %/% */
750
            } else { /* not an integer op %% or %/% */
738
                sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
751
                sprintf(g_sql_buf[2], insert_fmt_string2s, iname, funcname);
-
 
752
                _sqlite_exec("begin");
739
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
753
                res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
740
                _sqlite_error(res);
754
                _sqlite_error(res);
741
 
755
 
742
                if (svec_len == op2_len) {
756
                if (svec_len == op2_len) {
743
                    for (i = 0; i < svec_len; i++) {
757
                    for (i = 0; i < svec_len; i++) {
Line 776... Line 790...
776
                            sqlite3_step(stmt);
790
                            sqlite3_step(stmt);
777
                        }
791
                        }
778
                        sqlite3_reset(stmt3);
792
                        sqlite3_reset(stmt3);
779
                    }
793
                    }
780
                }
794
                }
-
 
795
                _sqlite_exec("commit");
781
            }
796
            }
782
 
797
 
783
            sqlite3_finalize(stmt);
798
            sqlite3_finalize(stmt);
784
            sqlite3_finalize(stmt2);
799
            sqlite3_finalize(stmt2);
785
            sqlite3_finalize(stmt3);
800
            sqlite3_finalize(stmt3);