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