| 1 |
#include "R.h"
|
1 |
#include "R.h"
|
| 2 |
#include "Rdefines.h"
|
2 |
#include "Rdefines.h"
|
| 3 |
#include "Rinternals.h"
|
3 |
#include "Rinternals.h"
|
| 4 |
#include "sqlite3.h"
|
4 |
#include "sqlite3.h"
|
| 5 |
|
5 |
|
| 6 |
#ifndef __SQLITE_DATAFRAME__
|
6 |
#ifndef __SQLITE_DATAFRAME__
|
| 7 |
#define __SQLITE_DATAFRAME__
|
7 |
#define __SQLITE_DATAFRAME__
|
| 8 |
|
8 |
|
| 9 |
#define WORKSPACE_COLUMNS 5
|
9 |
#define WORKSPACE_COLUMNS 5
|
| - |
|
10 |
#ifndef WIN32
|
| 10 |
#define MAX_ATTACHED 30 /* 31 including workspace.db */
|
11 |
#define MAX_ATTACHED 30 /* 31 including workspace.db */
|
| - |
|
12 |
#else
|
| - |
|
13 |
#define MAX_ATTACHED 10 /* set to 10 until I have recompiled it to 30 */
|
| - |
|
14 |
#endif
|
| 11 |
|
15 |
|
| 12 |
/* utilities for checking characteristics of arg */
|
16 |
/* utilities for checking characteristics of arg */
|
| 13 |
int _is_r_sym(char *sym);
|
17 |
int _is_r_sym(char *sym);
|
| 14 |
int _file_exists(char *filename);
|
18 |
int _file_exists(char *filename);
|
| 15 |
int _sdf_exists2(char *iname);
|
19 |
int _sdf_exists2(char *iname);
|
| 16 |
|
20 |
|
| 17 |
/* sdf utilities */
|
21 |
/* sdf utilities */
|
| 18 |
int USE_SDF(const char *iname); /* call this before doing anything on an SDF */
|
22 |
int USE_SDF(const char *iname, int exists); /* call this before doing anything on an SDF */
|
| 19 |
SEXP _create_sdf_sexp(const char *iname); /* create a SEXP for an SDF */
|
23 |
SEXP _create_sdf_sexp(const char *iname); /* create a SEXP for an SDF */
|
| 20 |
int _add_sdf1(char *filename, char *internal_name); /* add SDF to workspace */
|
24 |
int _add_sdf1(char *filename, char *internal_name); /* add SDF to workspace */
|
| 21 |
void _delete_sdf2(char *iname); /* remove SDF from workspace */
|
25 |
void _delete_sdf2(const char *iname); /* remove SDF from workspace */
|
| 22 |
int _get_factor_levels1(const char *iname, const char *varname, SEXP var);
|
26 |
int _get_factor_levels1(const char *iname, const char *varname, SEXP var);
|
| 23 |
int _get_row_count2(const char *table);
|
27 |
int _get_row_count2(const char *table);
|
| 24 |
SEXP _get_rownames(const char *sdf_iname);
|
28 |
SEXP _get_rownames(const char *sdf_iname);
|
| 25 |
char *_get_full_pathname2(char *relpath); /* get full path given relpath, used in workspace mgmt */
|
29 |
char *_get_full_pathname2(char *relpath); /* get full path given relpath, used in workspace mgmt */
|
| 26 |
|
30 |
|
| 27 |
/* utilities for creating SDF's */
|
31 |
/* utilities for creating SDF's */
|
| 28 |
char *_create_sdf_skeleton2(SEXP name, int *o_namelen);
|
32 |
char *_create_sdf_skeleton2(SEXP name, int *o_namelen);
|
| 29 |
|
33 |
|
| 30 |
/* R utilities */
|
34 |
/* R utilities */
|
| 31 |
SEXP _getListElement(SEXP list, char *varname);
|
35 |
SEXP _getListElement(SEXP list, char *varname);
|
| 32 |
SEXP _shrink_vector(SEXP vec, int len); /* shrink vector size */
|
36 |
SEXP _shrink_vector(SEXP vec, int len); /* shrink vector size */
|
| 33 |
|
37 |
|
| 34 |
/* sqlite utilities */
|
38 |
/* sqlite utilities */
|
| 35 |
int _empty_callback(void *data, int ncols, char **row, char **cols);
|
39 |
int _empty_callback(void *data, int ncols, char **row, char **cols);
|
| 36 |
int _sqlite_error(int res);
|
40 |
int _sqlite_error(int res);
|
| 37 |
const char *_get_column_type(const char *class, int type); /* get sqlite type corresponding to R class & type */
|
41 |
const char *_get_column_type(const char *class, int type); /* get sqlite type corresponding to R class & type */
|
| 38 |
|
42 |
|
| 39 |
/* global buffer (g_sql_buf) utilities */
|
43 |
/* global buffer (g_sql_buf) utilities */
|
| 40 |
int _expand_buf(int i, int size); /* expand ith buf if size > buf[i].size */
|
44 |
int _expand_buf(int i, int size); /* expand ith buf if size > buf[i].size */
|
| 41 |
|
45 |
|
| 42 |
|
46 |
|
| 43 |
/* sqlite.vector utilities */
|
47 |
/* sqlite.vector utilities */
|
| 44 |
SEXP sdf_get_variable(SEXP sdf, SEXP name);
|
48 |
SEXP sdf_get_variable(SEXP sdf, SEXP name);
|
| 45 |
|
49 |
|
| 46 |
/* misc utilities */
|
50 |
/* misc utilities */
|
| 47 |
char *_r2iname(char *internal_name, char *filename);
|
51 |
char *_r2iname(char *internal_name, char *filename);
|
| 48 |
char *_fixname(char *rname);
|
52 |
char *_fixname(char *rname);
|
| 49 |
|
53 |
|
| 50 |
/* register functions to sqlite */
|
54 |
/* register functions to sqlite */
|
| 51 |
void __register_vector_math();
|
55 |
void __register_vector_math();
|
| 52 |
|
56 |
|
| 53 |
#define _sqlite_exec(sql) sqlite3_exec(g_workspace, sql, _empty_callback, NULL, NULL)
|
57 |
#define _sqlite_exec(sql) sqlite3_exec(g_workspace, sql, _empty_callback, NULL, NULL)
|
| 54 |
#ifndef SET_ROWNAMES
|
58 |
#ifndef SET_ROWNAMES
|
| 55 |
#define SET_ROWNAMES(x,n) setAttrib(x, R_RowNamesSymbol, n)
|
59 |
#define SET_ROWNAMES(x,n) setAttrib(x, R_RowNamesSymbol, n)
|
| 56 |
#endif
|
60 |
#endif
|
| 57 |
|
61 |
|
| - |
|
62 |
/* override R's, which does a GetRowNames which is different I believe */
|
| - |
|
63 |
#undef GET_ROWNAMES
|
| - |
|
64 |
#define GET_ROWNAMES(x) getAttrib(x, R_RowNamesSymbol)
|
| - |
|
65 |
|
| 58 |
/* R object accessors shortcuts */
|
66 |
/* R object accessors shortcuts */
|
| 59 |
#define CHAR_ELT(str, i) CHAR(STRING_ELT(str,i))
|
67 |
#define CHAR_ELT(str, i) CHAR(STRING_ELT(str,i))
|
| 60 |
|
68 |
|
| 61 |
/* SDF object accessors shortcuts */
|
69 |
/* SDF object accessors shortcuts */
|
| 62 |
#define SDF_INAME(sdf) CHAR(STRING_ELT(_getListElement(sdf, "iname"),0))
|
70 |
#define SDF_INAME(sdf) CHAR(STRING_ELT(_getListElement(sdf, "iname"),0))
|
| 63 |
#define SVEC_VARNAME(sdf) CHAR(STRING_ELT(_getListElement(sdf, "varname"),0))
|
71 |
#define SVEC_VARNAME(sdf) CHAR(STRING_ELT(_getListElement(sdf, "varname"),0))
|
| 64 |
|
72 |
|
| 65 |
/* # of sql buffers */
|
73 |
/* # of sql buffers */
|
| 66 |
#define NBUFS 4
|
74 |
#define NBUFS 4
|
| 67 |
|
75 |
|
| 68 |
/* possible var types when stored in sqlite as integer */
|
76 |
/* possible var types when stored in sqlite as integer */
|
| 69 |
#define VAR_INTEGER 0
|
77 |
#define VAR_INTEGER 0
|
| 70 |
#define VAR_FACTOR 1
|
78 |
#define VAR_FACTOR 1
|
| 71 |
#define VAR_ORDERED 2
|
79 |
#define VAR_ORDERED 2
|
| 72 |
|
80 |
|
| 73 |
/* detail constants (see _get_sdf_detail2 in sqlite_workspace.c) */
|
81 |
/* detail constants (see _get_sdf_detail2 in sqlite_workspace.c) */
|
| 74 |
#define SDF_DETAIL_EXISTS 0
|
82 |
#define SDF_DETAIL_EXISTS 0
|
| 75 |
#define SDF_DETAIL_FULLFILENAME 1
|
83 |
#define SDF_DETAIL_FULLFILENAME 1
|
| 76 |
|
84 |
|
| 77 |
#ifndef __SQLITE_WORKSPACE__
|
85 |
#ifndef __SQLITE_WORKSPACE__
|
| 78 |
extern sqlite3 *g_workspace;
|
86 |
extern sqlite3 *g_workspace;
|
| 79 |
extern char *g_sql_buf[NBUFS];
|
87 |
extern char *g_sql_buf[NBUFS];
|
| 80 |
extern int g_sql_buf_sz[NBUFS];
|
88 |
extern int g_sql_buf_sz[NBUFS];
|
| 81 |
#endif
|
89 |
#endif
|
| 82 |
|
90 |
|
| 83 |
#endif
|
91 |
#endif
|