The R Project SVN R-packages

Rev

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

Rev 3419 Rev 3426
Line 10... Line 10...
10
 * default "data" */
10
 * default "data" */
11
static int _check_sdf_name(SEXP name, char **rname, char **iname, int *file_idx) {
11
static int _check_sdf_name(SEXP name, char **rname, char **iname, int *file_idx) {
12
    int namelen = 0;
12
    int namelen = 0;
13
 
13
 
14
    /* check if arg name is supplied */
14
    /* check if arg name is supplied */
-
 
15
    if (name == R_NilValue) {
-
 
16
        *rname = "data";
-
 
17
        namelen = 5;
-
 
18
        *iname = (char*)R_alloc(13, sizeof(char)); /* data10000.db\0 */
-
 
19
        *file_idx = 1;
-
 
20
        sprintf(*iname, "%s%d.db", *rname, *file_idx);
15
    if (IS_CHARACTER(name)) {
21
    } else if (IS_CHARACTER(name)) {
16
        *rname = CHAR_ELT(name,0);
22
        *rname = CHAR_ELT(name,0);
17
        if (!_is_r_sym(*rname)) { 
23
        if (!_is_r_sym(*rname)) { 
18
            Rprintf("Error: supplied name \"%s\"is not a valid R symbol.\n", 
24
            Rprintf("Error: supplied name \"%s\"is not a valid R symbol.\n", 
19
                    *rname); 
25
                    *rname); 
20
            return FALSE; 
26
            return FALSE; 
21
        }
27
        }
22
        namelen = strlen(*rname);
28
        namelen = strlen(*rname);
23
        *iname = (char*)R_alloc(namelen + 9, sizeof(char)); /* <name>10000.db\0 */
29
        *iname = (char*)R_alloc(namelen + 9, sizeof(char)); /* <name>10000.db\0 */
24
        sprintf(*iname, "%s.db", *rname);
30
        sprintf(*iname, "%s.db", *rname);
25
    } else if (name == R_NilValue) {
-
 
26
        *rname = "data";
-
 
27
        namelen = 5;
-
 
28
        *iname = (char*)R_alloc(13, sizeof(char)); /* data10000.db\0 */
-
 
29
        *file_idx = 1;
-
 
30
        sprintf(*iname, "%s%d.db", *rname, *file_idx);
-
 
31
    } else {
31
    } else {
32
        Rprintf("Error: the supplied value for arg name is not a string.\n");
32
        Rprintf("Error: the supplied value for arg name is not a string.\n");
33
    }
33
    }
34
    return namelen;
34
    return namelen;
35
}
35
}
Line 249... Line 249...
249
    if (iname != NULL) {
249
    if (iname != NULL) {
250
        int sql_len, sql_len2;
250
        int sql_len, sql_len2;
251
        sqlite3_stmt *stmt;
251
        sqlite3_stmt *stmt;
252
 
252
 
253
        /* create sdf_data table */
253
        /* create sdf_data table */
254
        SEXP names = GET_NAMES(df), variable, levels;
254
        SEXP names = GET_NAMES(df), variable, levels, var_class;
255
        int ncols = GET_LENGTH(names), type, *types;
255
        int ncols = GET_LENGTH(names), type, *types;
256
        char *col_name, *class, *factor;
256
        char *col_name, *class, *factor;
257
 
257
 
258
        /* variables for adding rownames */
258
        /* variables for adding rownames */
259
        SEXP rownames;
259
        SEXP rownames;
Line 276... Line 276...
276
 
276
 
277
            /* add column definition to the create table sql */
277
            /* add column definition to the create table sql */
278
            _expand_buf(0, sql_len+strlen(col_name)+10);
278
            _expand_buf(0, sql_len+strlen(col_name)+10);
279
 
279
 
280
            variable = _getListElement(df, col_name);
280
            variable = _getListElement(df, col_name);
281
            class = CHAR(STRING_ELT(GET_CLASS(variable), 0));
281
            var_class = GET_CLASS(variable);
-
 
282
            class = (var_class == R_NilValue) ? NULL : CHAR(STRING_ELT(var_class, 0));
282
            type = TYPEOF(variable);
283
            type = TYPEOF(variable);
283
            types[i] = type;
284
            types[i] = type;
284
 
285
 
285
            sql_len += sprintf(g_sql_buf[0]+sql_len, ", [%s] %s", col_name, 
286
            sql_len += sprintf(g_sql_buf[0]+sql_len, ", [%s] %s", col_name, 
286
                    _get_column_type(class, type));
287
                    _get_column_type(class, type));
Line 289... Line 290...
289
            _expand_buf(1, sql_len+5);
290
            _expand_buf(1, sql_len+5);
290
            strcpy(g_sql_buf[1]+sql_len2, ",?");
291
            strcpy(g_sql_buf[1]+sql_len2, ",?");
291
            sql_len2 += 2; 
292
            sql_len2 += 2; 
292
 
293
 
293
            /* create separate table for factors decode */
294
            /* create separate table for factors decode */
294
            if (strcmp(class, "factor") == 0 || strcmp(class, "ordered") == 0){
295
            if (class != NULL && (strcmp(class, "factor") == 0 || strcmp(class, "ordered") == 0)){
295
                if (_create_factor_table2(iname, class, col_name)) 
296
                if (_create_factor_table2(iname, class, col_name)) 
296
                    return R_NilValue; /* dup tbl name? */
297
                    return R_NilValue; /* dup tbl name? */
297
 
298
 
298
                _sqlite_exec("begin");
299
                _sqlite_exec("begin");
299
                levels = GET_LEVELS(variable);
300
                levels = GET_LEVELS(variable);