consult Yap.h to get ocnfig.h
This commit is contained in:
parent
d3796aba5a
commit
f20599478e
@ -14,10 +14,10 @@
|
|||||||
* comments: Predicates for maintaining MYDDAS *
|
* comments: Predicates for maintaining MYDDAS *
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
#include "Yap.h"
|
||||||
|
|
||||||
#ifdef USE_MYDDAS
|
#ifdef USE_MYDDAS
|
||||||
|
|
||||||
#include "Yap.h"
|
|
||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "cut_c.h"
|
#include "cut_c.h"
|
||||||
#include "myddas.h"
|
#include "myddas.h"
|
||||||
@ -28,101 +28,93 @@
|
|||||||
|
|
||||||
void init_myddas(void);
|
void init_myddas(void);
|
||||||
|
|
||||||
static Int c_db_initialize_myddas( USES_REGS1 );
|
static Int c_db_initialize_myddas(USES_REGS1);
|
||||||
static Int c_db_connection_type( USES_REGS1 );
|
static Int c_db_connection_type(USES_REGS1);
|
||||||
static Int c_db_add_preds( USES_REGS1 );
|
static Int c_db_add_preds(USES_REGS1);
|
||||||
static Int c_db_preds_conn_start ( USES_REGS1 );
|
static Int c_db_preds_conn_start(USES_REGS1);
|
||||||
static Int c_db_preds_conn_continue ( USES_REGS1 );
|
static Int c_db_preds_conn_continue(USES_REGS1);
|
||||||
static Int c_db_connection_start ( USES_REGS1 );
|
static Int c_db_connection_start(USES_REGS1);
|
||||||
static Int c_db_connection_continue ( USES_REGS1 );
|
static Int c_db_connection_continue(USES_REGS1);
|
||||||
static Int c_db_check_if_exists_pred( USES_REGS1 );
|
static Int c_db_check_if_exists_pred(USES_REGS1);
|
||||||
static Int c_db_delete_predicate( USES_REGS1 );
|
static Int c_db_delete_predicate(USES_REGS1);
|
||||||
static Int c_db_multi_queries_number( USES_REGS1 );
|
static Int c_db_multi_queries_number(USES_REGS1);
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
static Int c_db_stats( USES_REGS1 );
|
static Int c_db_stats(USES_REGS1);
|
||||||
static Int c_db_stats_walltime( USES_REGS1 );
|
static Int c_db_stats_walltime(USES_REGS1);
|
||||||
static Int c_db_stats_translate( USES_REGS1 );
|
static Int c_db_stats_translate(USES_REGS1);
|
||||||
static Int c_db_stats_time( USES_REGS1 );
|
static Int c_db_stats_time(USES_REGS1);
|
||||||
#endif
|
#endif
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static Int c_db_check( USES_REGS1 );
|
static Int c_db_check(USES_REGS1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void Yap_InitMYDDAS_SharedPreds(void)
|
void Yap_InitMYDDAS_SharedPreds(void) {
|
||||||
{
|
|
||||||
/* c_db_initialize_myddas */
|
/* c_db_initialize_myddas */
|
||||||
Yap_InitCPred("c_db_initialize_myddas",0,c_db_initialize_myddas, 0);
|
Yap_InitCPred("c_db_initialize_myddas", 0, c_db_initialize_myddas, 0);
|
||||||
|
|
||||||
/* c_db_connection_type: Connection x Type */
|
/* c_db_connection_type: Connection x Type */
|
||||||
Yap_InitCPred("c_db_connection_type",2,c_db_connection_type, 0);
|
Yap_InitCPred("c_db_connection_type", 2, c_db_connection_type, 0);
|
||||||
|
|
||||||
/* CORRECT THIS: db_add_preds : PredName * Arity * Connection */
|
/* CORRECT THIS: db_add_preds : PredName * Arity * Connection */
|
||||||
Yap_InitCPred("c_db_add_preds",4,c_db_add_preds, 0);
|
Yap_InitCPred("c_db_add_preds", 4, c_db_add_preds, 0);
|
||||||
|
|
||||||
/* c_db_check_if_exists_pred : PredName * Arity * Connection */
|
/* c_db_check_if_exists_pred : PredName * Arity * Connection */
|
||||||
Yap_InitCPred("c_db_check_if_exists_pred",3,c_db_check_if_exists_pred, 0);
|
Yap_InitCPred("c_db_check_if_exists_pred", 3, c_db_check_if_exists_pred, 0);
|
||||||
|
|
||||||
/* c_db_delete_pred : Module * PredName * Arity */
|
/* c_db_delete_pred : Module * PredName * Arity */
|
||||||
Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0);
|
Yap_InitCPred("c_db_delete_predicate", 3, c_db_delete_predicate, 0);
|
||||||
|
|
||||||
/* c_db_delete_pred : Module * PredName * Arity */
|
/* c_db_delete_pred : Module * PredName * Arity */
|
||||||
Yap_InitCPred("c_db_multi_queries_number",2,c_db_multi_queries_number, 0);
|
Yap_InitCPred("c_db_multi_queries_number", 2, c_db_multi_queries_number, 0);
|
||||||
|
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
/* c_db_stats: Connection * Stats */
|
/* c_db_stats: Connection * Stats */
|
||||||
Yap_InitCPred("c_db_stats",2, c_db_stats, 0);
|
Yap_InitCPred("c_db_stats", 2, c_db_stats, 0);
|
||||||
|
|
||||||
/* c_db_stats_walltime */
|
/* c_db_stats_walltime */
|
||||||
Yap_InitCPred("c_db_stats_walltime",1, c_db_stats_walltime, 0);
|
Yap_InitCPred("c_db_stats_walltime", 1, c_db_stats_walltime, 0);
|
||||||
|
|
||||||
/* c_db_stats_translate */
|
/* c_db_stats_translate */
|
||||||
Yap_InitCPred("c_db_stats_translate",2,c_db_stats_translate, 0);
|
Yap_InitCPred("c_db_stats_translate", 2, c_db_stats_translate, 0);
|
||||||
|
|
||||||
/* c_db_stats_time */
|
/* c_db_stats_time */
|
||||||
Yap_InitCPred("c_db_stats_time",2,c_db_stats_time, 0);
|
Yap_InitCPred("c_db_stats_time", 2, c_db_stats_time, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Yap_InitCPred("c_db_check",0, c_db_check, 0);
|
Yap_InitCPred("c_db_check", 0, c_db_check, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_InitBackMYDDAS_SharedPreds(void)
|
void Yap_InitBackMYDDAS_SharedPreds(void) {
|
||||||
{
|
|
||||||
/* Gives all the predicates associated to a given connection */
|
/* Gives all the predicates associated to a given connection */
|
||||||
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(Int),
|
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(Int), c_db_preds_conn_start,
|
||||||
c_db_preds_conn_start,
|
c_db_preds_conn_continue, 0);
|
||||||
c_db_preds_conn_continue, 0);
|
|
||||||
/* Gives all the connections stored on the MYDDAS Structure*/
|
/* Gives all the connections stored on the MYDDAS Structure*/
|
||||||
Yap_InitCPredBack("c_db_connection", 1, sizeof(Int),
|
Yap_InitCPredBack("c_db_connection", 1, sizeof(Int), c_db_connection_start,
|
||||||
c_db_connection_start,
|
c_db_connection_continue, 0);
|
||||||
c_db_connection_continue, 0);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize all of the MYDDAS global structures */
|
/* Initialize all of the MYDDAS global structures */
|
||||||
static Int
|
static Int c_db_initialize_myddas(USES_REGS1) {
|
||||||
c_db_initialize_myddas( USES_REGS1 ){
|
|
||||||
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_init_initialize_myddas();
|
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_init_initialize_myddas();
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_stats_initialize_global_stats(Yap_REGS.MYDDAS_GLOBAL_POINTER);
|
Yap_REGS.MYDDAS_GLOBAL_POINTER =
|
||||||
|
myddas_stats_initialize_global_stats(Yap_REGS.MYDDAS_GLOBAL_POINTER);
|
||||||
#endif /* MYDDAS_STATS */
|
#endif /* MYDDAS_STATS */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Gives the type of a given connection,
|
/* Gives the type of a given connection,
|
||||||
in other words, type will be mysql or odbc
|
in other words, type will be mysql or odbc
|
||||||
|
|
||||||
NOTE: In order to use this predicate, the connection*/
|
NOTE: In order to use this predicate, the connection*/
|
||||||
/* c_db_connection_type: +Connection * ?Type */
|
/* c_db_connection_type: +Connection * ?Type */
|
||||||
static Int
|
static Int c_db_connection_type(USES_REGS1) {
|
||||||
c_db_connection_type ( USES_REGS1 ){
|
|
||||||
Term arg_con = Deref(ARG1);
|
Term arg_con = Deref(ARG1);
|
||||||
Term arg_type =ARG2;
|
Term arg_type = ARG2;
|
||||||
|
|
||||||
Int *con = (Int *) IntegerOfTerm(arg_con);
|
Int *con = (Int *)IntegerOfTerm(arg_con);
|
||||||
MYDDAS_API type = myddas_util_connection_type(con);
|
MYDDAS_API type = myddas_util_connection_type(con);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -143,54 +135,47 @@ c_db_connection_type ( USES_REGS1 ){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* db_add_preds: PredName * Arity * Module * Connection*/
|
/* db_add_preds: PredName * Arity * Module * Connection*/
|
||||||
static Int
|
static Int c_db_add_preds(USES_REGS1) {
|
||||||
c_db_add_preds ( USES_REGS1 ){
|
|
||||||
Term arg_nome = Deref(ARG1);
|
Term arg_nome = Deref(ARG1);
|
||||||
Term arg_aridade = Deref(ARG2);
|
Term arg_aridade = Deref(ARG2);
|
||||||
Term arg_module = Deref(ARG3);
|
Term arg_module = Deref(ARG3);
|
||||||
Term arg_conn = Deref(ARG4);
|
Term arg_conn = Deref(ARG4);
|
||||||
|
|
||||||
/* PredEntry *pe; */
|
/* PredEntry *pe; */
|
||||||
/* pe = RepPredProp(PredPropByFunc(FunctorOfTerm(arg_pred),arg_module)); */
|
/* pe = RepPredProp(PredPropByFunc(FunctorOfTerm(arg_pred),arg_module)); */
|
||||||
|
|
||||||
|
|
||||||
const char *nome = AtomName(AtomOfTerm(arg_nome));
|
const char *nome = AtomName(AtomOfTerm(arg_nome));
|
||||||
const char *module = AtomName(AtomOfTerm(arg_module));
|
const char *module = AtomName(AtomOfTerm(arg_module));
|
||||||
Int aridade = IntegerOfTerm(arg_aridade);
|
Int aridade = IntegerOfTerm(arg_aridade);
|
||||||
Int *conn = (Int *) IntegerOfTerm(arg_conn);
|
Int *conn = (Int *)IntegerOfTerm(arg_conn);
|
||||||
|
|
||||||
if (myddas_util_add_predicate(nome,aridade,module,conn) == NULL)
|
if (myddas_util_add_predicate(nome, aridade, module, conn) == NULL) {
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf ("ERROR : Could not add Predicate: Line: %d File: %s\n",__LINE__,__FILE__);
|
printf("ERROR : Could not add Predicate: Line: %d File: %s\n", __LINE__,
|
||||||
|
__FILE__);
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int c_db_check_if_exists_pred(USES_REGS1) {
|
||||||
static Int
|
|
||||||
c_db_check_if_exists_pred ( USES_REGS1 ){
|
|
||||||
Term arg_nome = Deref(ARG1);
|
Term arg_nome = Deref(ARG1);
|
||||||
Term arg_aridade = Deref(ARG2);
|
Term arg_aridade = Deref(ARG2);
|
||||||
Term arg_module = Deref(ARG3);
|
Term arg_module = Deref(ARG3);
|
||||||
|
|
||||||
|
|
||||||
const char *nome = AtomName(AtomOfTerm(arg_nome));
|
const char *nome = AtomName(AtomOfTerm(arg_nome));
|
||||||
const char *module = AtomName(AtomOfTerm(arg_module));
|
const char *module = AtomName(AtomOfTerm(arg_module));
|
||||||
Int aridade = IntegerOfTerm(arg_aridade);
|
Int aridade = IntegerOfTerm(arg_aridade);
|
||||||
|
|
||||||
if (myddas_util_search_predicate(nome,aridade,module) == NULL)
|
if (myddas_util_search_predicate(nome, aridade, module) == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
else
|
else
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int c_db_delete_predicate(USES_REGS1) {
|
||||||
static Int
|
|
||||||
c_db_delete_predicate( USES_REGS1 ){
|
|
||||||
Term arg_module = Deref(ARG1);
|
Term arg_module = Deref(ARG1);
|
||||||
Term arg_name = Deref(ARG2);
|
Term arg_name = Deref(ARG2);
|
||||||
Term arg_arity = Deref(ARG3);
|
Term arg_arity = Deref(ARG3);
|
||||||
@ -200,7 +185,7 @@ c_db_delete_predicate( USES_REGS1 ){
|
|||||||
Int arity = IntegerOfTerm(arg_arity);
|
Int arity = IntegerOfTerm(arg_arity);
|
||||||
|
|
||||||
MYDDAS_UTIL_PREDICATE predicate =
|
MYDDAS_UTIL_PREDICATE predicate =
|
||||||
myddas_util_search_predicate(name,arity,module);
|
myddas_util_search_predicate(name, arity, module);
|
||||||
if (predicate == NULL)
|
if (predicate == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -209,123 +194,110 @@ c_db_delete_predicate( USES_REGS1 ){
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Int c_db_multi_queries_number(USES_REGS1) {
|
||||||
static Int
|
|
||||||
c_db_multi_queries_number( USES_REGS1 ){
|
|
||||||
Term arg_conn = Deref(ARG1);
|
Term arg_conn = Deref(ARG1);
|
||||||
Term arg_number = Deref(ARG2);
|
Term arg_number = Deref(ARG2);
|
||||||
|
|
||||||
Int *conn = (Int *) IntegerOfTerm(arg_conn);
|
Int *conn = (Int *)IntegerOfTerm(arg_conn);
|
||||||
MYDDAS_UTIL_CONNECTION node =
|
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||||
myddas_util_search_connection(conn);
|
|
||||||
|
|
||||||
if (node == NULL)
|
if (node == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (IsVarTerm(arg_number)){
|
if (IsVarTerm(arg_number)) {
|
||||||
Yap_unify(arg_number,MkIntegerTerm(((Int)myddas_util_get_total_multi_queries_number(node))+1));
|
Yap_unify(arg_number,
|
||||||
}
|
MkIntegerTerm(
|
||||||
else {
|
((Int)myddas_util_get_total_multi_queries_number(node)) + 1));
|
||||||
|
} else {
|
||||||
Int number = IntegerOfTerm(arg_number);
|
Int number = IntegerOfTerm(arg_number);
|
||||||
number--;
|
number--;
|
||||||
myddas_util_set_total_multi_queries_number(node,number);
|
myddas_util_set_total_multi_queries_number(node, number);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int c_db_connection_start(USES_REGS1) {
|
||||||
c_db_connection_start( USES_REGS1 ){
|
|
||||||
|
|
||||||
MYDDAS_UTIL_CONNECTION node =
|
MYDDAS_UTIL_CONNECTION node =
|
||||||
Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_top_connections;
|
Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_top_connections;
|
||||||
|
|
||||||
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)node);
|
EXTRA_CBACK_ARG(1, 1) = (CELL)MkIntegerTerm((Int)node);
|
||||||
|
|
||||||
return (c_db_connection_continue( PASS_REGS1 ));
|
return (c_db_connection_continue(PASS_REGS1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int c_db_connection_continue(USES_REGS1) {
|
||||||
c_db_connection_continue( USES_REGS1 ){
|
|
||||||
Term arg_conn = Deref(ARG1);
|
Term arg_conn = Deref(ARG1);
|
||||||
|
|
||||||
MYDDAS_UTIL_CONNECTION node;
|
MYDDAS_UTIL_CONNECTION node;
|
||||||
node = (MYDDAS_UTIL_CONNECTION) IntegerOfTerm(EXTRA_CBACK_ARG(1,1));
|
node = (MYDDAS_UTIL_CONNECTION)IntegerOfTerm(EXTRA_CBACK_ARG(1, 1));
|
||||||
|
|
||||||
/* There is no connections */
|
/* There is no connections */
|
||||||
if (node == NULL)
|
if (node == NULL) {
|
||||||
{
|
cut_fail();
|
||||||
cut_fail();
|
return FALSE;
|
||||||
return FALSE;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Yap_unify(arg_conn, MkIntegerTerm((Int)(node->connection)));
|
Yap_unify(arg_conn, MkIntegerTerm((Int)(node->connection)));
|
||||||
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((Int)(node->next));
|
EXTRA_CBACK_ARG(1, 1) = (CELL)MkIntegerTerm((Int)(node->next));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
|
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
|
||||||
static Int
|
static Int c_db_preds_conn_start(USES_REGS1) {
|
||||||
c_db_preds_conn_start ( USES_REGS1 ){
|
|
||||||
Term arg_conn = Deref(ARG1);
|
Term arg_conn = Deref(ARG1);
|
||||||
|
|
||||||
Int *conn = (Int *) IntegerOfTerm(arg_conn);
|
Int *conn = (Int *)IntegerOfTerm(arg_conn);
|
||||||
MYDDAS_UTIL_CONNECTION node =
|
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||||
myddas_util_search_connection(conn);
|
|
||||||
|
|
||||||
/* Caso a ligacao já tenha sido apagada*/
|
/* Caso a ligacao já tenha sido apagada*/
|
||||||
if (node == NULL)
|
if (node == NULL) {
|
||||||
{
|
cut_fail();
|
||||||
cut_fail();
|
return FALSE;
|
||||||
return FALSE;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void *pointer = myddas_util_get_list_pred(node);
|
void *pointer = myddas_util_get_list_pred(node);
|
||||||
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)pointer);
|
EXTRA_CBACK_ARG(4, 1) = (CELL)MkIntegerTerm((Int)pointer);
|
||||||
|
|
||||||
return (c_db_preds_conn_continue( PASS_REGS1 ));
|
return (c_db_preds_conn_continue(PASS_REGS1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/
|
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/
|
||||||
static Int
|
static Int c_db_preds_conn_continue(USES_REGS1) {
|
||||||
c_db_preds_conn_continue ( USES_REGS1 ){
|
|
||||||
Term module = Deref(ARG2);
|
Term module = Deref(ARG2);
|
||||||
Term name = Deref(ARG3);
|
Term name = Deref(ARG3);
|
||||||
Term arity = Deref(ARG4);
|
Term arity = Deref(ARG4);
|
||||||
|
|
||||||
void *pointer;
|
void *pointer;
|
||||||
pointer = (void *) IntegerOfTerm(EXTRA_CBACK_ARG(4,1));
|
pointer = (void *)IntegerOfTerm(EXTRA_CBACK_ARG(4, 1));
|
||||||
|
|
||||||
if (pointer != NULL)
|
if (pointer != NULL) {
|
||||||
{
|
EXTRA_CBACK_ARG(4, 1) =
|
||||||
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((Int)myddas_util_get_pred_next(pointer));
|
(CELL)MkIntegerTerm((Int)myddas_util_get_pred_next(pointer));
|
||||||
|
|
||||||
if (!Yap_unify(module, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_module(pointer))))){
|
if (!Yap_unify(module, MkAtomTerm(Yap_LookupAtom(
|
||||||
return FALSE;
|
myddas_util_get_pred_module(pointer))))) {
|
||||||
}
|
|
||||||
if (!Yap_unify(name,MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_name(pointer))))){
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (!Yap_unify(arity, MkIntegerTerm((Int)myddas_util_get_pred_arity(pointer)))){
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cut_fail();
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
if (!Yap_unify(name, MkAtomTerm(Yap_LookupAtom(
|
||||||
|
myddas_util_get_pred_name(pointer))))) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!Yap_unify(arity,
|
||||||
|
MkIntegerTerm((Int)myddas_util_get_pred_arity(pointer)))) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
} else {
|
||||||
|
cut_fail();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static Int
|
static Int c_db_check(USES_REGS1) {
|
||||||
c_db_check( USES_REGS1 ){
|
|
||||||
check_int();
|
check_int();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -333,168 +305,166 @@ c_db_check( USES_REGS1 ){
|
|||||||
|
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
|
|
||||||
static Int
|
static Int c_db_stats_walltime(USES_REGS1) {
|
||||||
c_db_stats_walltime( USES_REGS1 ){
|
|
||||||
Term arg_time = Deref(ARG1);
|
Term arg_time = Deref(ARG1);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (IsVarTerm(arg_time)){
|
if (IsVarTerm(arg_time)) {
|
||||||
#endif
|
#endif
|
||||||
Yap_unify(arg_time,MkIntegerTerm((Int)myddas_stats_walltime()));
|
Yap_unify(arg_time, MkIntegerTerm((Int)myddas_stats_walltime()));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
}
|
} else {
|
||||||
else{
|
printf("ERROR: c_db_stats_walltime got a variable\n");
|
||||||
printf ("ERROR: c_db_stats_walltime got a variable\n");
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int c_db_stats_translate(USES_REGS1) {
|
||||||
c_db_stats_translate( USES_REGS1 ){
|
|
||||||
Term arg_start = Deref(ARG1);
|
Term arg_start = Deref(ARG1);
|
||||||
Term arg_end = Deref(ARG2);
|
Term arg_end = Deref(ARG2);
|
||||||
|
|
||||||
MYDDAS_STATS_TIME start;
|
MYDDAS_STATS_TIME start;
|
||||||
MYDDAS_STATS_TIME end;
|
MYDDAS_STATS_TIME end;
|
||||||
|
|
||||||
MYDDAS_STATS_TIME total_time,diff;
|
MYDDAS_STATS_TIME total_time, diff;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
//Both args must be instanciated
|
// Both args must be instanciated
|
||||||
if (IsNonVarTerm(arg_start) && IsNonVarTerm(arg_end)){
|
if (IsNonVarTerm(arg_start) && IsNonVarTerm(arg_end)) {
|
||||||
#endif
|
#endif
|
||||||
start = (MYDDAS_STATS_TIME) IntegerOfTerm(arg_start);
|
start = (MYDDAS_STATS_TIME)IntegerOfTerm(arg_start);
|
||||||
end = (MYDDAS_STATS_TIME) IntegerOfTerm(arg_end);
|
end = (MYDDAS_STATS_TIME)IntegerOfTerm(arg_end);
|
||||||
|
|
||||||
MYDDAS_STATS_GET_TRANSLATE(total_time);
|
MYDDAS_STATS_GET_TRANSLATE(total_time);
|
||||||
|
|
||||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff, time_copy);
|
||||||
myddas_stats_subtract_time(diff,end,start);
|
myddas_stats_subtract_time(diff, end, start);
|
||||||
|
|
||||||
diff = myddas_stats_time_copy_to_final(diff);
|
diff = myddas_stats_time_copy_to_final(diff);
|
||||||
myddas_stats_add_time(total_time,diff,total_time);
|
myddas_stats_add_time(total_time, diff, total_time);
|
||||||
MyddasULInt count;
|
MyddasULInt count;
|
||||||
MYDDAS_STATS_GET_TRANSLATE_COUNT(count);
|
MYDDAS_STATS_GET_TRANSLATE_COUNT(count);
|
||||||
MYDDAS_STATS_SET_TRANSLATE_COUNT(++count);
|
MYDDAS_STATS_SET_TRANSLATE_COUNT(++count);
|
||||||
|
|
||||||
MYDDAS_FREE(diff,struct myddas_stats_time_struct);
|
MYDDAS_FREE(diff, struct myddas_stats_time_struct);
|
||||||
MYDDAS_FREE(start, struct myddas_stats_time_struct);
|
MYDDAS_FREE(start, struct myddas_stats_time_struct);
|
||||||
MYDDAS_FREE(end, struct myddas_stats_time_struct);
|
MYDDAS_FREE(end, struct myddas_stats_time_struct);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
}
|
} else {
|
||||||
else{
|
printf("ERROR: c_db_stats_translate got a variable\n");
|
||||||
printf ("ERROR: c_db_stats_translate got a variable\n");
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int
|
static Int c_db_stats_time(USES_REGS1) {
|
||||||
c_db_stats_time( USES_REGS1 ){
|
|
||||||
Term arg_reference = Deref(ARG1);
|
Term arg_reference = Deref(ARG1);
|
||||||
Term arg_time = Deref(ARG2);
|
Term arg_time = Deref(ARG2);
|
||||||
|
|
||||||
Term final_term;
|
Term final_term;
|
||||||
|
|
||||||
MYDDAS_STATS_STRUCT struc = (MYDDAS_STATS_STRUCT)IntegerOfTerm(arg_reference);
|
MYDDAS_STATS_STRUCT struc = (MYDDAS_STATS_STRUCT)IntegerOfTerm(arg_reference);
|
||||||
Functor functor_count = Yap_MkFunctor(Yap_LookupAtom("count"),1);
|
Functor functor_count = Yap_MkFunctor(Yap_LookupAtom("count"), 1);
|
||||||
Term count_number[1];
|
Term count_number[1];
|
||||||
Functor unit;
|
Functor unit;
|
||||||
Term number[1];
|
Term number[1];
|
||||||
|
|
||||||
switch(struc->type){
|
switch (struc->type) {
|
||||||
|
|
||||||
case integer:
|
case integer: {
|
||||||
{
|
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_integer"), 2);
|
||||||
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_integer"),2);
|
Term integer_number[1];
|
||||||
Term integer_number[1];
|
MyddasULInt integer;
|
||||||
MyddasULInt integer;
|
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("number"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("number"), 1);
|
||||||
integer = struc->u.integer.integer;
|
integer = struc->u.integer.integer;
|
||||||
number[0] = MkIntegerTerm(integer);
|
number[0] = MkIntegerTerm(integer);
|
||||||
integer_number[0] = Yap_MkApplTerm(unit,1,number);;
|
integer_number[0] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
count_number[0] = MkIntegerTerm(struc->count);
|
count_number[0] = MkIntegerTerm(struc->count);
|
||||||
integer_number[1] = Yap_MkApplTerm(functor_count,1,count_number);
|
integer_number[1] = Yap_MkApplTerm(functor_count, 1, count_number);
|
||||||
final_term = Yap_MkApplTerm(functor,2,integer_number);
|
final_term = Yap_MkApplTerm(functor, 2, integer_number);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case time_str:
|
case time_str: {
|
||||||
{
|
MYDDAS_STATS_TIME time = struc->u.time_str.time_str;
|
||||||
MYDDAS_STATS_TIME time = struc->u.time_str.time_str;
|
|
||||||
|
|
||||||
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_time"),6);
|
Functor functor = Yap_MkFunctor(Yap_LookupAtom("myddas_time"), 6);
|
||||||
Term time_numbers[6];
|
Term time_numbers[6];
|
||||||
MyddasUInt time_number;
|
MyddasUInt time_number;
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("hours"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("hours"), 1);
|
||||||
time_number = MYDDAS_STATS_TIME_HOURS(time);
|
time_number = MYDDAS_STATS_TIME_HOURS(time);
|
||||||
number[0] = MkIntegerTerm(time_number);
|
number[0] = MkIntegerTerm(time_number);
|
||||||
time_numbers[0] = Yap_MkApplTerm(unit,1,number);;
|
time_numbers[0] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("minutes"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("minutes"), 1);
|
||||||
time_number = MYDDAS_STATS_TIME_MINUTES(time);
|
time_number = MYDDAS_STATS_TIME_MINUTES(time);
|
||||||
number[0] = MkIntegerTerm(time_number);
|
number[0] = MkIntegerTerm(time_number);
|
||||||
time_numbers[1] = Yap_MkApplTerm(unit,1,number);;
|
time_numbers[1] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("seconds"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("seconds"), 1);
|
||||||
time_number = MYDDAS_STATS_TIME_SECONDS(time);
|
time_number = MYDDAS_STATS_TIME_SECONDS(time);
|
||||||
number[0] = MkIntegerTerm(time_number);
|
number[0] = MkIntegerTerm(time_number);
|
||||||
time_numbers[2] = Yap_MkApplTerm(unit,1,number);;
|
time_numbers[2] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("miliseconds"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("miliseconds"), 1);
|
||||||
time_number = MYDDAS_STATS_TIME_MILISECONDS(time);
|
time_number = MYDDAS_STATS_TIME_MILISECONDS(time);
|
||||||
number[0] = MkIntegerTerm(time_number);
|
number[0] = MkIntegerTerm(time_number);
|
||||||
time_numbers[3] = Yap_MkApplTerm(unit,1,number);;
|
time_numbers[3] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
unit = Yap_MkFunctor(Yap_LookupAtom("microseconds"),1);
|
unit = Yap_MkFunctor(Yap_LookupAtom("microseconds"), 1);
|
||||||
time_number = MYDDAS_STATS_TIME_MICROSECONDS(time);
|
time_number = MYDDAS_STATS_TIME_MICROSECONDS(time);
|
||||||
number[0] = MkIntegerTerm(time_number);
|
number[0] = MkIntegerTerm(time_number);
|
||||||
time_numbers[4] = Yap_MkApplTerm(unit,1,number);;
|
time_numbers[4] = Yap_MkApplTerm(unit, 1, number);
|
||||||
|
;
|
||||||
|
|
||||||
count_number[0] = MkIntegerTerm(struc->count);
|
count_number[0] = MkIntegerTerm(struc->count);
|
||||||
time_numbers[5] = Yap_MkApplTerm(functor_count,1,count_number);
|
time_numbers[5] = Yap_MkApplTerm(functor_count, 1, count_number);
|
||||||
final_term = Yap_MkApplTerm(functor,6,time_numbers);
|
final_term = Yap_MkApplTerm(functor, 6, time_numbers);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf ("ERROR: c_db_stats_time unknow option\n");
|
printf("ERROR: c_db_stats_time unknow option\n");
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Yap_unify(arg_time,final_term )){
|
if (!Yap_unify(arg_time, final_term)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Returns the stats of this module in a list
|
// Returns the stats of this module in a list
|
||||||
static Int
|
static Int c_db_stats(USES_REGS1) {
|
||||||
c_db_stats( USES_REGS1 ) {
|
|
||||||
Term arg_conn = Deref(ARG1);
|
Term arg_conn = Deref(ARG1);
|
||||||
Term arg_list = Deref(ARG2);
|
Term arg_list = Deref(ARG2);
|
||||||
|
|
||||||
MyddasPointer *conn = (MyddasPointer *) (IntegerOfTerm(arg_conn));
|
MyddasPointer *conn = (MyddasPointer *)(IntegerOfTerm(arg_conn));
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
if (get_myddas_top() == 0 ){ /* We want all the statistics */
|
if (get_myddas_top() == 0) { /* We want all the statistics */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
MYDDAS_STATS_STRUCT str;
|
MYDDAS_STATS_STRUCT str;
|
||||||
MYDDAS_UTIL_CONNECTION
|
MYDDAS_UTIL_CONNECTION
|
||||||
node = myddas_util_search_connection(conn);
|
node = myddas_util_search_connection(conn);
|
||||||
Term head, list;
|
Term head, list;
|
||||||
list = arg_list;
|
list = arg_list;
|
||||||
|
|
||||||
@ -502,18 +472,18 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
MYDDAS_STATS_TIME time = NULL;
|
MYDDAS_STATS_TIME time = NULL;
|
||||||
#endif
|
#endif
|
||||||
//[Index 1] -> Total Number of Rows by connection
|
//[Index 1] -> Total Number of Rows by connection
|
||||||
//Total number of Rows returned by the server
|
// Total number of Rows returned by the server
|
||||||
//WARNING: only works with store_result
|
// WARNING: only works with store_result
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
str = myddas_stats_get_stat(node->stats,5);
|
str = myddas_stats_get_stat(node->stats, 5);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MyddasUInt number = 0;
|
MyddasUInt number = 0;
|
||||||
|
|
||||||
MYDDAS_STATS_CON_GET_TOTAL_ROWS(node,number);
|
MYDDAS_STATS_CON_GET_TOTAL_ROWS(node, number);
|
||||||
printf ("Total Number of Rows returned from the Server\n");
|
printf("Total Number of Rows returned from the Server\n");
|
||||||
printf ("%lu\n\n",(unsigned long)number);
|
printf("%lu\n\n", (unsigned long)number);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 2] -> Total of Time Spent by the DB Server
|
//[Index 2] -> Total of Time Spent by the DB Server
|
||||||
@ -521,13 +491,13 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,1);
|
str = myddas_stats_get_stat(node->stats, 1);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(node,time);
|
MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(node, time);
|
||||||
printf ("Reference to time Spent by the Server, on all the SQL Querys\n");
|
printf("Reference to time Spent by the Server, on all the SQL Querys\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 3] -> Total of Time Spent by the DB Server
|
//[Index 3] -> Total of Time Spent by the DB Server
|
||||||
@ -535,13 +505,13 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,2);
|
str = myddas_stats_get_stat(node->stats, 2);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(node,time);
|
MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(node, time);
|
||||||
printf ("Reference to time Spent by the Server, on the last SQL Query\n");
|
printf("Reference to time Spent by the Server, on the last SQL Query\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 4] -> Total of Time Spent by the DB Server
|
//[Index 4] -> Total of Time Spent by the DB Server
|
||||||
@ -549,13 +519,14 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,3);
|
str = myddas_stats_get_stat(node->stats, 3);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(node,time);
|
MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(node, time);
|
||||||
printf ("Refence to time Spent by the Server, transfering all the results SQL Query\n");
|
printf("Refence to time Spent by the Server, transfering all the results SQL "
|
||||||
|
"Query\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 5] -> Total of Time Spent by the DB Server
|
//[Index 5] -> Total of Time Spent by the DB Server
|
||||||
@ -563,13 +534,14 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,4);
|
str = myddas_stats_get_stat(node->stats, 4);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(node,time);
|
MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(node, time);
|
||||||
printf ("Reference to time Spent by the Server, transfering the result of the last SQL Query\n");
|
printf("Reference to time Spent by the Server, transfering the result of the "
|
||||||
|
"last SQL Query\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 6] -> Total of Time Spent by the
|
//[Index 6] -> Total of Time Spent by the
|
||||||
@ -577,14 +549,15 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats,1);
|
str = myddas_stats_get_stat(
|
||||||
|
Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats, 1);
|
||||||
|
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
Yap_unify(head, MkIntegerTerm((MyddasInt)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_GET_DB_ROW_FUNCTION(time);
|
MYDDAS_STATS_GET_DB_ROW_FUNCTION(time);
|
||||||
printf ("Reference to time Spent by the db_row_function\n");
|
printf("Reference to time Spent by the db_row_function\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 7] -> Total of Bytes Transfered by the
|
//[Index 7] -> Total of Bytes Transfered by the
|
||||||
@ -592,12 +565,12 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,6);
|
str = myddas_stats_get_stat(node->stats, 6);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node, number);
|
||||||
printf ("Bytes Transfered by the DB Server from all querys\n");
|
printf("Bytes Transfered by the DB Server from all querys\n");
|
||||||
printf ("%llu\n\n",(MyddasULInt)number);
|
printf("%llu\n\n", (MyddasULInt)number);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 8] -> Total of Bytes Transfered by the
|
//[Index 8] -> Total of Bytes Transfered by the
|
||||||
@ -605,23 +578,23 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,7);
|
str = myddas_stats_get_stat(node->stats, 7);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node, number);
|
||||||
printf ("Bytes Transfered by the DB Server on the last query\n");
|
printf("Bytes Transfered by the DB Server on the last query\n");
|
||||||
printf ("%llu\n\n",(MyddasULInt)number);
|
printf("%llu\n\n", (MyddasULInt)number);
|
||||||
#endif
|
#endif
|
||||||
//[Index 9] -> Number of querys made to the DBserver
|
//[Index 9] -> Number of querys made to the DBserver
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(node->stats,8);
|
str = myddas_stats_get_stat(node->stats, 8);
|
||||||
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
Yap_unify(head, MkIntegerTerm((MyddasPointer)str));
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(node,number);
|
MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(node, number);
|
||||||
printf ("Number of Querys made to the server\n");
|
printf("Number of Querys made to the server\n");
|
||||||
printf ("%llu\n\n",(MyddasULInt)number);
|
printf("%llu\n\n", (MyddasULInt)number);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//[Index 10] -> Total of Time Spent by the
|
//[Index 10] -> Total of Time Spent by the
|
||||||
@ -629,28 +602,29 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
|
|
||||||
str = myddas_stats_get_stat(Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats,2);
|
str = myddas_stats_get_stat(
|
||||||
|
Yap_REGS.MYDDAS_GLOBAL_POINTER->myddas_statistics->stats, 2);
|
||||||
Yap_unify(head, MkIntegerTerm((Int)str));
|
Yap_unify(head, MkIntegerTerm((Int)str));
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MYDDAS_STATS_GET_TRANSLATE(time);
|
MYDDAS_STATS_GET_TRANSLATE(time);
|
||||||
printf ("Reference to time Spent by the translate predicate\n");
|
printf("Reference to time Spent by the translate predicate\n");
|
||||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||||
printf ("\n\n");
|
printf("\n\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MyddasULInt nr;
|
MyddasULInt nr;
|
||||||
MYDDAS_MEMORY_MALLOC_NR(nr);
|
MYDDAS_MEMORY_MALLOC_NR(nr);
|
||||||
printf ("Number of times malloc was called in MYDDAS: %lu \n",nr);
|
printf("Number of times malloc was called in MYDDAS: %lu \n", nr);
|
||||||
MYDDAS_MEMORY_FREE_NR(nr);
|
MYDDAS_MEMORY_FREE_NR(nr);
|
||||||
printf ("Number of times free was called in MYDDAS : %lu \n",nr);
|
printf("Number of times free was called in MYDDAS : %lu \n", nr);
|
||||||
|
|
||||||
MYDDAS_MEMORY_MALLOC_SIZE(nr);
|
MYDDAS_MEMORY_MALLOC_SIZE(nr);
|
||||||
printf ("Total memory allocated in MYDDAS: %lu \n",nr);
|
printf("Total memory allocated in MYDDAS: %lu \n", nr);
|
||||||
MYDDAS_MEMORY_FREE_SIZE(nr);
|
MYDDAS_MEMORY_FREE_SIZE(nr);
|
||||||
printf ("Total memory freed in MYDDAS : %lu \n",nr);
|
printf("Total memory freed in MYDDAS : %lu \n", nr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -658,53 +632,48 @@ c_db_stats( USES_REGS1 ) {
|
|||||||
|
|
||||||
#endif /* MYDDAS_STATS */
|
#endif /* MYDDAS_STATS */
|
||||||
|
|
||||||
|
|
||||||
/* Function to delete all the temporary tables */
|
/* Function to delete all the temporary tables */
|
||||||
/* from the mysql server */
|
/* from the mysql server */
|
||||||
void Yap_MYDDAS_delete_all_myddas_structs(void)
|
void Yap_MYDDAS_delete_all_myddas_structs(void) {
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
/* NAO ESQUECER DE FAZER ISTO TB PARA O DB_CLOSE*/
|
/* NAO ESQUECER DE FAZER ISTO TB PARA O DB_CLOSE*/
|
||||||
MYDDAS_GLOBAL global =
|
MYDDAS_GLOBAL global = Yap_REGS.MYDDAS_GLOBAL_POINTER;
|
||||||
Yap_REGS.MYDDAS_GLOBAL_POINTER;
|
|
||||||
|
|
||||||
/* In case that the MYDDAS module isn't loaded */
|
/* In case that the MYDDAS module isn't loaded */
|
||||||
if (global == NULL)
|
if (global == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
MYDDAS_UTIL_CONNECTION connections =
|
MYDDAS_UTIL_CONNECTION connections = global->myddas_top_connections;
|
||||||
global->myddas_top_connections;
|
|
||||||
|
|
||||||
/* Delete all connections */
|
/* Delete all connections */
|
||||||
for(;connections!=NULL;connections=connections->next)
|
for (; connections != NULL; connections = connections->next)
|
||||||
myddas_util_delete_connection(connections->connection);
|
myddas_util_delete_connection(connections->connection);
|
||||||
|
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
myddas_stats_delete_stats_list(global->myddas_statistics->stats);
|
myddas_stats_delete_stats_list(global->myddas_statistics->stats);
|
||||||
MYDDAS_FREE(global->myddas_statistics,struct myddas_global_stats);
|
MYDDAS_FREE(global->myddas_statistics, struct myddas_global_stats);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MYDDAS_FREE(global,struct myddas_global);
|
MYDDAS_FREE(global, struct myddas_global);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
MyddasULInt nr;
|
MyddasULInt nr;
|
||||||
MYDDAS_MEMORY_MALLOC_NR(nr);
|
MYDDAS_MEMORY_MALLOC_NR(nr);
|
||||||
printf ("Number of times malloc was called in MYDDAS: " UInt_FORMAT " \n",(UInt)nr);
|
printf("Number of times malloc was called in MYDDAS: " UInt_FORMAT " \n",
|
||||||
|
(UInt)nr);
|
||||||
MYDDAS_MEMORY_FREE_NR(nr);
|
MYDDAS_MEMORY_FREE_NR(nr);
|
||||||
printf ("Number of times free was called in MYDDAS : " UInt_FORMAT " \n",(UInt)nr);
|
printf("Number of times free was called in MYDDAS : " UInt_FORMAT " \n",
|
||||||
|
(UInt)nr);
|
||||||
|
|
||||||
MYDDAS_MEMORY_MALLOC_SIZE(nr);
|
MYDDAS_MEMORY_MALLOC_SIZE(nr);
|
||||||
printf ("Total memory allocated in MYDDAS: " UInt_FORMAT " \n",(UInt)nr);
|
printf("Total memory allocated in MYDDAS: " UInt_FORMAT " \n", (UInt)nr);
|
||||||
MYDDAS_MEMORY_FREE_SIZE(nr);
|
MYDDAS_MEMORY_FREE_SIZE(nr);
|
||||||
printf ("Total memory freed in MYDDAS : " UInt_FORMAT " \n",(UInt)nr);
|
printf("Total memory freed in MYDDAS : " UInt_FORMAT " \n", (UInt)nr);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void init_myddas(void) {
|
||||||
void
|
|
||||||
init_myddas(void)
|
|
||||||
{
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
#if defined MYDDAS_ODBC
|
#if defined MYDDAS_ODBC
|
||||||
Yap_InitBackMYDDAS_ODBCPreds();
|
Yap_InitBackMYDDAS_ODBCPreds();
|
||||||
@ -727,7 +696,8 @@ init_myddas(void)
|
|||||||
#if defined USE_MYDDAS
|
#if defined USE_MYDDAS
|
||||||
Yap_InitMYDDAS_SharedPreds();
|
Yap_InitMYDDAS_SharedPreds();
|
||||||
#endif
|
#endif
|
||||||
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE
|
#if defined MYDDAS_TOP_LEVEL && \
|
||||||
|
defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE
|
||||||
Yap_InitMYDDAS_TopLevelPreds();
|
Yap_InitMYDDAS_TopLevelPreds();
|
||||||
#endif
|
#endif
|
||||||
#if USE_MYDDAS
|
#if USE_MYDDAS
|
||||||
@ -735,13 +705,14 @@ init_myddas(void)
|
|||||||
#define _stringify(X) #X
|
#define _stringify(X) #X
|
||||||
Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL;
|
Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL;
|
||||||
Yap_PutValue(AtomMyddasVersionName,
|
Yap_PutValue(AtomMyddasVersionName,
|
||||||
MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION))));
|
MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION))));
|
||||||
Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs,NULL);
|
Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs,
|
||||||
|
NULL);
|
||||||
#undef stringify
|
#undef stringify
|
||||||
#undef _stringify
|
#undef _stringify
|
||||||
Yap_MYDDAS_delete_all_myddas_structs();
|
Yap_MYDDAS_delete_all_myddas_structs();
|
||||||
#endif
|
#endif
|
||||||
c_db_initialize_myddas( PASS_REGS1 );
|
c_db_initialize_myddas(PASS_REGS1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -750,23 +721,19 @@ c_db_initialize_myddas( PASS_REGS1 );
|
|||||||
|
|
||||||
int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved);
|
int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved);
|
||||||
|
|
||||||
int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved)
|
int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||||
{
|
switch (reason) {
|
||||||
switch (reason)
|
case DLL_PROCESS_ATTACH:
|
||||||
{
|
break;
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_DETACH:
|
||||||
break;
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_THREAD_ATTACH:
|
||||||
break;
|
break;
|
||||||
case DLL_THREAD_ATTACH:
|
case DLL_THREAD_DETACH:
|
||||||
break;
|
break;
|
||||||
case DLL_THREAD_DETACH:
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* USE_MYDDAS*/
|
#endif /* USE_MYDDAS*/
|
||||||
|
Reference in New Issue
Block a user