The R Project SVN R-packages

Rev

Rev 3700 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3700 Rev 4798
Line 12... Line 12...
12
/****************************************************************************
12
/****************************************************************************
13
 * UTILITY FUNCTIONS
13
 * UTILITY FUNCTIONS
14
 ****************************************************************************/
14
 ****************************************************************************/
15
 
15
 
16
/* test if a file is a sqlite database file */
16
/* test if a file is a sqlite database file */
17
sqlite3* _is_sqlitedb(char *filename) {
17
sqlite3* _is_sqlitedb(const char *filename) {
18
    sqlite3 *db;
18
    sqlite3 *db;
19
    int res;
19
    int res;
20
    res = sqlite3_open(filename, &db);
20
    res = sqlite3_open(filename, &db);
21
    if (res != SQLITE_OK) { goto is_sqlitedb_FAIL; }
21
    if (res != SQLITE_OK) { goto is_sqlitedb_FAIL; }
22
 
22
 
Line 69... Line 69...
69
    return db;
69
    return db;
70
}
70
}
71
 
71
 
72
/* test if a file is a sqlite.data.frame. returns the internal name of the
72
/* test if a file is a sqlite.data.frame. returns the internal name of the
73
 * sdf if file is an sdf or NULL otherwise */
73
 * sdf if file is an sdf or NULL otherwise */
74
char * _is_sdf2(char *filename) {
74
const char * _is_sdf2(const char *filename) {
75
    sqlite3* db = _is_sqlitedb(filename); 
75
    sqlite3* db = _is_sqlitedb(filename); 
76
    char *ret = (db == NULL) ? NULL : filename;
76
    const char *ret = (db == NULL) ? NULL : filename;
77
 
77
 
78
    if (ret) {
78
    if (ret) {
79
        sqlite3_stmt *stmt;
79
        sqlite3_stmt *stmt;
80
        char *sql = "select * from sdf_attributes where attr='name'";
80
        char *sql = "select * from sdf_attributes where attr='name'";
81
        int res, ncols;
81
        int res, ncols;
Line 118... Line 118...
118
    sprintf(g_sql_buf[2], "delete from workspace where internal_name='%s';", iname);
118
    sprintf(g_sql_buf[2], "delete from workspace where internal_name='%s';", iname);
119
    _sqlite_exec(g_sql_buf[2]);
119
    _sqlite_exec(g_sql_buf[2]);
120
}
120
}
121
 
121
 
122
/* add a sdf to the workspace */
122
/* add a sdf to the workspace */
123
int _add_sdf1(char *filename, char *internal_name) {
123
int _add_sdf1(const char *filename, const char *internal_name) {
124
    sprintf(g_sql_buf[1], "insert into workspace(rel_filename, full_filename, "
124
    sprintf(g_sql_buf[1], "insert into workspace(rel_filename, full_filename, "
125
            "internal_name, loaded, uses, used) values('%s', '%s', '%s', 0, 0, 0)",
125
            "internal_name, loaded, uses, used) values('%s', '%s', '%s', 0, 0, 0)",
126
            filename, _get_full_pathname2(filename), internal_name);
126
            filename, _get_full_pathname2(filename), internal_name);
127
 
127
 
128
    return _sqlite_exec(g_sql_buf[1]);
128
    return _sqlite_exec(g_sql_buf[1]);
129
}
129
}
130
 
130
 
131
 
131
 
132
static char* _get_sdf_detail2(char *iname, int what) {
132
static char* _get_sdf_detail2(const char *iname, int what) {
133
    sqlite3_stmt *stmt;
133
    sqlite3_stmt *stmt;
134
    char * ret; int res;
134
    char * ret; int res;
135
 
135
 
136
    sprintf(g_sql_buf[2], "select full_filename from workspace where "
136
    sprintf(g_sql_buf[2], "select full_filename from workspace where "
137
            "internal_name='%s'", iname);
137
            "internal_name='%s'", iname);
Line 154... Line 154...
154
 
154
 
155
    return ret;
155
    return ret;
156
}
156
}
157
 
157
 
158
/* returns TRUE if sdf exists in the workspace */
158
/* returns TRUE if sdf exists in the workspace */
159
int _sdf_exists2(char *iname) {
159
int _sdf_exists2(const char *iname) {
160
    return _get_sdf_detail2(iname, SDF_DETAIL_EXISTS) != NULL;
160
    return _get_sdf_detail2(iname, SDF_DETAIL_EXISTS) != NULL;
161
}
161
}
162
 
162
 
163
/****************************************************************************
163
/****************************************************************************
164
 * WORKSPACE FUNCTIONS
164
 * WORKSPACE FUNCTIONS
Line 362... Line 362...
362
    UNPROTECT(1);
362
    UNPROTECT(1);
363
    return ret;
363
    return ret;
364
}
364
}
365
 
365
 
366
SEXP sdf_get_sdf(SEXP name) {    
366
SEXP sdf_get_sdf(SEXP name) {    
367
    char *iname;
367
    const char *iname;
368
    SEXP ret;
368
    SEXP ret;
369
 
369
 
370
    if (TYPEOF(name) != STRSXP) {
370
    if (TYPEOF(name) != STRSXP) {
371
        error("Argument must be a string containing the SDF name.");
371
        error("Argument must be a string containing the SDF name.");
372
    }
372
    }
Line 379... Line 379...
379
}
379
}
380
 
380
 
381
SEXP sdf_attach_sdf(SEXP filename, SEXP internal_name) {
381
SEXP sdf_attach_sdf(SEXP filename, SEXP internal_name) {
382
    /* when studying this, please be mindful of the global buffers used.
382
    /* when studying this, please be mindful of the global buffers used.
383
     * you have been warned */
383
     * you have been warned */
384
    char *fname=NULL, *iname, *iname_orig=NULL;
384
    const char *fname=NULL, *iname, *iname_orig=NULL;
385
    int fnamelen=0, res;
385
    int fnamelen=0, res;
386
    sqlite3_stmt *stmt;
386
    sqlite3_stmt *stmt;
387
 
387
 
388
    if (IS_CHARACTER(filename)) {
388
    if (IS_CHARACTER(filename)) {
389
        fname = CHAR_ELT(filename, 0);
389
        fname = CHAR_ELT(filename, 0);
Line 475... Line 475...
475
}
475
}
476
 
476
 
477
/* not necessary anymore, since stuffs will eventually be detached
477
/* not necessary anymore, since stuffs will eventually be detached
478
 * if we keep on adding new sdfs */
478
 * if we keep on adding new sdfs */
479
SEXP sdf_detach_sdf(SEXP internal_name) {
479
SEXP sdf_detach_sdf(SEXP internal_name) {
480
    char *iname;
480
    const char *iname;
481
    int res;
481
    int res;
482
 
482
 
483
    if (!IS_CHARACTER(internal_name)) {
483
    if (!IS_CHARACTER(internal_name)) {
484
        error("iname argument is not a string.");
484
        error("iname argument is not a string.");
485
    }
485
    }
Line 494... Line 494...
494
    
494
    
495
    return ScalarLogical(res);
495
    return ScalarLogical(res);
496
}
496
}
497
 
497
 
498
SEXP sdf_rename_sdf(SEXP sdf, SEXP name) {
498
SEXP sdf_rename_sdf(SEXP sdf, SEXP name) {
499
    char *iname, *path, *newname;
499
    const char *iname, *newname;
-
 
500
    char *path; 
500
    int res, ret_tmp;
501
    int res, ret_tmp;
501
 
502
 
502
    iname = SDF_INAME(sdf);
503
    iname = SDF_INAME(sdf);
503
    newname = CHAR_ELT(name, 0);
504
    newname = CHAR_ELT(name, 0);
504
    
505