2015-02-10 09:17:59 +00:00
|
|
|
#ifdef USE_MYDDAS
|
2009-02-16 12:23:29 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2015-02-09 10:19:15 +00:00
|
|
|
#if MYDDAS_SQLITE3
|
|
|
|
#include <sqlite3.h>
|
|
|
|
#endif
|
|
|
|
#include "Yap.h"
|
2009-02-16 12:23:29 +00:00
|
|
|
#include "myddas.h"
|
|
|
|
#ifdef MYDDAS_STATS
|
|
|
|
#include "myddas_statistics.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MYDDAS_GLOBAL
|
|
|
|
myddas_init_initialize_myddas(void){
|
|
|
|
MYDDAS_GLOBAL global = NULL;
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
/* We cannot call MYDDAS_MALLOC were because the global
|
|
|
|
register isn't yet initialized */
|
|
|
|
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
|
2015-02-14 11:35:07 +00:00
|
|
|
#ifdef DEBUGX
|
2009-02-16 12:23:29 +00:00
|
|
|
printf ("MALLOC %p %s %d\n",global,__FILE__,__LINE__);
|
2015-02-10 09:17:59 +00:00
|
|
|
#endif
|
2009-02-16 12:23:29 +00:00
|
|
|
global->myddas_top_connections = NULL;
|
|
|
|
#ifdef MYDDAS_TOP_LEVEL
|
|
|
|
global->myddas_top_level_connection = NULL;
|
|
|
|
#endif
|
|
|
|
#ifdef MYDDAS_STATS
|
|
|
|
global->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_stats));
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf ("MALLOC %p %s %d\n",global->myddas_statistics,__FILE__,__LINE__);
|
2015-02-10 09:17:59 +00:00
|
|
|
#endif
|
2009-02-16 12:23:29 +00:00
|
|
|
global->myddas_statistics->stats = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* We first malloc for this struct and the stats struct */
|
|
|
|
#ifdef MYDDAS_STATS
|
|
|
|
global->malloc_called = 2;
|
|
|
|
global->memory_allocated = sizeof(struct myddas_global) + sizeof(struct myddas_global_stats);
|
|
|
|
#else
|
|
|
|
global->malloc_called = 1;
|
|
|
|
global->memory_allocated = sizeof(struct myddas_global);
|
|
|
|
#endif /* MYDDAS_STATS */
|
|
|
|
global->free_called = 0;
|
|
|
|
global->memory_freed = 0;
|
|
|
|
#endif
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
return global;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inserts the new node on the front of the list */
|
2015-02-10 09:17:59 +00:00
|
|
|
MYDDAS_UTIL_CONNECTION
|
2009-02-16 12:23:29 +00:00
|
|
|
myddas_init_initialize_connection(void *conn,void *enviromment,
|
2015-02-14 11:35:07 +00:00
|
|
|
MYDDAS_API api,
|
2009-02-16 12:23:29 +00:00
|
|
|
MYDDAS_UTIL_CONNECTION next){
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2009-02-16 12:23:29 +00:00
|
|
|
MYDDAS_UTIL_CONNECTION new = NULL;
|
|
|
|
MYDDAS_MALLOC(new,struct myddas_list_connection);
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
if (new == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-02-14 11:35:07 +00:00
|
|
|
new->api = api;
|
2009-02-16 12:23:29 +00:00
|
|
|
new->predicates=NULL;
|
|
|
|
new->connection=conn;
|
|
|
|
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;
|
2015-02-10 09:17:59 +00:00
|
|
|
/* If there's already at least one node
|
2009-02-16 12:23:29 +00:00
|
|
|
on the list */
|
|
|
|
if (next != NULL)
|
|
|
|
next->previous=new;
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
#ifdef MYDDAS_STATS
|
|
|
|
new->stats = NULL;
|
|
|
|
new->stats = myddas_stats_initialize_connection_stats();
|
|
|
|
#endif
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2015-02-10 09:17:59 +00:00
|
|
|
MYDDAS_UTIL_PREDICATE
|
2015-06-19 01:19:48 +01:00
|
|
|
myddas_init_initialize_predicate(const char *pred_name, int pred_arity,
|
|
|
|
const char *pred_module, MYDDAS_UTIL_PREDICATE next){
|
2011-03-07 16:02:55 +00:00
|
|
|
CACHE_REGS
|
2009-02-16 12:23:29 +00:00
|
|
|
MYDDAS_UTIL_PREDICATE new = NULL;
|
|
|
|
MYDDAS_MALLOC(new,struct myddas_list_preds);
|
2015-02-10 09:17:59 +00:00
|
|
|
|
|
|
|
if (new == NULL)
|
2009-02-16 12:23:29 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
new->pred_name=pred_name;
|
|
|
|
new->pred_arity=pred_arity;
|
|
|
|
new->pred_module=pred_module;
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
/* List integrity */
|
|
|
|
new->next=next;
|
|
|
|
new->previous=NULL;
|
2015-02-10 09:17:59 +00:00
|
|
|
/* If there's already at least one node
|
2009-02-16 12:23:29 +00:00
|
|
|
on the list */
|
|
|
|
if (next != NULL)
|
|
|
|
next->previous=new;
|
2015-02-10 09:17:59 +00:00
|
|
|
|
2009-02-16 12:23:29 +00:00
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2015-02-10 09:17:59 +00:00
|
|
|
#endif
|