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 74... Line 74...
74
        expanded = TRUE;
74
        expanded = TRUE;
75
    }
75
    }
76
    return expanded;
76
    return expanded;
77
}
77
}
78
 
78
 
79
int _sqlite_error(int res) {
79
int _sqlite_error_check(int res, const char *file, int line) {
80
    int ret = FALSE;
80
    int ret = FALSE;
81
    if (res != SQLITE_OK) { 
81
    if (res != SQLITE_OK) { 
82
        Rprintf("SQLITE ERROR: %s\n", sqlite3_errmsg(g_workspace));
82
        Rprintf("SQLITE ERROR (line %d at %s): %s\n", line, file, sqlite3_errmsg(g_workspace));
83
        ret = TRUE;
83
        ret = TRUE;
84
    }
84
    }
85
    return ret;
85
    return ret;
86
}
86
}
87
 
87
 
88
const char *_get_column_type(const char *class, int type) {
88
const char *_get_column_type(const char *class, int type) {
89
    if (type == INTSXP) return "int";
89
    if (type == INTSXP) return "int";
90
    else if (type == REALSXP) return "double";
90
    else if (type == REALSXP) return "double";
91
    else if (type == CHARSXP) return "text";
91
    else if (type == STRSXP) return "text";
92
    else if (type == LGLSXP) return "bit";
92
    else if (type == LGLSXP) return "bit";
93
    else if (strcmp(class, "factor") == 0) return "int"; /* do I really reach this ? */
93
    else if (strcmp(class, "factor") == 0) return "int"; /* do I really reach this ? */
94
    else if (strcmp(class, "ordered") == 0) return "int";
94
    else if (strcmp(class, "ordered") == 0) return "int";
95
    
95
    
96
    return NULL;
96
    return NULL;
Line 186... Line 186...
186
    }
186
    }
187
 
187
 
188
    return ret;
188
    return ret;
189
}
189
}
190
 
190
 
-
 
191
/* return the row names of an sdf as a sqlite.vector */
191
SEXP _get_rownames2(const char *sdf_iname) {
192
SEXP _get_rownames2(const char *sdf_iname) {
192
    sqlite3_stmt *stmt;
193
    sqlite3_stmt *stmt;
193
    sprintf(g_sql_buf[2], "select [row name] from [%s].sdf_data", sdf_iname);
194
    sprintf(g_sql_buf[2], "select [row name] from [%s].sdf_data", sdf_iname);
194
    int res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
195
    int res = sqlite3_prepare(g_workspace, g_sql_buf[2], -1, &stmt, 0);
195
 
196
 
Line 307... Line 308...
307
    }
308
    }
308
 
309
 
309
    return ret;
310
    return ret;
310
}
311
}
311
 
312
 
-
 
313
/* prepare sdf workspace before attaching a new db */
-
 
314
int _prepare_attach2() {
-
 
315
    sqlite3_stmt *stmt;
-
 
316
    int nloaded;
-
 
317
 
-
 
318
    sqlite3_prepare(g_workspace, "select count(*) from workspace where loaded=1",
-
 
319
            -1, &stmt, NULL);
-
 
320
    sqlite3_step(stmt);
-
 
321
    nloaded = sqlite3_column_int(stmt, 0);
-
 
322
    sqlite3_finalize(stmt);
-
 
323
 
-
 
324
    /* test if we have to detach somebody */
-
 
325
    if (nloaded == MAX_ATTACHED) {
-
 
326
        /* have to evict */
-
 
327
        sqlite3_prepare(g_workspace, "select internal_name from workspace "
-
 
328
                "where loaded=1 order by uses", -1, &stmt, NULL);
-
 
329
        sqlite3_step(stmt);
-
 
330
        char *iname2;
-
 
331
        iname2 = (char *)sqlite3_column_text(stmt, 0);
-
 
332
        sprintf(g_sql_buf[2], "detach [%s]", iname2);
-
 
333
        _sqlite_exec(g_sql_buf[2]);
-
 
334
        /* I don't know why I get away with this, but I think
-
 
335
         * I should finalize stmt before I can update workspace table */
-
 
336
        sqlite3_finalize(stmt); 
-
 
337
    }
-
 
338
 
-
 
339
    return nloaded == MAX_ATTACHED;
-
 
340
}
-
 
341
 
-
 
342
char *_str_tolower(char *out, const char *ref) {
-
 
343
    int i;
-
 
344
    for (i = 0; ref[i]; i++) out[i] = tolower(ref[i]);
-
 
345
    return out;
-
 
346
}
-
 
347
 
312
/* see equivalent: inherits() */
348
/* see equivalent: inherits() */
313
/* int _sexp_instance_of(SEXP obj, const char *class) {
349
/* int _sexp_instance_of(SEXP obj, const char *class) {
314
    SEXP obj_class = GET_CLASS(obj);
350
    SEXP obj_class = GET_CLASS(obj);
315
    int ret = 0, len = LENGTH(obj_class), i;
351
    int ret = 0, len = LENGTH(obj_class), i;
316
 
352