Updates to existing R->c files
This commit is contained in:
@@ -2,14 +2,15 @@
|
|||||||
|
|
||||||
#include "R_modb_manage.h"
|
#include "R_modb_manage.h"
|
||||||
#include "R_list_item.h"
|
#include "R_list_item.h"
|
||||||
#include "modb_manage.h"
|
|
||||||
|
|
||||||
#include "R_helpers_p.h"
|
#include "R_helpers_p.h"
|
||||||
|
|
||||||
|
#include "modb_database.h"
|
||||||
|
|
||||||
SEXP modb_connectionInfo(SEXP r_conn_ref)
|
|
||||||
|
|
||||||
|
SEXP rmodb_connectionInfo(SEXP r_conn_ref)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
SEXP res, conn_name, last_qry, names;
|
SEXP res, conn_name, last_qry, names;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
@@ -43,10 +44,10 @@ SEXP modb_connectionInfo(SEXP r_conn_ref)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
SEXP modb_connectToHost(SEXP r_name, SEXP r_host, SEXP r_port,
|
SEXP rmodb_connectToHost(SEXP r_name, SEXP r_host, SEXP r_port,
|
||||||
SEXP r_username, SEXP r_password, SEXP r_database)
|
SEXP r_username, SEXP r_password, SEXP r_database)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
const char *name = 0, *host, *user, *pass, *db;
|
const char *name = 0, *host, *user, *pass, *db;
|
||||||
unsigned int port;
|
unsigned int port;
|
||||||
|
|
||||||
@@ -72,10 +73,10 @@ SEXP modb_connectToHost(SEXP r_name, SEXP r_host, SEXP r_port,
|
|||||||
|
|
||||||
return Rf_ScalarInteger(sconn->conn_id);
|
return Rf_ScalarInteger(sconn->conn_id);
|
||||||
}
|
}
|
||||||
SEXP modb_connectToSocket(SEXP r_name, SEXP r_socket,
|
SEXP rmodb_connectToSocket(SEXP r_name, SEXP r_socket,
|
||||||
SEXP r_username, SEXP r_password, SEXP r_database)
|
SEXP r_username, SEXP r_password, SEXP r_database)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
const char *name = 0, *sock, *user, *pass, *db;
|
const char *name = 0, *sock, *user, *pass, *db;
|
||||||
|
|
||||||
if (!Rf_isNull(r_name)) {
|
if (!Rf_isNull(r_name)) {
|
||||||
@@ -99,9 +100,9 @@ SEXP modb_connectToSocket(SEXP r_name, SEXP r_socket,
|
|||||||
|
|
||||||
return Rf_ScalarInteger(sconn->conn_id);
|
return Rf_ScalarInteger(sconn->conn_id);
|
||||||
}
|
}
|
||||||
SEXP modb_disconnect(SEXP r_conn_ref)
|
SEXP rmodb_disconnect(SEXP r_conn_ref)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
int conn_id;
|
int conn_id;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
@@ -118,10 +119,10 @@ SEXP modb_disconnect(SEXP r_conn_ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SEXP modb_exists(SEXP r_conn_ref, SEXP r_name)
|
SEXP rmodb_exists(SEXP r_conn_ref, SEXP r_name)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
struct modb_ref_t modb;
|
modb_ref modb;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
Rf_error("invalid connection reference\n");
|
Rf_error("invalid connection reference\n");
|
||||||
@@ -133,13 +134,13 @@ SEXP modb_exists(SEXP r_conn_ref, SEXP r_name)
|
|||||||
return Rf_ScalarLogical(modbExists(sconn, &modb));
|
return Rf_ScalarLogical(modbExists(sconn, &modb));
|
||||||
}
|
}
|
||||||
|
|
||||||
SEXP modb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta)
|
SEXP rmodb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
struct modb_ref_t modb;
|
modb_ref modb;
|
||||||
struct column_data_t **cols;
|
struct column_data_t **cols = 0;
|
||||||
size_t n_cols;
|
size_t n_cols = 0;
|
||||||
SEXP r_col, r_col_name, r_col_type, r_col_null;
|
SEXP r_col, r_col_name, r_col_type, r_col_null, r_col_max_len;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
Rf_error("invalid connection reference\n");
|
Rf_error("invalid connection reference\n");
|
||||||
@@ -153,19 +154,11 @@ SEXP modb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta)
|
|||||||
return Rf_ScalarLogical(FALSE);
|
return Rf_ScalarLogical(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!modbCreate(sconn, &modb)) {
|
|
||||||
modb_destroy(r_conn_ref, r_name);
|
|
||||||
Rf_error("failed to create MODB instance");
|
|
||||||
}
|
|
||||||
if (!modbAccountingCreate(sconn, &modb)) {
|
|
||||||
modb_destroy(r_conn_ref, r_name);
|
|
||||||
Rf_error("failed to create MODB instance");
|
|
||||||
}
|
|
||||||
if (!Rf_isNull(r_extra_meta)) {
|
if (!Rf_isNull(r_extra_meta)) {
|
||||||
n_cols = (size_t)Rf_length(r_extra_meta);
|
n_cols = (size_t)Rf_length(r_extra_meta);
|
||||||
cols = (struct column_data_t **)calloc(sizeof(struct column_data_t *), n_cols);
|
cols = (struct column_data_t **)calloc(sizeof(struct column_data_t *), n_cols);
|
||||||
if (cols == 0) {
|
if (cols == 0) {
|
||||||
modb_destroy(r_conn_ref, r_name);
|
rmodb_destroy(r_conn_ref, r_name);
|
||||||
Rf_error("failed to create MODB instance");
|
Rf_error("failed to create MODB instance");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,6 +167,7 @@ SEXP modb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta)
|
|||||||
r_col_name = STRING_ELT(R_listItem(r_col, "name"), 0);
|
r_col_name = STRING_ELT(R_listItem(r_col, "name"), 0);
|
||||||
r_col_type = R_listItem(r_col, "type");
|
r_col_type = R_listItem(r_col, "type");
|
||||||
r_col_null = R_listItem(r_col, "nullable");
|
r_col_null = R_listItem(r_col, "nullable");
|
||||||
|
r_col_max_len = R_listItem(r_col, "max_length");
|
||||||
|
|
||||||
*(cols + i) = initEmptyColumn(
|
*(cols + i) = initEmptyColumn(
|
||||||
(e_column_type)(unsigned int)Rf_asInteger(r_col_type),
|
(e_column_type)(unsigned int)Rf_asInteger(r_col_type),
|
||||||
@@ -182,26 +176,30 @@ SEXP modb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta)
|
|||||||
0, 0, 0);
|
0, 0, 0);
|
||||||
if (*(cols + i) == 0) {
|
if (*(cols + i) == 0) {
|
||||||
freeColumns(cols, i);
|
freeColumns(cols, i);
|
||||||
modb_destroy(r_conn_ref, r_name);
|
rmodb_destroy(r_conn_ref, r_name);
|
||||||
Rf_error("failed to create MODB instance");
|
Rf_error("failed to create MODB instance");
|
||||||
}
|
}
|
||||||
|
if (r_col_max_len != R_NilValue && (*(cols + i))->type == TYPE_STRING) {
|
||||||
|
(*(cols + i))->max_len = (unsigned int)Rf_asInteger(r_col_max_len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!modbMetaExtCreate(sconn, &modb, cols, n_cols)) {
|
if (!modbCreate(sconn, &modb, cols, n_cols)) {
|
||||||
freeColumns(cols, n_cols);
|
rmodb_destroy(r_conn_ref, r_name);
|
||||||
modb_destroy(r_conn_ref, r_name);
|
Rf_error("failed to create MODB instance");
|
||||||
Rf_error("failed to create MODB instance");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (n_cols > 0) {
|
||||||
freeColumns(cols, n_cols);
|
freeColumns(cols, n_cols);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Rf_ScalarLogical(TRUE);
|
return Rf_ScalarLogical(TRUE);
|
||||||
}
|
}
|
||||||
SEXP modb_destroy(SEXP r_conn_ref, SEXP r_name)
|
SEXP rmodb_destroy(SEXP r_conn_ref, SEXP r_name)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
struct modb_ref_t modb;
|
modb_ref modb;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
Rf_error("invalid connection reference\n");
|
Rf_error("invalid connection reference\n");
|
||||||
@@ -210,20 +208,16 @@ SEXP modb_destroy(SEXP r_conn_ref, SEXP r_name)
|
|||||||
modb.name = Rf_translateCharUTF8(STRING_ELT(r_name, 0));
|
modb.name = Rf_translateCharUTF8(STRING_ELT(r_name, 0));
|
||||||
modb.name_len = strlen(modb.name);
|
modb.name_len = strlen(modb.name);
|
||||||
|
|
||||||
if (modbMetaExtExists(sconn, &modb)) {
|
|
||||||
modbMetaExtDestroy(sconn, &modb);
|
|
||||||
}
|
|
||||||
modbAccountingDestroy(sconn, &modb);
|
|
||||||
modbDestroy(sconn, &modb);
|
modbDestroy(sconn, &modb);
|
||||||
|
|
||||||
return Rf_ScalarLogical(TRUE);
|
return Rf_ScalarLogical(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SEXP modb_use(SEXP r_conn_ref, SEXP r_name, SEXP r_override)
|
SEXP rmodb_use(SEXP r_conn_ref, SEXP r_name, SEXP r_override)
|
||||||
{
|
{
|
||||||
struct stored_conn_t *sconn;
|
stored_conn *sconn;
|
||||||
struct modb_ref_t modb;
|
modb_ref modb;
|
||||||
|
|
||||||
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
if ((sconn = getConnectionByRef(r_conn_ref)) == 0) {
|
||||||
Rf_error("invalid connection reference\n");
|
Rf_error("invalid connection reference\n");
|
||||||
|
|||||||
@@ -4,23 +4,24 @@
|
|||||||
#include <Rinternals.h>
|
#include <Rinternals.h>
|
||||||
|
|
||||||
// Connections
|
// Connections
|
||||||
SEXP modb_connectionInfo(SEXP r_conn_ref);
|
SEXP rmodb_connectionInfo(SEXP r_conn_ref);
|
||||||
|
|
||||||
SEXP modb_connectToHost(SEXP r_name, SEXP r_host, SEXP r_port,
|
SEXP rmodb_connectToHost(SEXP r_name, SEXP r_host, SEXP r_port,
|
||||||
SEXP r_username, SEXP r_password, SEXP r_database);
|
SEXP r_username, SEXP r_password, SEXP r_database);
|
||||||
SEXP modb_connectToSocket(SEXP r_name, SEXP r_socket,
|
SEXP rmodb_connectToSocket(SEXP r_name, SEXP r_socket,
|
||||||
SEXP r_username, SEXP r_password, SEXP r_database);
|
SEXP r_username, SEXP r_password, SEXP r_database);
|
||||||
SEXP modb_disconnect(SEXP r_conn_ref);
|
SEXP rmodb_disconnect(SEXP r_conn_ref);
|
||||||
|
|
||||||
|
|
||||||
// MODB instances
|
// MODB instances
|
||||||
SEXP modb_exists(SEXP r_conn_ref, SEXP r_name);
|
SEXP rmodb_exists(SEXP r_conn_ref, SEXP r_name);
|
||||||
|
|
||||||
SEXP modb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta);
|
SEXP rmodb_create(SEXP r_conn_ref, SEXP r_name, SEXP r_extra_meta);
|
||||||
SEXP modb_destroy(SEXP r_conn_ref, SEXP r_name);
|
SEXP rmodb_destroy(SEXP r_conn_ref, SEXP r_name);
|
||||||
|
|
||||||
|
|
||||||
// Link connection to MODB instance
|
// Link connection to MODB instance
|
||||||
SEXP modb_use(SEXP r_conn_ref, SEXP r_name, SEXP r_override);
|
SEXP rmodb_use(SEXP r_conn_ref, SEXP r_name, SEXP r_override);
|
||||||
|
|
||||||
|
|
||||||
#endif // H__R_MODB_MANAGE__
|
#endif // H__R_MODB_MANAGE__
|
||||||
|
|||||||
Reference in New Issue
Block a user