MyDDAS: Changed MyDDAS internal structure

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1521 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-01-17 22:54:02 +00:00
parent ac5ba3fa10
commit 54595ec094
16 changed files with 691 additions and 656 deletions

View File

@ -23,6 +23,9 @@ static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98";
#ifdef CUT_C
#include "cut_c.h"
#endif
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
#include "myddas_util.h"
#endif
STATIC_PROTO(Int CallPredicate, (PredEntry *, choiceptr, yamop *));
STATIC_PROTO(Int EnterCreepMode, (Term, Term));
@ -1801,6 +1804,12 @@ Yap_InitYaamRegs(void)
WPP = NULL;
PREG_ADDR = NULL;
#endif
#ifdef CUT_C
cut_c_initialize();
#endif
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
Yap_regp->MYDDAS_GLOBAL_POINTER = myddas_util_initialize_myddas();
#endif
}
static Int

View File

@ -10,7 +10,7 @@
* File: Regs.h *
* mods: *
* comments: YAP abstract machine registers *
* version: $Id: Regs.h,v 1.33 2006-01-17 14:10:40 vsc Exp $ *
* version: $Id: Regs.h,v 1.34 2006-01-17 22:50:10 tiagosoares Exp $ *
*************************************************************************/
@ -19,6 +19,9 @@
#include "cut_c.h"
#endif
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
#include "myddas_util.h"
#endif
#define MaxTemps 512
@ -83,6 +86,9 @@ typedef struct
#ifdef CUT_C
cut_c_str_ptr CUT_C_TOP;
#endif
#if defined CUT_C && (defined MYDDAS_ODBC || defined MYDDAS_MYSQL)
MYDDAS_GLOBAL MYDDAS_GLOBAL_POINTER;
#endif
#ifdef DEPTH_LIMIT
CELL DEPTH_; /* 27 */
#endif /* DEPTH_LIMIT */

View File

@ -0,0 +1,91 @@
//* Initializes a new connection node for the MYDDAS list*/
static MYDDAS_UTIL_CONNECTION
myddas_util_initialize_connection(void *,void *,
MYDDAS_UTIL_CONNECTION);
/* Initializes a new predicate node for the MYDDAS list */
static MYDDAS_UTIL_PREDICATE
myddas_util_initialize_predicate(char *, int,char *,
MYDDAS_UTIL_PREDICATE);
MYDDAS_GLOBAL
myddas_util_initialize_myddas(){
MYDDAS_GLOBAL global = NULL;
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
global->myddas_top_connections = NULL;
#ifdef MYDDAS_STATS
global->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_stats));
global->myddas_statistics->total_db_row = 0;
#endif
return global;
}
/* Inserts the new node on the front of the list */
static MYDDAS_UTIL_CONNECTION
myddas_util_initialize_connection(void *conn,void *enviromment,
MYDDAS_UTIL_CONNECTION next){
MYDDAS_UTIL_CONNECTION new = malloc (sizeof(struct myddas_list_connection));
if (new == NULL)
{
return NULL;
}
new->predicates=NULL;
new->connection=conn;
new->temporary_tables=NULL;
new->odbc_enviromment=enviromment;
/* It saves n queries, doing at once n+1 queries */
new->total_number_queries=0; //Default
new->actual_number_queries=0;
new->queries = NULL;
/* List integrity */
new->next=next;
new->previous=NULL;
/* If there's already at least one node
on the list */
if (next != NULL)
next->previous=new;
#ifdef MYDDAS_STATS
new->totalNumberOfRows=0;
new->totalTimeofDBServer=0;
new->lastTimeofDBServer=0;
new->totalFromDBServer=0;
new->lastFromDBServer=0;
new->total_db_row=0;
new->lastBytesTransfered=0;
new->totalBytesTransfered=0;
new->total_querys_made=0;
#endif
return new;
}
static MYDDAS_UTIL_PREDICATE
myddas_util_initialize_predicate(char *pred_name, int pred_arity,
char *pred_module, MYDDAS_UTIL_PREDICATE next){
MYDDAS_UTIL_PREDICATE new = malloc (sizeof(struct myddas_list_preds));
if (new == NULL)
{
return NULL;
}
new->pred_name=pred_name;
new->pred_arity=pred_arity;
new->pred_module=pred_module;
/* List integrity */
new->next=next;
new->previous=NULL;
/* If there's already at least one node
on the list */
if (next != NULL)
next->previous=new;
return new;
}

View File

@ -25,6 +25,9 @@
#include "Yatom.h"
#include "cut_c.h"
#include "myddas_util.h"
#ifdef MYDDAS_STATS
#include "myddas_statistics.h"
#endif
#define IS_SQL_INT(FIELD) FIELD == FIELD_TYPE_INT24 || \
FIELD == FIELD_TYPE_LONG || \

View File

@ -22,6 +22,9 @@
#include "cut_c.h"
#include "myddas_util.h"
#include <stdlib.h>
#ifdef MYDDAS_STATS
#include "myddas_statistics.h"
#endif
STATIC_PROTO(int c_db_get_new_table_name,(void));
STATIC_PROTO(int c_db_connection_type,(void));
@ -29,6 +32,8 @@ STATIC_PROTO(int c_db_add_preds,(void));
STATIC_PROTO(int c_db_preds_conn_start ,(void));
STATIC_PROTO(int c_db_preds_conn_continue ,(void));
STATIC_PROTO(int c_db_check_if_exists_pred,(void));
STATIC_PROTO(int c_db_delete_predicate,(void));
STATIC_PROTO(int c_db_multi_queries_number,(void));
#ifdef MYDDAS_STATS
STATIC_PROTO(int c_db_stats,(void));
#endif
@ -39,15 +44,15 @@ STATIC_PROTO(int c_db_check,(void));
/* c_db_get_new_table_name: -TableName */
static int
c_db_get_new_table_name (void){
Term arg_con = Deref(ARG1);
Term arg_name = Deref(ARG2);
/* Term arg_con = Deref(ARG1); */
/* Term arg_name = Deref(ARG2); */
int *con = (int *) IntegerOfTerm(arg_con);
char *tableName = myddas_util_get_table_name(con);
/* int *con = (int *) IntegerOfTerm(arg_con); */
/* char *tableName = myddas_util_get_table_name(con); */
Yap_unify(arg_name, MkAtomTerm(Yap_LookupAtom(tableName)));
/* Yap_unify(arg_name, MkAtomTerm(Yap_LookupAtom(tableName))); */
free(tableName);
/* free(tableName); */
return TRUE;
}
@ -101,7 +106,7 @@ c_db_add_preds (void){
return TRUE;
}
/* db_add_preds: PredName * Arity */
static int
c_db_check_if_exists_pred (void){
Term arg_nome = Deref(ARG1);
@ -119,6 +124,51 @@ c_db_check_if_exists_pred (void){
}
static int
c_db_delete_predicate(void){
Term arg_module = Deref(ARG1);
Term arg_name = Deref(ARG2);
Term arg_arity = Deref(ARG3);
char *module = AtomName(AtomOfTerm(arg_module));
char *name = AtomName(AtomOfTerm(arg_name));
int arity = IntegerOfTerm(arg_arity);
MYDDAS_UTIL_PREDICATE predicate =
myddas_util_search_predicate(name,arity,module);
if (predicate == NULL)
return FALSE;
myddas_util_delete_predicate(predicate);
return TRUE;
}
static int
c_db_multi_queries_number(void){
Term arg_conn = Deref(ARG1);
Term arg_number = Deref(ARG2);
int *conn = (int *) IntegerOfTerm(arg_conn);
MYDDAS_UTIL_CONNECTION node =
myddas_util_search_connection(conn);
if (node == NULL)
return FALSE;
if (IsVarTerm(arg_number)){
Yap_unify(arg_number,MkIntegerTerm(((int)myddas_util_get_total_multi_queries_number(node))+1));
}
else {
int number = IntegerOfTerm(arg_number);
number--;
myddas_util_set_total_multi_queries_number(node,number);
}
return TRUE;
}
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
static int
c_db_preds_conn_start (void){
@ -328,9 +378,15 @@ void Yap_InitMYDDAS_SharedPreds(void)
/* CORRECT THIS: db_add_preds : PredName * Arity * Connection */
Yap_InitCPred("c_db_add_preds",4,c_db_add_preds, 0);
/* 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);
/* c_db_delete_pred : Module * PredName * Arity */
Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0);
/* c_db_delete_pred : Module * PredName * Arity */
Yap_InitCPred("c_db_multi_queries_number",2,c_db_multi_queries_number, 0);
#ifdef MYDDAS_STATS
/* db_stats: Connection * Stats*/
Yap_InitCPred("c_db_stats",2, c_db_stats, 0);

128
MYDDAS/myddas_statistics.c Normal file
View File

@ -0,0 +1,128 @@
#ifdef CUT_C
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL
#include "myddas_structs.h"
#include "myddas_statistics.h"
#include "Yap.h"
#ifdef MYDDAS_STATS
int
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION node){
return node->totalNumberOfRows;
}
void
myddas_util_set_conn_total_rows(MYDDAS_UTIL_CONNECTION node ,
int totalRows){
node->totalNumberOfRows = totalRows;
}
unsigned long
myddas_util_get_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->totalTimeofDBServer;
}
void
myddas_util_set_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long totaltime){
node->totalTimeofDBServer = totaltime;
}
unsigned long
myddas_util_get_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->lastTimeofDBServer;
}
void
myddas_util_set_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long lasttime){
node->lastTimeofDBServer = lasttime;
}
unsigned long
myddas_util_get_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->lastFromDBServer;
}
void
myddas_util_set_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long lasttime){
node->lastFromDBServer = lasttime;
}
unsigned long
myddas_util_get_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->totalFromDBServer;
}
void
myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long totaltime){
node->totalFromDBServer = totaltime;
}
unsigned long
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
return node->lastBytesTransfered;
}
void
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
node->lastBytesTransfered = bytes;
}
unsigned long
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
return node->totalBytesTransfered;
}
void
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
node->totalBytesTransfered = bytes;
}
unsigned long
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node){
return node->total_querys_made;
}
void
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node, unsigned long number){
node->total_querys_made = number;
}
unsigned long
myddas_util_get_total_db_row_function(void){
return Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_statistics->total_db_row;
}
void
myddas_util_set_total_db_row_function(unsigned long time){
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_statistics->total_db_row = time;
}
unsigned long
myddas_current_time(void) {
/* to get time as Yap */
Int now, interval;
Yap_cputime_interval(&now, &interval);
//return ((realtime)now);
return (now);
/*Fine grained time
tv_usec -> microseconds [0-999999]
*/
/*Fine grained time
sec -> [0-999]
tv_usec -> microseconds [0-99999] -> last digit is negleted
-> max execution time: 16minutes
milliseconds -> s/1000
microseconds -> s/1000000
*/
/* struct timeval tempo; */
/* if (!gettimeofday(&tempo, NULL)) */
/* //returns time in microseconds */
/* return (tempo.tv_sec %1000)*1000000+tempo.tv_usec; */
/* //return (tempo.tv_sec %1000)*1000+tempo.tv_usec; */
return 0;
}
#endif /* MYDDAS_STATS */
#endif
#endif

View File

@ -0,0 +1,54 @@
#ifdef MYDDAS_STATS
int
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_rows(MYDDAS_UTIL_CONNECTION,int);
unsigned long
myddas_util_get_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_time_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_time_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION, unsigned long);
unsigned long
myddas_util_get_total_db_row_function(void);
void
myddas_util_set_total_db_row_function(unsigned long);
unsigned long
myddas_current_time(void);
#endif /* MYDDAS_STATS */

View File

@ -1,6 +1,8 @@
#ifndef __MYDDAS_STRUCTS_H__
#define __MYDDAS_STRUCTS_H__
#include "myddas_util.h"
struct myddas_global {
MYDDAS_UTIL_CONNECTION myddas_top_connections;
#ifdef MYDDAS_STATS
@ -26,14 +28,15 @@ struct myddas_global_stats {
};
#endif /* MYDDAS_STATS */
struct list_preds {
struct myddas_list_preds {
char *pred_module;
char *pred_name;
short pred_arity;
struct list_preds *next;
MYDDAS_UTIL_PREDICATE next;
MYDDAS_UTIL_PREDICATE previous;
};
struct list_connection {
struct myddas_list_connection {
void *connection;
MYDDAS_TEMP_TABLES temporary_tables;
@ -70,9 +73,19 @@ struct list_connection {
unsigned long total_querys_made;
#endif
MYDDAS_UTIL_PREDICATE predicates;
struct list_connection *next;
/*Multi Queries Section */
unsigned long total_number_queries;
unsigned long actual_number_queries;
MYDDAS_UTIL_QUERY *queries;
MYDDAS_UTIL_CONNECTION next;
MYDDAS_UTIL_CONNECTION previous;
};
struct myddas_util_query{
char *query;
MYDDAS_UTIL_QUERY next;
};
#endif

View File

@ -11,7 +11,9 @@
#include "Yatom.h"
#include "cut_c.h"
#include "myddas_util.h"
#ifdef MYDDAS_STATS
#include "myddas_statistics.h"
#endif
#define IS_SQL_INT(FIELD) FIELD == FIELD_TYPE_INT24 || \

View File

@ -6,192 +6,25 @@
#include "cut_c.h"
#include "myddas_util.h"
#include "myddas_structs.h"
#include "myddas_initialization.c"
#ifdef MYDDAS_ODBC
#include <sql.h>
#endif /*MYDDAS_ODBC*/
#include "Yap.h"
static MYDDAS_GLOBAL MYDDAS_GLOBAL_STRUCT = NULL;
/* Get's a new number for the temporary tables */
static
unsigned int myddas_util_get_table_number(MYDDAS_UTIL_CONNECTION);
/* Prints a error message */
static void
myddas_util_error_message(char *,int,char *);
/* Search for the connection node, before of the actual*/
static MYDDAS_UTIL_CONNECTION
myddas_util_search_previous_connection(void *);
/* Initializes a new connection node for the MYDDAS list*/
static MYDDAS_UTIL_CONNECTION
myddas_util_initialize_connection(void *,void *, MYDDAS_UTIL_CONNECTION);
/* Initializes a new predicate node for the MYDDAS list */
static MYDDAS_UTIL_PREDICATE
myddas_util_initialize_predicate(char *, int,char *);
/* Search for the predicate in the given predicate list*/
static MYDDAS_UTIL_PREDICATE
myddas_util_find_predicate(char *, int , char *, MYDDAS_UTIL_PREDICATE);
/* Add's a predicate node to the given predicate list*/
static void
myddas_util_add_predicate_node(MYDDAS_UTIL_PREDICATE, MYDDAS_UTIL_PREDICATE *);
/* Deletes a predicate list */
static void
myddas_util_delete_predicate_list(MYDDAS_UTIL_PREDICATE);
#ifdef DEBUG
void check_int(){
int i;
MYDDAS_UTIL_PREDICATE pred = NULL;
MYDDAS_UTIL_CONNECTION top = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
for (i=1 ; top!=NULL ; top=top->next)
{
printf ("***************\n");
printf ("===== top =====\n");
printf ("======= %p =====\n",top);
printf ("CONN: = %p =====\n",top->connection);
printf ("ENV : = %p =====\n",top->odbc_enviromment);
printf ("PRED: = %p =====\n",top->predicates);
printf ("======= %p =====\n",top->next);
if (top->predicates != NULL)
{
printf ("\t******\n");
printf ("\t===== PREDICADOS =====\n");
for (pred = top->predicates ; pred != NULL ; pred = pred->next)
{
printf ("\t--------------\n");
printf ("\t===== %p =====\n",pred);
printf ("\t===== %s =====\n",pred->pred_name);
printf ("\t===== %d =====\n",pred->pred_arity);
printf ("\t===== %s =====\n",pred->pred_module);
printf ("\t===== %p =====\n",pred->next);
}
}
}
return;
}
#endif
#ifdef MYDDAS_STATS
int
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION node){
return node->totalNumberOfRows;
}
void
myddas_util_set_conn_total_rows(MYDDAS_UTIL_CONNECTION node ,
int totalRows){
node->totalNumberOfRows = totalRows;
}
unsigned long
myddas_util_get_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->totalTimeofDBServer;
}
void
myddas_util_set_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long totaltime){
node->totalTimeofDBServer = totaltime;
}
unsigned long
myddas_util_get_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->lastTimeofDBServer;
}
void
myddas_util_set_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long lasttime){
node->lastTimeofDBServer = lasttime;
}
unsigned long
myddas_util_get_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->lastFromDBServer;
}
void
myddas_util_set_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long lasttime){
node->lastFromDBServer = lasttime;
}
unsigned long
myddas_util_get_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node){
return node->totalFromDBServer;
}
void
myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION node ,
unsigned long totaltime){
node->totalFromDBServer = totaltime;
}
unsigned long
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
return node->lastBytesTransfered;
}
void
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
node->lastBytesTransfered = bytes;
}
unsigned long
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node){
return node->totalBytesTransfered;
}
void
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION node, unsigned long bytes){
node->totalBytesTransfered = bytes;
}
unsigned long
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node){
return node->total_querys_made;
}
void
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION node, unsigned long number){
node->total_querys_made = number;
}
unsigned long
myddas_util_get_total_db_row_function(void){
return MYDDAS_GLOBAL_STRUCT->myddas_statistics->total_db_row;
}
void
myddas_util_set_total_db_row_function(unsigned long time){
MYDDAS_GLOBAL_STRUCT->myddas_statistics->total_db_row = time;
}
/* Prints a error message */
static void
myddas_util_error_message(char *,int,char *);
unsigned long
myddas_current_time(void) {
/* to get time as Yap */
Int now, interval;
Yap_cputime_interval(&now, &interval);
//return ((realtime)now);
return (now);
/*Fine grained time
tv_usec -> microseconds [0-999999]
*/
/*Fine grained time
sec -> [0-999]
tv_usec -> microseconds [0-99999] -> last digit is negleted
-> max execution time: 16minutes
milliseconds -> s/1000
microseconds -> s/1000000
*/
/* struct timeval tempo; */
/* if (!gettimeofday(&tempo, NULL)) */
/* //returns time in microseconds */
/* return (tempo.tv_sec %1000)*1000000+tempo.tv_usec; */
/* //return (tempo.tv_sec %1000)*1000+tempo.tv_usec; */
return 0;
}
#endif /* MYDDAS_STATS */
/* Type: MYSQL->1 ODBC->2*/
short int
@ -209,6 +42,202 @@ myddas_util_connection_type(void *con){
return 1;
}
MYDDAS_UTIL_PREDICATE
myddas_util_search_predicate(char *pred_name, int pred_arity,
char *pred_module){
MYDDAS_UTIL_PREDICATE pred=NULL;
MYDDAS_UTIL_CONNECTION top = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
for (;top!=NULL;top=top->next)
{
if ((pred=myddas_util_find_predicate(pred_name,pred_arity,pred_module,top->predicates)))
return pred;
}
return NULL;
}
/* When using this function, we must guarante that this predicate
it's unique */
MYDDAS_UTIL_CONNECTION
myddas_util_add_predicate(char *pred_name, int pred_arity,
char *pred_module, void *con){
MYDDAS_UTIL_CONNECTION node_con =
myddas_util_search_connection(con);
MYDDAS_UTIL_PREDICATE new =
myddas_util_initialize_predicate(pred_name,pred_arity,pred_module,node_con->predicates);
if (new == NULL)
{
myddas_util_error_message("Could not initialize predicate node",__LINE__,__FILE__);
return NULL;
}
node_con->predicates=new;
return node_con;
}
void
myddas_util_delete_predicate(MYDDAS_UTIL_PREDICATE to_delete){
if (to_delete->next != NULL)
to_delete->next->previous = to_delete->previous;
if (to_delete->previous != NULL)
to_delete->previous->next = to_delete->next;
else //First predicate of the predicate list
{
MYDDAS_UTIL_CONNECTION con_node = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
for(;con_node != NULL; con_node = con_node->next)
if (con_node->predicates == to_delete)
break;
con_node->predicates = to_delete->next;
}
free(to_delete);
}
void
myddas_util_delete_connection(void *conn){
MYDDAS_UTIL_CONNECTION to_delete = myddas_util_search_connection(conn);
if (to_delete == NULL)
return;
else
{
/* Removes the predicates list */
myddas_util_delete_predicate_list(to_delete->predicates);
/* List Integrety */
/* Is the last element of the list */
if ((to_delete->next) != NULL)
to_delete->next->previous = to_delete->previous;
/* Is the first element of the list */
if (to_delete == (Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections))
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections = to_delete->next;
else
to_delete->previous->next=to_delete->next;
free(to_delete);
return;
}
}
MYDDAS_UTIL_CONNECTION
myddas_util_search_connection(void *conn){
MYDDAS_UTIL_CONNECTION list = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
#ifdef MYDDAS_STATS
if (conn == 0) { /* We want all the statistics */
return list;
}
#endif
for (;list!=NULL;list=list->next)
if (list->connection == conn)
return list;
return NULL;
}
MYDDAS_UTIL_CONNECTION
myddas_util_add_connection(void *conn, void *enviromment){
MYDDAS_UTIL_CONNECTION node=NULL;
MYDDAS_UTIL_CONNECTION temp=NULL;
if ((node = myddas_util_search_connection(conn)) != NULL)
{
return node;
}
//put the new connection node on the top of the list
temp = myddas_util_initialize_connection(conn,enviromment,Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections);
if (temp == NULL)
{
#ifdef DEBUG
myddas_util_error_message("Could not initialize connection node",__LINE__,__FILE__);
#endif
return NULL;
}
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections = temp;
return Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
}
#ifdef MYDDAS_ODBC
/* This function searches the MYDDAS list for odbc connections
If there isn't any, it returns NULL. This is a nice way to know
if there is any odbc connections left on the list*/
SQLHENV
myddas_util_get_odbc_enviromment(SQLHDBC connection){
MYDDAS_UTIL_CONNECTION top = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
for (;top != NULL;top=top->next)
if (top->connection == ((void *)connection))
return top->odbc_enviromment;
return NULL;
}
#endif
unsigned long
myddas_util_get_total_multi_queries_number(MYDDAS_UTIL_CONNECTION con){
return con->total_number_queries;
}
void
myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION con,
unsigned long number){
con->total_number_queries = number;
}
static
void myddas_util_error_message(char *message,int line,char *file){
#ifdef DEBUG
printf ("ERROR: %s at line %d in file %s\n",message,line,file);
#else
printf ("ERROR: %s\n",message);
#endif
}
static MYDDAS_UTIL_PREDICATE
myddas_util_find_predicate(char *pred_name, int pred_arity,
char *pred_module, MYDDAS_UTIL_PREDICATE list){
for(;list != NULL ; list = list->next)
if (pred_arity == list->pred_arity &&
!strcmp(pred_name,list->pred_name) &&
!strcmp(pred_module,list->pred_module))
return list;
return NULL;
}
static void
myddas_util_delete_predicate_list(MYDDAS_UTIL_PREDICATE preds_list){
MYDDAS_UTIL_PREDICATE to_delete = NULL;
for (;preds_list != NULL;)
{
to_delete = preds_list;
preds_list = preds_list->next;
free(to_delete);
}
return;
}
//DELETE THIS WHEN DB_STATS IS COMPLETED
int
get_myddas_top(){
if (Yap_regp->MYDDAS_GLOBAL_POINTER == NULL)
return 0;
return (int)Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
}
void *
myddas_util_get_pred_next(void *pointer){
MYDDAS_UTIL_PREDICATE temp = (MYDDAS_UTIL_PREDICATE) pointer;
@ -238,374 +267,43 @@ myddas_util_get_list_pred(MYDDAS_UTIL_CONNECTION node){
return (void *)(node->predicates);
}
MYDDAS_UTIL_PREDICATE
myddas_util_search_predicate(char *pred_name, int pred_arity,
char *pred_module){
#ifdef DEBUG
void check_int(){
int i;
MYDDAS_UTIL_PREDICATE pred = NULL;
MYDDAS_UTIL_CONNECTION top = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
for (;top!=NULL;top=top->next)
MYDDAS_UTIL_CONNECTION top = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
for (i=1 ; top!=NULL ; top=top->next)
{
if ((pred=myddas_util_find_predicate(pred_name,pred_arity,pred_module,top->predicates)))
return pred;
printf ("***************\n");
printf ("===== top =====\n");
printf ("======= %p =====\n",top);
printf ("CONN: = %p =====\n",top->connection);
printf ("ENV : = %p =====\n",top->odbc_enviromment);
printf ("PRED: = %p =====\n",top->predicates);
printf ("======= %p =====\n",top->previous);
printf ("======= %p =====\n",top->next);
if (top->predicates != NULL)
{
printf ("\t******\n");
printf ("\t===== PREDICADOS =====\n");
for (pred = top->predicates ; pred != NULL ; pred = pred->next)
{
printf ("\t--------------\n");
printf ("\t===== %p =====\n",pred);
printf ("\t===== %s =====\n",pred->pred_name);
printf ("\t===== %d =====\n",pred->pred_arity);
printf ("\t===== %s =====\n",pred->pred_module);
printf ("\t===== %p =====\n",pred->previous);
printf ("\t===== %p =====\n",pred->next);
}
return NULL;
}
/* When using this function, we must guarante that this predicate
it's unique */
MYDDAS_UTIL_CONNECTION
myddas_util_add_predicate(char *pred_name, int pred_arity,
char *pred_module, void *conn){
MYDDAS_UTIL_CONNECTION node_conn =
myddas_util_search_connection(conn);
MYDDAS_UTIL_PREDICATE new =
myddas_util_initialize_predicate(pred_name,pred_arity,pred_module);
if (new == NULL)
{
myddas_util_error_message("Could not initialize predicate node",__LINE__,__FILE__);
return NULL;
}
myddas_util_add_predicate_node(new,&(node_conn->predicates));
return node_conn;
}
void
myddas_util_delete_connection(void *conn){
MYDDAS_UTIL_CONNECTION before_to_delete = NULL;
MYDDAS_UTIL_CONNECTION to_delete =
myddas_util_search_connection(conn);
if (to_delete == NULL)
return;
else
{
/*Removes the predicates list*/
myddas_util_delete_predicate_list(to_delete->predicates);
if (to_delete == MYDDAS_GLOBAL_STRUCT->myddas_top_connections)
{
MYDDAS_GLOBAL_STRUCT->myddas_top_connections= to_delete->next;
free(to_delete);
return;
}
else
{
before_to_delete =
myddas_util_search_previous_connection(conn);
before_to_delete->next=to_delete->next;
free(to_delete);
return;
}
}
}
MYDDAS_UTIL_CONNECTION
myddas_util_search_connection(void *conn){
MYDDAS_UTIL_CONNECTION list = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
if (conn == 0) { /* We want all the statistics */
return list;
}
for (;list!=NULL;list=list->next)
if (list->connection == conn)
return list;
return NULL;
}
MYDDAS_UTIL_CONNECTION
myddas_util_add_connection(void *conn, void *enviromment){
MYDDAS_UTIL_CONNECTION node=NULL;
MYDDAS_UTIL_CONNECTION temp=NULL;
if (MYDDAS_GLOBAL_STRUCT == NULL)
{
MYDDAS_GLOBAL_STRUCT = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
MYDDAS_GLOBAL_STRUCT->myddas_top_connections = NULL;
#ifdef MYDDAS_STATS
MYDDAS_GLOBAL_STRUCT->myddas_statistics = NULL;
#endif
}
if ((node = myddas_util_search_connection(conn)) != NULL)
{
return node;
}
if (MYDDAS_GLOBAL_STRUCT->myddas_top_connections!=NULL)
{
//put the new connection node on the top of the list
temp = myddas_util_initialize_connection(conn,enviromment,MYDDAS_GLOBAL_STRUCT->myddas_top_connections);
if (temp == NULL)
{
#ifdef DEBUG
myddas_util_error_message("Could not initialize connection node",__LINE__,__FILE__);
#endif
return NULL;
}
MYDDAS_GLOBAL_STRUCT->myddas_top_connections = temp;
return MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
}
else //The MYDDAS list is empty
{
#ifdef MYDDAS_STATS
/* Allocates the MYDDAS stats
global structure */
MYDDAS_GLOBAL_STRUCT->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_stats));
MYDDAS_GLOBAL_STRUCT->myddas_statistics->total_db_row = 0;
#endif /* MYDDAS_STATS */
temp = myddas_util_initialize_connection(conn,enviromment,NULL);
if (temp == NULL)
{
myddas_util_error_message("Could not initialize connection node",__LINE__,__FILE__);
return NULL;
}
MYDDAS_GLOBAL_STRUCT->myddas_top_connections = temp;
return MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
}
}
#ifdef MYDDAS_ODBC
/* This function searches the MYDDAS list for odbc connections
If there isn't any, it returns NULL. This is a nice way to know
if there is any odbc connections left on the list*/
SQLHENV
myddas_util_get_odbc_enviromment(SQLHDBC connection){
MYDDAS_UTIL_CONNECTION top = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
for (;top != NULL;top=top->next)
if (top->connection == ((void *)connection))
return top->odbc_enviromment;
return NULL;
}
#endif
/* Dont forget to free the memory on the other side*/
char *
myddas_util_delete_all_temp_table(){
if (MYDDAS_GLOBAL_STRUCT == NULL)
return NULL;
MYDDAS_UTIL_CONNECTION node = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
if (node->temporary_tables == NULL){
return NULL;
}
MYDDAS_TEMP_TABLES tables = node->temporary_tables;
if (tables->table_numbers == NULL){
free(tables->default_table_name);
free(tables);
return NULL; /* No more tables*/
}
else {
int table_number = tables->table_numbers->number;
struct myddas_table_integers *temporary = tables->table_numbers;
tables->table_numbers = tables->table_numbers->next;
if (tables->table_numbers == NULL)
tables->last_number = NULL;
free(temporary);
int i=0;
/* Number of Digits of table_number */
for (i=1;;i++)
if ((table_number / (10*i)) < 10)
break;
int size = strlen(node->temporary_tables->default_table_name);
char *table_name = (char *) malloc (sizeof(char) * (i + size + 1));
sprintf(table_name,"%s%d",
node->temporary_tables->default_table_name,table_number);
return table_name;
}
}
/* Dont forget to free the memory on the other side*/
char *
myddas_util_get_table_name(void *con){
int table_number;
int i=0;
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(con);
if (node->temporary_tables == NULL) {
node->temporary_tables =
(MYDDAS_TEMP_TABLES) malloc (sizeof(struct myddas_temp_tables));
node->temporary_tables->last_number = NULL;
node->temporary_tables->table_numbers = NULL;
/* Number of Digits of the connnection pointer */
for (i=1;;i++)
if ((((int)con) / (10*i)) < 10)
break;
node->temporary_tables->default_table_name =
(char *) malloc (sizeof(char *) + i + 1 + 23);
sprintf (node->temporary_tables->default_table_name,"$myddas_temporary_table%d",(int)con);
}
table_number = myddas_util_get_table_number(node);
/* Number of Digits of table_number */
for (i=1;;i++)
if ((table_number / (10*i)) < 10)
break;
int size = strlen(node->temporary_tables->default_table_name);
char *table_name = (char *) malloc (sizeof(char) * (i + size + 1));
sprintf(table_name,"%s%d",
node->temporary_tables->default_table_name,table_number);
return table_name;
}
static
unsigned int myddas_util_get_table_number(MYDDAS_UTIL_CONNECTION node){
MYDDAS_TEMP_TABLES table = node->temporary_tables;
if (table->table_numbers == NULL) {
table->last_number = (struct myddas_table_integers *) malloc (sizeof(struct myddas_table_integers));
table->table_numbers = table->last_number;
table->last_number->number = 0;
table->last_number->next=NULL;
}
else {
unsigned int last_number = table->last_number->number;
table->last_number->next = (struct myddas_table_integers *) malloc (sizeof(struct myddas_table_integers));
table->last_number = table->last_number->next;
table->last_number->number = ++last_number;
table->last_number->next=NULL;
}
return table->last_number->number;
}
static
void myddas_util_error_message(char *message,int line,char *file){
#ifdef DEBUG
printf ("ERROR: %s at line %d in file %s\n",message,line,file);
#else
printf ("ERROR: %s\n",message);
#endif
}
static MYDDAS_UTIL_CONNECTION
myddas_util_search_previous_connection(void *conn){
MYDDAS_UTIL_CONNECTION top = MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
for(;top->next!=NULL;top=top->next)
if (top->next->connection == conn)
return top;
return NULL;
}
static MYDDAS_UTIL_CONNECTION
myddas_util_initialize_connection(void *conn,void *enviromment,
MYDDAS_UTIL_CONNECTION next){
MYDDAS_UTIL_CONNECTION new = malloc (sizeof(struct list_connection));
if (new == NULL)
{
return NULL;
}
new->predicates=NULL;
new->connection=conn;
new->temporary_tables=NULL;
new->odbc_enviromment=enviromment;
new->next=next;
#ifdef MYDDAS_STATS
new->totalNumberOfRows=0;
new->totalTimeofDBServer=0;
new->lastTimeofDBServer=0;
new->totalFromDBServer=0;
new->lastFromDBServer=0;
new->total_db_row=0;
new->lastBytesTransfered=0;
new->totalBytesTransfered=0;
new->total_querys_made=0;
#endif
return new;
}
static MYDDAS_UTIL_PREDICATE
myddas_util_initialize_predicate(char *pred_name, int pred_arity,
char *pred_module){
MYDDAS_UTIL_PREDICATE new = malloc (sizeof(struct list_preds));
if (new == NULL)
{
return NULL;
}
new->pred_name=pred_name;
new->pred_arity=pred_arity;
new->pred_module=pred_module;
new->next=NULL;
return new;
}
static MYDDAS_UTIL_PREDICATE
myddas_util_find_predicate(char *pred_name, int pred_arity,
char *pred_module, MYDDAS_UTIL_PREDICATE list){
for(;list != NULL ; list = list->next)
if (pred_arity == list->pred_arity &&
!strcmp(pred_name,list->pred_name) &&
!strcmp(pred_module,list->pred_module))
return list;
return NULL;
}
static void
myddas_util_add_predicate_node(MYDDAS_UTIL_PREDICATE new,
MYDDAS_UTIL_PREDICATE *list){
MYDDAS_UTIL_PREDICATE temp = *list;
*list = new;
new->next = temp;
}
static void
myddas_util_delete_predicate_list(MYDDAS_UTIL_PREDICATE preds_list){
MYDDAS_UTIL_PREDICATE to_delete = NULL;
for (;preds_list != NULL;)
{
to_delete = preds_list;
preds_list = preds_list->next;
free(to_delete);
}
return;
}
//DELETE THIS WHEN DB_STATS IS COMPLETED
int
get_myddas_top(){
if (MYDDAS_GLOBAL_STRUCT == NULL)
return 0;
return (int)MYDDAS_GLOBAL_STRUCT->myddas_top_connections;
}
#endif /*defined MYDDAS_ODBC || defined MYDDAS_MYSQL*/
#endif /*CUT_C*/

View File

@ -15,15 +15,14 @@ typedef struct myddas_global *MYDDAS_GLOBAL;
#ifdef MYDDAS_STATS
typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS;
#endif
typedef struct list_connection *MYDDAS_UTIL_CONNECTION;
typedef struct list_preds *MYDDAS_UTIL_PREDICATE;
typedef struct myddas_util_query *MYDDAS_UTIL_QUERY;
typedef struct myddas_list_connection *MYDDAS_UTIL_CONNECTION;
typedef struct myddas_list_preds *MYDDAS_UTIL_PREDICATE;
typedef struct myddas_temp_tables *MYDDAS_TEMP_TABLES;
MYDDAS_GLOBAL
myddas_util_initialize_myddas(void);
char *
myddas_util_delete_all_temp_table(void);
char *
myddas_util_get_table_name(void *);
/* Returns the connection type (mysql -> 1 or odbc -> 2) */
short int
myddas_util_connection_type(void *);
@ -41,9 +40,18 @@ myddas_util_delete_connection(void *);
/* Adds a new predicate to it's connection node list*/
MYDDAS_UTIL_CONNECTION
myddas_util_add_predicate(char *,int , char *,void *);
/* Search for a predicate node in it's connection list*/
/* Search for a predicate node*/
MYDDAS_UTIL_PREDICATE
myddas_util_search_predicate(char *,int , char *);
/* Deletes predicate from the prediate list */
void
myddas_util_delete_predicate(MYDDAS_UTIL_PREDICATE);
/* Get's the number of queries to save */
unsigned long
myddas_util_get_total_multi_queries_number(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION,unsigned long);
#ifdef MYDDAS_ODBC
/* Return enviromment identifier*/
@ -63,63 +71,6 @@ int
myddas_util_get_pred_arity(void *);
#ifdef MYDDAS_STATS
int
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_rows(MYDDAS_UTIL_CONNECTION,int);
unsigned long
myddas_util_get_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_time_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_time_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_total_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION,unsigned long);
unsigned long
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION);
void
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION, unsigned long);
unsigned long
myddas_util_get_total_db_row_function(void);
void
myddas_util_set_total_db_row_function(unsigned long);
unsigned long
myddas_current_time(void);
#endif /* MYDDAS_STATS */
#ifdef DEBUG
void check_int(void);
#endif

View File

@ -53,7 +53,7 @@ YAP_EXTRAS=@YAP_EXTRAS@
#
CC=@CC@
MPI_CC=@MPI_CC@
CPPFLAGS=@CPPFLAGS@ -I. -I$(srcdir)/H -I$(srcdir)/OPTYap -I$(srcdir)/BEAM
CPPFLAGS=@CPPFLAGS@ -I. -I$(srcdir)/H -I$(srcdir)/OPTYap -I$(srcdir)/BEAM -I$(srcdir)/MYDDAS
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) $(CPPFLAGS)
C_INTERF_FLAGS= @C_INTERF_FLAGS@ $(YAP_EXTRAS) $(DEFS) $(CPPFLAGS) -I$(srcdir)/include
C_PARSER_FLAGS= @C_PARSER_FLAGS@ $(YAP_EXTRAS) $(DEFS) $(CPPFLAGS)
@ -124,7 +124,8 @@ HEADERS = \
$(srcdir)/OPTYap/alpha_locks_funcs.h \
$(srcdir)/OPTYap/pthread_locks.h \
$(srcdir)/H/cut_c.h \
$(srcdir)/MYDDAS/myddas_util.h $(srcdir)/MYDDAS/myddas_structs.h
$(srcdir)/MYDDAS/myddas_util.h $(srcdir)/MYDDAS/myddas_structs.h \
$(srcdir)/MYDDAS/myddas_statistics.h
C_SOURCES= \
$(srcdir)/C/absmi.c $(srcdir)/C/adtdefs.c \
@ -170,7 +171,8 @@ C_SOURCES= \
$(srcdir)/MYDDAS/myddas_odbc.c \
$(srcdir)/MYDDAS/myddas_util.c \
$(srcdir)/MYDDAS/myddas_shared.c \
$(srcdir)/MYDDAS/myddas_test_predicates.c
$(srcdir)/MYDDAS/myddas_test_predicates.c \
$(srcdir)/MYDDAS/myddas_statistics.c
PL_SOURCES= \
$(srcdir)/pl/arith.yap $(srcdir)/pl/arrays.yap $(srcdir)/pl/boot.yap \
@ -206,7 +208,7 @@ ENGINE_OBJECTS = \
heapgc.o index.o init.o inlines.o \
iopreds.o depth_bound.o mavar.o \
myddas_mysql.o myddas_odbc.o myddas_shared.o myddas_test_predicates.o \
myddas_util.o modules.o other.o \
myddas_util.o myddas_statistics.o modules.o other.o \
parser.o save.o scanner.o sort.o stdpreds.o sysbits.o threads.o \
tracer.o \
unify.o userpreds.o utilpreds.o write.o ypsocks.o ypstdio.o @MPI_OBJS@
@ -433,6 +435,9 @@ myddas_test_predicates.o: $(srcdir)/MYDDAS/myddas_test_predicates.c
myddas_util.o: $(srcdir)/MYDDAS/myddas_util.c
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_util.c -o $@
myddas_statistics.o: $(srcdir)/MYDDAS/myddas_statistics.c
$(CC) -c $(CFLAGS) $(srcdir)/MYDDAS/myddas_statistics.c -o $@
opt.memory.o: $(srcdir)/OPTYap/opt.memory.c
$(CC) -c $(CFLAGS) $(srcdir)/OPTYap/opt.memory.c -o $@

View File

@ -664,11 +664,6 @@ main (int argc, char **argv)
BootMode = init_standard_system(argc, argv, &init_args);
#ifdef CUT_C
cut_c_initialize();
#endif
if (BootMode == YAP_BOOT_ERROR) {
fprintf(stderr,"[ FATAL ERROR: could not find saved state ]\n");
exit(1);

View File

@ -22,7 +22,6 @@
db_verbose/1,
db_module/1,
db_is_database_predicate/3,
db_abolish/2,
db_stats/2,
db_sql_select/3,
@ -36,10 +35,13 @@
db_get_attributes_types/3,
db_number_of_fields/3,
db_multi_queries_number/2,
% myddas_assert_predicates.yap
db_import/3,
db_view/3,
db_insert/3,
db_abolish/2,
% myddas_mysql.yap
db_my_open/5,
@ -56,13 +58,13 @@
db_my_sql_select/3,
db_my_number_of_fields/3,
db_my_get_attributes_types/3
]).
:- use_module(myddas_assert_predicates,[
db_import/3,
db_view/3,
db_insert/3
db_insert/3,
db_abolish/2
]).
:- use_module(myddas_mysql,[
@ -188,23 +190,6 @@ db_is_database_predicate(PredName,Arity,Module):-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_abolish(+,+)
%
%
db_abolish(Module:PredName,Arity):-!,
'$error_checks'(db_abolish(Module:PredName,Arity)),
%c_db_delete_predicate(
abolish(Module:PredName,Arity).
db_abolish(PredName,Arity):-
'$error_checks'(db_abolish(PredName,Arity)),
%c_db_delete_predicate(
abolish(PredName,Arity).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_stats(+,-)
%
@ -443,3 +428,16 @@ db_number_of_fields(Connection,RelationName,Arity) :-
c_db_odbc_number_of_fields(RelationName,Con,Arity)
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_multi_queries_number(+,+)
% TO
%
db_multi_queries_number(Connection,Number) :-
'$error_checks'(db_multi_queries_number(Connection,Number)),
get_value(Connection,Con),
c_db_multi_queries_number(Con,Number).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -18,7 +18,8 @@
:- module(myddas_assert_predicates,[
db_import/3,
db_view/3,
db_insert/3
db_insert/3,
db_abolish/2
]).
@ -152,7 +153,7 @@ db_view(Connection,PredName,DbGoal) :-
% get arity of projection term
functor(PredName,ViewName,Arity),
db_module(Module),
%not c_db_check_if_exists_pred(ViewName,Arity,Module),
not c_db_check_if_exists_pred(ViewName,Arity,Module),
% This copy_term is done to prevent the unification
% with top-level variables A='var('A')' error
@ -175,14 +176,14 @@ db_view(Connection,PredName,DbGoal) :-
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
','(!,M:c_db_my_row(ResultSet,Arity,LA)))))))))]
;
Assert =..[':-',NewName,
','(M:translate(CopyView,CopyGoal,Code),
','(M:queries_atom(Code,FinalSQL),
','(M:'$make_a_list'(Arity,BindList),
','(M:'$write_or_not'(FinalSQL),
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
','(!,M:c_db_odbc_row(ResultSet,BindList,LA)))))))]
% Assert =..[':-',NewName,
% ','(M:translate(CopyView,CopyGoal,Code),
% ','(M:queries_atom(Code,FinalSQL),
% ','(M:'$make_a_list'(Arity,BindList),
% ','(M:'$write_or_not'(FinalSQL),
% ','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
% ','(!,M:c_db_odbc_row(ResultSet,BindList,LA)))))))]
true
),
assert(Module:Assert),
c_db_add_preds(ViewName,Arity,Module,Con).
@ -239,3 +240,20 @@ db_insert(Connection,RelationName,PredName) :-
assert(Module:Assert),
c_db_add_preds(PredName,Arity,Module,Con).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_abolish(+,+)
%
%
db_abolish(Module:PredName,Arity):-!,
%'$error_checks'(db_abolish(Module:PredName,Arity)),
c_db_delete_predicate(Module,PredName,Arity),
abolish(Module:PredName,Arity).
db_abolish(PredName,Arity):-
%'$error_checks'(db_abolish(PredName,Arity)),
db_module(Module),
c_db_delete_predicate(Module,PredName,Arity),
abolish(Module:PredName,Arity).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -28,6 +28,14 @@
is_list/1
]).
'$error_checks'(db_multi_queries_number(Connection,Number)):-!,
atom(Connection),
( var(Number) ->
true
;
number(Number),
Number > 0
).
'$error_checks'(db_command(Connection,SQL)):-!,
atom(Connection),
nonvar(SQL).