MYDDAS: Updates and BUGs corrections on myddas-statistics
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1533 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
b6b8366698
commit
96bc3dd011
@ -8,6 +8,8 @@ static MYDDAS_UTIL_PREDICATE
|
||||
myddas_util_initialize_predicate(char *, int,char *,
|
||||
MYDDAS_UTIL_PREDICATE);
|
||||
|
||||
|
||||
|
||||
MYDDAS_GLOBAL
|
||||
myddas_util_initialize_myddas(){
|
||||
MYDDAS_GLOBAL global = NULL;
|
||||
@ -15,16 +17,18 @@ myddas_util_initialize_myddas(){
|
||||
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
|
||||
|
||||
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));
|
||||
global->myddas_statistics->total_db_row = 0;
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(global->myddas_statistics->total_db_row,time_final);
|
||||
#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,
|
||||
@ -37,7 +41,6 @@ myddas_util_initialize_connection(void *conn,void *enviromment,
|
||||
}
|
||||
new->predicates=NULL;
|
||||
new->connection=conn;
|
||||
new->temporary_tables=NULL;
|
||||
new->odbc_enviromment=enviromment;
|
||||
|
||||
/* It saves n queries, doing at once n+1 queries */
|
||||
@ -55,13 +58,15 @@ myddas_util_initialize_connection(void *conn,void *enviromment,
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
new->totalNumberOfRows=0;
|
||||
new->totalTimeofDBServer=0;
|
||||
new->lastTimeofDBServer=0;
|
||||
new->totalFromDBServer=0;
|
||||
new->lastFromDBServer=0;
|
||||
new->total_db_row=0;
|
||||
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->totalTimeofDBServer,time_final);
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->lastTimeofDBServer,time_final);
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->totalFromDBServer,time_final);
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->lastFromDBServer,time_final);
|
||||
|
||||
new->lastBytesTransfered=0;
|
||||
new->totalBytesTransfered=0;
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->total_db_row,time_final);
|
||||
new->total_querys_made=0;
|
||||
#endif
|
||||
return new;
|
||||
@ -89,3 +94,4 @@ myddas_util_initialize_predicate(char *pred_name, int pred_arity,
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "cut_c.h"
|
||||
#include "myddas_util.h"
|
||||
#ifdef MYDDAS_STATS
|
||||
#include "myddas_structs.h"
|
||||
#include "myddas_statistics.h"
|
||||
#endif
|
||||
|
||||
@ -53,9 +54,56 @@ STATIC_PROTO(int c_db_my_row_cut,(void));
|
||||
STATIC_PROTO(int c_db_my_get_fields_properties,(void));
|
||||
STATIC_PROTO(int c_db_my_number_of_fields_in_query,(void));
|
||||
STATIC_PROTO(int c_db_my_get_next_result_set,(void));
|
||||
STATIC_PROTO(int c_db_my_get_database,(void));
|
||||
STATIC_PROTO(int c_db_my_change_database,(void));
|
||||
|
||||
void Yap_InitMYDDAS_MySQLPreds(void)
|
||||
{
|
||||
/* db_connect: Host x User x Passwd x Database x Connection x ERROR_CODE */
|
||||
Yap_InitCPred("c_db_my_connect", 5, c_db_my_connect, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
||||
/* db_number_of_fields: Relation x Connection x NumberOfFields */
|
||||
Yap_InitCPred("c_db_my_number_of_fields",3, c_db_my_number_of_fields, 0);
|
||||
|
||||
/* db_number_of_fields_in_query: SQLQuery x Connection x NumberOfFields */
|
||||
Yap_InitCPred("c_db_my_number_of_fields_in_query",3, c_db_my_number_of_fields_in_query, 0);
|
||||
|
||||
/* db_get_attributes_types: Relation x TypesList */
|
||||
Yap_InitCPred("c_db_my_get_attributes_types", 3, c_db_my_get_attributes_types, 0);
|
||||
|
||||
/* db_query: SQLQuery x ResultSet x Connection */
|
||||
Yap_InitCPred("c_db_my_query", 4, c_db_my_query, 0);
|
||||
|
||||
/* db_disconnect: Connection */
|
||||
Yap_InitCPred("c_db_my_disconnect", 1,c_db_my_disconnect, 0);
|
||||
|
||||
/* db_table_write: Result Set */
|
||||
Yap_InitCPred("c_db_my_table_write", 1, c_db_my_table_write, 0);
|
||||
|
||||
/* db_get_fields_properties: PredName x Connnection x PropertiesList*/
|
||||
Yap_InitCPred("c_db_my_get_fields_properties",3,c_db_my_get_fields_properties,0);
|
||||
|
||||
|
||||
Yap_InitCPred("c_db_my_get_next_result_set",2,c_db_my_get_next_result_set,0);
|
||||
|
||||
/* c_db_my_get_database: Connnection x DataBaseName */
|
||||
Yap_InitCPred("c_db_my_get_database",2,c_db_my_get_database,0);
|
||||
|
||||
/* c_db_my_change_database: Connnection x DataBaseName */
|
||||
Yap_InitCPred("c_db_my_change_database",2,c_db_my_change_database,0);
|
||||
|
||||
|
||||
static void n_print(int, char);
|
||||
}
|
||||
|
||||
void Yap_InitBackMYDDAS_MySQLPreds(void)
|
||||
{
|
||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
||||
Yap_InitCPredBackCut("c_db_my_row", 3, sizeof(int),
|
||||
c_db_my_row,
|
||||
c_db_my_row,
|
||||
c_db_my_row_cut, 0);
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
c_db_my_connect(void) {
|
||||
@ -121,13 +169,14 @@ c_db_my_query(void) {
|
||||
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||
|
||||
/* Count the number of querys made to the server */
|
||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
||||
myddas_util_set_conn_number_querys_made(node,++number_querys);
|
||||
unsigned long number_querys;
|
||||
MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(node,number_querys);
|
||||
MYDDAS_STATS_CON_SET_NUMBER_QUERIES_MADE(node,++number_querys);
|
||||
|
||||
/* Measure time spent by the MySQL Server
|
||||
processing the SQL Query */
|
||||
unsigned long start,end,total_time,last_time;
|
||||
start = myddas_current_time();
|
||||
MYDDAS_STATS_TIME start,end,total_time,diff;
|
||||
start = myddas_stats_walltime();
|
||||
#endif
|
||||
|
||||
/* executar a query SQL */
|
||||
@ -140,15 +189,23 @@ c_db_my_query(void) {
|
||||
}
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
/* Measure time spent by the MySQL Server
|
||||
processing the SQL Query */
|
||||
end = myddas_current_time();
|
||||
/* Measure time spent by the MySQL Server
|
||||
processing the SQL Query */
|
||||
end = myddas_stats_walltime();
|
||||
|
||||
last_time = (end-start);
|
||||
total_time = last_time + myddas_util_get_conn_total_time_DBServer(node);
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||
myddas_stats_subtract_time(diff,end,start);
|
||||
diff = myddas_stats_time_copy_to_final(diff);
|
||||
|
||||
myddas_util_set_conn_last_time_DBServer(node,last_time);
|
||||
myddas_util_set_conn_total_time_DBServer(node,total_time);
|
||||
free(end);
|
||||
free(start);
|
||||
|
||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(node,total_time);
|
||||
|
||||
/* Automacally updates the MYDDAS_STRUCTURE */
|
||||
myddas_stats_add_time(total_time,diff,total_time);
|
||||
|
||||
myddas_stats_move_time(diff,node->lastTimeofDBServer);
|
||||
#endif
|
||||
|
||||
/* guardar os tuplos do lado do cliente */
|
||||
@ -158,52 +215,64 @@ c_db_my_query(void) {
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
/* Measure time spent by the MySQL Server
|
||||
transferring the result of the last query
|
||||
transferring the result of the last query
|
||||
back to the client */
|
||||
start = myddas_current_time();
|
||||
start = myddas_stats_walltime();
|
||||
#endif
|
||||
res_set = mysql_store_result(conn);
|
||||
#ifdef MYDDAS_STATS
|
||||
/* Measure time spent by the MySQL Server
|
||||
transferring the result of the last query
|
||||
transferring the result of the last query
|
||||
back to the client */
|
||||
end = myddas_current_time();
|
||||
end = myddas_stats_walltime();
|
||||
|
||||
node = myddas_util_search_connection(conn);
|
||||
last_time = (end-start);
|
||||
total_time = last_time + myddas_util_get_conn_total_transfering_from_DBServer(node);
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||
myddas_stats_subtract_time(diff,end,start);
|
||||
diff = myddas_stats_time_copy_to_final(diff);
|
||||
|
||||
myddas_util_set_conn_last_transfering_from_DBServer(node,last_time);
|
||||
myddas_util_set_conn_total_transfering_from_DBServer(node,total_time);
|
||||
free(end);
|
||||
free(start);
|
||||
|
||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(node,total_time);
|
||||
|
||||
/* Automacally updates the MYDDAS_STRUCTURE */
|
||||
myddas_stats_add_time(total_time,diff,total_time);
|
||||
|
||||
myddas_stats_move_time(diff,node->lastFromDBServer);
|
||||
|
||||
/* Measure the number of Rows returned from the server */
|
||||
if (res_set != NULL)
|
||||
{
|
||||
/* With an INSERT statement, mysql_(use or store)_result()
|
||||
/* With an INSERT statement, mysql_(use or store)_result()
|
||||
returns a NULL pointer*/
|
||||
node = myddas_util_search_connection(conn);
|
||||
|
||||
/* This is only works if we use mysql_store_result */
|
||||
/* This is only works if we use mysql_store_result */
|
||||
unsigned long numberRows = mysql_num_rows(res_set);
|
||||
numberRows = numberRows + myddas_util_get_conn_total_rows(node);
|
||||
myddas_util_set_conn_total_rows(node,numberRows);
|
||||
unsigned long rows;
|
||||
|
||||
MYDDAS_STATS_CON_GET_TOTAL_ROWS(node,rows);
|
||||
numberRows = numberRows + rows;
|
||||
MYDDAS_STATS_CON_SET_TOTAL_ROWS(node,numberRows);
|
||||
|
||||
/* Calculate the ammount of data sent by the server */
|
||||
unsigned long int total,number_fields = mysql_num_fields(res_set);
|
||||
unsigned long int total,number_fields = mysql_num_fields(res_set);
|
||||
MYSQL_ROW row;
|
||||
unsigned int i;
|
||||
total=0;
|
||||
while ((row = mysql_fetch_row(res_set)) != NULL){
|
||||
mysql_field_seek(res_set,0);
|
||||
mysql_field_seek(res_set,0);
|
||||
|
||||
for(i=0;i<number_fields;i++){
|
||||
if (row[i] != NULL)
|
||||
total = total + strlen(row[i]);
|
||||
}
|
||||
}
|
||||
myddas_util_set_conn_last_bytes_transfering_from_DBserver(node,total);
|
||||
total = total + myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
||||
myddas_util_set_conn_total_bytes_transfering_from_DBserver(node,total);
|
||||
MYDDAS_STATS_CON_SET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node,total);
|
||||
unsigned long bytes;
|
||||
|
||||
MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node,bytes);
|
||||
total = total + bytes;
|
||||
MYDDAS_STATS_CON_SET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node,total);
|
||||
mysql_data_seek(res_set,0);
|
||||
}
|
||||
#endif
|
||||
@ -234,7 +303,7 @@ c_db_my_number_of_fields(void) {
|
||||
Term arg_relation = Deref(ARG1);
|
||||
Term arg_conn = Deref(ARG2);
|
||||
Term arg_fields = Deref(ARG3);
|
||||
|
||||
|
||||
char *relation = AtomName(AtomOfTerm(arg_relation));
|
||||
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
|
||||
|
||||
@ -354,74 +423,13 @@ c_db_my_table_write(void) {
|
||||
Term arg_res_set = Deref(ARG1);
|
||||
|
||||
MYSQL_RES *res_set = (MYSQL_RES *) IntegerOfTerm(arg_res_set);
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *fields;
|
||||
int i,f;
|
||||
|
||||
f = mysql_num_fields(res_set);
|
||||
|
||||
fields = mysql_fetch_field(res_set);
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
if (strlen(fields[i].name)>fields[i].max_length) fields[i].max_length=strlen(fields[i].name);
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("|");
|
||||
printf(" %s ",fields[i].name);
|
||||
n_print(fields[i].max_length - strlen(fields[i].name),' ');
|
||||
}
|
||||
printf("|\n");
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
while ((row = mysql_fetch_row(res_set)) != NULL)
|
||||
{
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("|");
|
||||
if (row[i] != NULL)
|
||||
{
|
||||
printf(" %s ",row[i]);
|
||||
n_print(fields[i].max_length - strlen(row[i]),' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" NULL ");
|
||||
n_print(fields[i].max_length - 4,' ');
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
myddas_util_table_write(res_set);
|
||||
mysql_free_result(res_set);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Auxilary function to table_write*/
|
||||
static void
|
||||
n_print(int n, char c)
|
||||
{
|
||||
for(;n>0;n--) printf("%c",c);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
c_db_my_row_cut(void) {
|
||||
MYSQL_RES *mysql_res=NULL;
|
||||
@ -437,8 +445,8 @@ c_db_my_row(void) {
|
||||
#ifdef MYDDAS_STATS
|
||||
/* Measure time used by the
|
||||
c_db_my_row function */
|
||||
unsigned long start,end,total_time,last_time;
|
||||
start = myddas_current_time();
|
||||
MYDDAS_STATS_TIME start,end,total_time,diff;
|
||||
start = myddas_stats_walltime();
|
||||
#endif
|
||||
Term arg_result_set = Deref(ARG1);
|
||||
Term arg_arity = Deref(ARG2);
|
||||
@ -496,12 +504,19 @@ c_db_my_row(void) {
|
||||
}
|
||||
}
|
||||
#ifdef MYDDAS_STATS
|
||||
end = myddas_current_time();
|
||||
end = myddas_stats_walltime();
|
||||
|
||||
last_time = (end-start);
|
||||
total_time = last_time + myddas_util_get_total_db_row_function();
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||
myddas_stats_subtract_time(diff,end,start);
|
||||
diff = myddas_stats_time_copy_to_final(diff);
|
||||
|
||||
myddas_util_set_total_db_row_function(total_time);
|
||||
free(end);
|
||||
free(start);
|
||||
|
||||
MYDDAS_STATS_GET_DB_ROW_FUNCTION(total_time);
|
||||
myddas_stats_add_time(total_time,diff,total_time);
|
||||
|
||||
free(diff);
|
||||
#endif /* MYDDAS_STATS */
|
||||
return TRUE;
|
||||
}
|
||||
@ -510,12 +525,19 @@ c_db_my_row(void) {
|
||||
mysql_free_result(res_set);
|
||||
cut_fail();
|
||||
#ifdef MYDDAS_STATS
|
||||
end = myddas_current_time();
|
||||
end = myddas_stats_walltime();
|
||||
|
||||
last_time = (end-start);
|
||||
total_time = last_time + myddas_util_get_total_db_row_function();
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||
myddas_stats_subtract_time(diff,end,start);
|
||||
diff = myddas_stats_time_copy_to_final(diff);
|
||||
|
||||
myddas_util_set_total_db_row_function(total_time);
|
||||
free(end);
|
||||
free(start);
|
||||
|
||||
MYDDAS_STATS_GET_DB_ROW_FUNCTION(total_time);
|
||||
myddas_stats_add_time(total_time,diff,total_time);
|
||||
|
||||
free(diff);
|
||||
#endif /* MYDDAS_STATS */
|
||||
return FALSE;
|
||||
}
|
||||
@ -656,44 +678,32 @@ c_db_my_get_next_result_set(void) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void Yap_InitMYDDAS_MySQLPreds(void)
|
||||
{
|
||||
/* db_connect: Host x User x Passwd x Database x Connection x ERROR_CODE */
|
||||
Yap_InitCPred("c_db_my_connect", 5, c_db_my_connect, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
static int
|
||||
c_db_my_get_database(void) {
|
||||
Term arg_con = Deref(ARG1);
|
||||
Term arg_database = Deref(ARG2);
|
||||
|
||||
/* db_number_of_fields: Relation x Connection x NumberOfFields */
|
||||
Yap_InitCPred("c_db_my_number_of_fields",3, c_db_my_number_of_fields, 0);
|
||||
MYSQL *con = (MYSQL *) (IntegerOfTerm(arg_con));
|
||||
|
||||
if (!Yap_unify(arg_database,MkAtomTerm(Yap_LookupAtom(con->db))))
|
||||
return FALSE;
|
||||
|
||||
/* db_number_of_fields_in_query: SQLQuery x Connection x NumberOfFields */
|
||||
Yap_InitCPred("c_db_my_number_of_fields_in_query",3, c_db_my_number_of_fields_in_query, 0);
|
||||
return TRUE;
|
||||
|
||||
/* db_get_attributes_types: Relation x TypesList */
|
||||
Yap_InitCPred("c_db_my_get_attributes_types", 3, c_db_my_get_attributes_types, 0);
|
||||
|
||||
/* db_query: SQLQuery x ResultSet x Connection */
|
||||
Yap_InitCPred("c_db_my_query", 4, c_db_my_query, 0);
|
||||
|
||||
/* db_disconnect: Connection */
|
||||
Yap_InitCPred("c_db_my_disconnect", 1,c_db_my_disconnect, 0);
|
||||
|
||||
/* db_table_write: Result Set */
|
||||
Yap_InitCPred("c_db_my_table_write", 1, c_db_my_table_write, 0);
|
||||
|
||||
/* db_get_fields_properties: PredName x Connnection x PropertiesList*/
|
||||
Yap_InitCPred("c_db_my_get_fields_properties",3,c_db_my_get_fields_properties,0);
|
||||
|
||||
/* db_get_fields_properties: PredName x Connnection x PropertiesList*/
|
||||
Yap_InitCPred("c_db_my_get_next_result_set",2,c_db_my_get_next_result_set,0);
|
||||
}
|
||||
|
||||
void Yap_InitBackMYDDAS_MySQLPreds(void)
|
||||
{
|
||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
||||
Yap_InitCPredBackCut("c_db_my_row", 3, sizeof(int),
|
||||
c_db_my_row,
|
||||
c_db_my_row,
|
||||
c_db_my_row_cut, 0);
|
||||
static int
|
||||
c_db_my_change_database(void) {
|
||||
Term arg_con = Deref(ARG1);
|
||||
Term arg_database = Deref(ARG2);
|
||||
|
||||
MYSQL *con = (MYSQL *) (IntegerOfTerm(arg_con));
|
||||
char *database = AtomName(AtomOfTerm(arg_database));
|
||||
|
||||
if (mysql_select_db(con,database)!=0)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif /*MYDDAS_MYSQL && CUT_C*/
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "myddas_util.h"
|
||||
#include <stdlib.h>
|
||||
#ifdef MYDDAS_STATS
|
||||
#include "myddas_structs.h"
|
||||
#include "myddas_statistics.h"
|
||||
#endif
|
||||
|
||||
@ -252,95 +253,113 @@ c_db_stats(void) {
|
||||
node = myddas_util_search_connection(conn);
|
||||
Term head, list;
|
||||
list = arg_list;
|
||||
|
||||
MYDDAS_STATS_TIME time;
|
||||
unsigned long number;
|
||||
|
||||
|
||||
//[Index 1] -> Total Number of Rows by connection
|
||||
//Total number of Rows returned by the server
|
||||
//WARNING: only works with store_result
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long totalRows = myddas_util_get_conn_total_rows(node);
|
||||
Yap_unify(head, MkIntegerTerm(totalRows));
|
||||
MYDDAS_STATS_CON_GET_TOTAL_ROWS(node,number);
|
||||
Yap_unify(head, MkIntegerTerm(number));
|
||||
#ifdef DEBUG
|
||||
printf ("Total Number of Rows returned from the Server: %lu\n",totalRows);
|
||||
printf ("Total Number of Rows returned from the Server\n");
|
||||
printf ("%lu\n\n",number);
|
||||
#endif
|
||||
|
||||
//[Index 2] -> Total of Time Spent by the DB Server
|
||||
// processing all the SQL Querys
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long totalTimeDBServer = myddas_util_get_conn_total_time_DBServer(node);
|
||||
Yap_unify(head, MkIntegerTerm(totalTimeDBServer));
|
||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(node,time);
|
||||
Yap_unify(head, MkIntegerTerm((int)time));
|
||||
#ifdef DEBUG
|
||||
printf ("Time Spent by the Server, on all the SQL Querys: %lu\n",totalTimeDBServer);
|
||||
printf ("Reference to time Spent by the Server, on all the SQL Querys\n");
|
||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||
printf ("\n\n");
|
||||
#endif
|
||||
|
||||
//[Index 3] -> Total of Time Spent by the DB Server
|
||||
// processing a the last SQL Query
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long lastTimeDBServer = myddas_util_get_conn_last_time_DBServer(node);
|
||||
Yap_unify(head, MkIntegerTerm(lastTimeDBServer));
|
||||
MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(node,time);
|
||||
Yap_unify(head, MkIntegerTerm((int)time));
|
||||
#ifdef DEBUG
|
||||
printf ("Time Spent by the Server, on the last SQL Query: %lu\n",lastTimeDBServer);
|
||||
printf ("Reference to time Spent by the Server, on the last SQL Query\n");
|
||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||
printf ("\n\n");
|
||||
#endif
|
||||
|
||||
//[Index 4] -> Total of Time Spent by the DB Server
|
||||
// transfering all the results of the SQL Querys
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long totalFromDBServer = myddas_util_get_conn_total_transfering_from_DBServer(node);
|
||||
Yap_unify(head, MkIntegerTerm(totalFromDBServer));
|
||||
MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(node,time);
|
||||
Yap_unify(head, MkIntegerTerm((int)time));
|
||||
#ifdef DEBUG
|
||||
printf ("Time Spent by the Server, transfering all the results SQL Query: %lu\n",totalFromDBServer);
|
||||
printf ("Refence to time Spent by the Server, transfering all the results SQL Query\n");
|
||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||
printf ("\n\n");
|
||||
#endif
|
||||
|
||||
//[Index 5] -> Total of Time Spent by the DB Server
|
||||
// transfering the result of the last SQL Query
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long lastFromDBServer = myddas_util_get_conn_last_transfering_from_DBServer(node);
|
||||
Yap_unify(head, MkIntegerTerm(lastFromDBServer));
|
||||
MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(node,time);
|
||||
Yap_unify(head, MkIntegerTerm((int)time));
|
||||
#ifdef DEBUG
|
||||
printf ("Time Spent by the Server, transfering the result of the last SQL Query: %lu\n",lastFromDBServer);
|
||||
printf ("Reference to time Spent by the Server, transfering the result of the last SQL Query\n");
|
||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||
printf ("\n\n");
|
||||
#endif
|
||||
|
||||
//[Index 6] -> Total of Time Spent by the
|
||||
// db_row_function
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long db_row = myddas_util_get_total_db_row_function();
|
||||
Yap_unify(head, MkIntegerTerm(db_row));
|
||||
MYDDAS_STATS_GET_DB_ROW_FUNCTION(time);
|
||||
Yap_unify(head, MkIntegerTerm((int)time));
|
||||
#ifdef DEBUG
|
||||
printf ("Time Spent by the db_row_function: %lu\n",db_row);
|
||||
printf ("Reference to time Spent by the db_row_function\n");
|
||||
MYDDAS_STATS_PRINT_TIME_STRUCT(time);
|
||||
printf ("\n\n");
|
||||
#endif
|
||||
|
||||
//[Index 7] -> Total of Bytes Transfered by the
|
||||
// DB Server on all SQL Querys
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long totalBytes = myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
||||
Yap_unify(head, MkIntegerTerm(totalBytes));
|
||||
MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
||||
Yap_unify(head, MkIntegerTerm(number));
|
||||
#ifdef DEBUG
|
||||
printf ("Bytes Transfered by the DB Server from all querys: %lu\n",totalBytes);
|
||||
printf ("Bytes Transfered by the DB Server from all querys\n");
|
||||
printf ("%lu\n\n",number);
|
||||
#endif
|
||||
|
||||
//[Index 8] -> Total of Bytes Transfered by the
|
||||
// DB Server on the last SQL Query
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long lastBytes = myddas_util_get_conn_last_bytes_transfering_from_DBserver(node);
|
||||
Yap_unify(head, MkIntegerTerm(lastBytes));
|
||||
MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
||||
Yap_unify(head, MkIntegerTerm(number));
|
||||
#ifdef DEBUG
|
||||
printf ("Bytes Transfered by the DB Server on the last query: %lu\n",lastBytes);
|
||||
printf ("Bytes Transfered by the DB Server on the last query\n");
|
||||
printf ("%lu\n\n",number);
|
||||
#endif
|
||||
|
||||
//[Index 9] -> Number of querys made to the DBserver
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
||||
Yap_unify(head, MkIntegerTerm(number_querys));
|
||||
MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(node,number);
|
||||
Yap_unify(head, MkIntegerTerm(number));
|
||||
#ifdef DEBUG
|
||||
printf ("Number of Querys made to the server: %lu\n",number_querys);
|
||||
printf ("Number of Querys made to the server\n");
|
||||
printf ("%lu\n\n",number);
|
||||
#endif
|
||||
|
||||
return TRUE;
|
||||
|
@ -1,131 +1,246 @@
|
||||
#include "myddas_structs.h"
|
||||
#include "myddas_statistics.h"
|
||||
#include "Yap.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#ifdef CUT_C
|
||||
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL
|
||||
|
||||
|
||||
#include "myddas_structs.h"
|
||||
#include "myddas_statistics.h"
|
||||
#include "Yap.h"
|
||||
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||
static void
|
||||
myddas_stats_time_subtract (unsigned long *, unsigned long *, MYDDAS_STATS_TIME, MYDDAS_STATS_TIME);
|
||||
static void
|
||||
myddas_stats_add_seconds_time(MYDDAS_STATS_TIME,unsigned long, unsigned long);
|
||||
static void
|
||||
myddas_stats_integrity_of_time(MYDDAS_STATS_TIME);
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
int
|
||||
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION node){
|
||||
return node->totalNumberOfRows;
|
||||
|
||||
/* Documentation: Time Units
|
||||
------------------------------------------------------------------------
|
||||
*****| Second(s) | MiliSeconds(ms) | MicroSeconds(us) | NanoSecond(ns) |
|
||||
-----|-----------|-----------------|------------------|----------------|
|
||||
s | 1 | 0.001 | 0.000001 | 1e-9 |
|
||||
ms | 1000 | 1 | 0.001 | 0.000001 |
|
||||
us | 10000000 | 1000 | 1 | 0.001 |
|
||||
ns |1000000000 | 1000000 | 1000 | 1 |
|
||||
------------------------------------------------------------------------
|
||||
|
||||
------
|
||||
|
||||
The struct timeval structure represents an elapsed time. It is
|
||||
declared in `sys/time.h' and has the following members:
|
||||
|
||||
long int tv_sec -> This represents the number of whole seconds of
|
||||
elapsed time.
|
||||
|
||||
long int tv_usec -> This is the rest of the elapsed time (a fraction
|
||||
of a second), represented as the number of microseconds. It is
|
||||
always less than one million.
|
||||
|
||||
|
||||
------
|
||||
|
||||
The struct timespec structure represents an elapsed time. It is
|
||||
declared in `time.h' and has the following members:
|
||||
|
||||
long int tv_sec -> This represents the number of whole seconds of
|
||||
elapsed time.
|
||||
|
||||
long int tv_nsec -> This is the rest of the elapsed time (a fraction
|
||||
of a second), represented as the number of nanoseconds. It is
|
||||
always less than one billion.
|
||||
|
||||
-----
|
||||
|
||||
The gettimeofday() function shall obtain the current time,
|
||||
expressed as seconds and microseconds since the Epoch, and store
|
||||
it in the timeval structure pointed to by tp. The resolution of
|
||||
the system clock is unspecified.
|
||||
|
||||
If tzp is not a null pointer, the behavior is unspecified.
|
||||
|
||||
*/
|
||||
|
||||
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||
|
||||
|
||||
/* Be shore to delete MYDDAS_STATS_TIME structure */
|
||||
MYDDAS_STATS_TIME
|
||||
myddas_stats_walltime(void) {
|
||||
|
||||
MYDDAS_STATS_TIME myddas_time;
|
||||
myddas_time = (MYDDAS_STATS_TIME) malloc (sizeof(struct timeval));
|
||||
myddas_time->type = time_copy;
|
||||
|
||||
struct timeval time;
|
||||
gettimeofday(&time,NULL);
|
||||
|
||||
myddas_time->u.time_copy.tv_sec = time.tv_sec;
|
||||
myddas_time->u.time_copy.tv_usec = time.tv_usec;
|
||||
|
||||
return myddas_time;
|
||||
}
|
||||
|
||||
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 */
|
||||
myddas_stats_add_time(MYDDAS_STATS_TIME sum, MYDDAS_STATS_TIME time1,MYDDAS_STATS_TIME time2){
|
||||
|
||||
Int now, interval;
|
||||
//Yap_cputime_interval(&now, &interval);
|
||||
if (sum->type == time_final){
|
||||
sum->u.time_final.microseconds =
|
||||
time1->u.time_final.microseconds +
|
||||
time2->u.time_final.microseconds;
|
||||
sum->u.time_final.miliseconds =
|
||||
time1->u.time_final.miliseconds +
|
||||
time2->u.time_final.miliseconds;
|
||||
sum->u.time_final.seconds =
|
||||
time1->u.time_final.seconds +
|
||||
time2->u.time_final.seconds;
|
||||
sum->u.time_final.minutes =
|
||||
time1->u.time_final.minutes +
|
||||
time2->u.time_final.minutes;
|
||||
sum->u.time_final.hours =
|
||||
time1->u.time_final.hours +
|
||||
time2->u.time_final.hours;
|
||||
} else {
|
||||
sum->u.time_copy.tv_sec =
|
||||
time1->u.time_copy.tv_sec +
|
||||
time2->u.time_copy.tv_sec;
|
||||
sum->u.time_copy.tv_usec =
|
||||
time1->u.time_copy.tv_usec +
|
||||
time2->u.time_copy.tv_usec;
|
||||
}
|
||||
|
||||
myddas_stats_integrity_of_time(sum);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
myddas_stats_subtract_time(MYDDAS_STATS_TIME result, MYDDAS_STATS_TIME t1,MYDDAS_STATS_TIME t2){
|
||||
|
||||
if (result->type == time_copy){
|
||||
|
||||
unsigned long sec;
|
||||
unsigned long usec;
|
||||
myddas_stats_time_subtract(&sec,&usec,t1,t2);
|
||||
|
||||
//milliseconds
|
||||
Yap_walltime_interval(&now, &interval);
|
||||
//return ((realtime)now);
|
||||
return (now);
|
||||
result->u.time_copy.tv_sec = sec;
|
||||
result->u.time_copy.tv_usec = usec;
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
/*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;
|
||||
}
|
||||
|
||||
void
|
||||
myddas_stats_move_time(MYDDAS_STATS_TIME from,
|
||||
MYDDAS_STATS_TIME to)
|
||||
{
|
||||
if (from->type == time_copy)
|
||||
{
|
||||
to->type = time_copy;
|
||||
to->u.time_copy.tv_sec = from->u.time_copy.tv_sec;
|
||||
to->u.time_copy.tv_usec = from->u.time_copy.tv_usec;
|
||||
}
|
||||
else if (from->type == time_final)
|
||||
{
|
||||
to->u.time_final.hours = from->u.time_final.hours;
|
||||
to->u.time_final.minutes = from->u.time_final.minutes;
|
||||
to->u.time_final.seconds = from->u.time_final.seconds;
|
||||
to->u.time_final.miliseconds = from->u.time_final.miliseconds;
|
||||
to->u.time_final.microseconds = from->u.time_final.microseconds;
|
||||
}
|
||||
free(from);
|
||||
}
|
||||
|
||||
MYDDAS_STATS_TIME
|
||||
myddas_stats_time_copy_to_final(MYDDAS_STATS_TIME t_copy){
|
||||
|
||||
MYDDAS_STATS_TIME t_final;
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(t_final,time_final);
|
||||
|
||||
myddas_stats_add_seconds_time(t_final,
|
||||
t_copy->u.time_copy.tv_sec,
|
||||
t_copy->u.time_copy.tv_usec);
|
||||
free(t_copy);
|
||||
return t_final;
|
||||
}
|
||||
|
||||
static void
|
||||
myddas_stats_add_seconds_time(MYDDAS_STATS_TIME myddas_time,
|
||||
unsigned long sec,
|
||||
unsigned long usec){
|
||||
|
||||
short hours = sec / 3600;
|
||||
sec %= 3600;
|
||||
short minutes = sec / 60;
|
||||
sec %= 60;
|
||||
short milisec = usec / 1000;
|
||||
usec %= 1000;
|
||||
|
||||
myddas_time->u.time_final.microseconds += usec ;
|
||||
myddas_time->u.time_final.miliseconds += milisec;
|
||||
myddas_time->u.time_final.seconds += sec ;
|
||||
myddas_time->u.time_final.minutes += minutes ;
|
||||
myddas_time->u.time_final.hours += hours;
|
||||
|
||||
myddas_stats_integrity_of_time(myddas_time);
|
||||
}
|
||||
|
||||
|
||||
#endif /* MYDDAS_STATS */
|
||||
static void
|
||||
myddas_stats_time_subtract(unsigned long *sec,unsigned long *usec,
|
||||
MYDDAS_STATS_TIME start, MYDDAS_STATS_TIME end){
|
||||
|
||||
/* Perform the carry for the later subtraction by updating y. */
|
||||
if (start->u.time_copy.tv_usec < end->u.time_copy.tv_usec) {
|
||||
int nsec = (end->u.time_copy.tv_usec - start->u.time_copy.tv_usec) / 1000000 + 1;
|
||||
end->u.time_copy.tv_usec -= 1000000 * nsec;
|
||||
end->u.time_copy.tv_sec += nsec;
|
||||
}
|
||||
if (start->u.time_copy.tv_usec - end->u.time_copy.tv_usec > 1000000) {
|
||||
int nsec = (start->u.time_copy.tv_usec - end->u.time_copy.tv_usec) / 1000000;
|
||||
end->u.time_copy.tv_usec += 1000000 * nsec;
|
||||
end->u.time_copy.tv_sec -= nsec;
|
||||
}
|
||||
|
||||
/* Compute the time remaining to wait.
|
||||
tv_usec is certainly positive. */
|
||||
*sec = start->u.time_copy.tv_sec - end->u.time_copy.tv_sec;
|
||||
*usec = start->u.time_copy.tv_usec - end->u.time_copy.tv_usec;
|
||||
}
|
||||
|
||||
static void
|
||||
myddas_stats_integrity_of_time(MYDDAS_STATS_TIME myddas_time){
|
||||
|
||||
if (myddas_time->u.time_final.microseconds > 999)
|
||||
{
|
||||
myddas_time->u.time_final.microseconds -= 1000;
|
||||
myddas_time->u.time_final.miliseconds++;
|
||||
}
|
||||
if (myddas_time->u.time_final.miliseconds > 999)
|
||||
{
|
||||
myddas_time->u.time_final.miliseconds -= 1000;
|
||||
myddas_time->u.time_final.seconds++;
|
||||
}
|
||||
|
||||
if (myddas_time->u.time_final.seconds > 59)
|
||||
{
|
||||
myddas_time->u.time_final.seconds -= 60;
|
||||
myddas_time->u.time_final.minutes++;
|
||||
}
|
||||
|
||||
if (myddas_time->u.time_final.minutes > 59)
|
||||
{
|
||||
myddas_time->u.time_final.minutes -= 60;
|
||||
myddas_time->u.time_final.hours++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* MYDDAS_STATS || MYDDAS_TOP_LEVEL */
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
@ -1,54 +1,92 @@
|
||||
#ifndef __MYDDAS_STATISTICS_H__
|
||||
#define __MYDDAS_STATISTICS_H__
|
||||
|
||||
|
||||
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||
|
||||
#define MYDDAS_STATS_PRINT_TIME_STRUCT(TIME) \
|
||||
if (TIME->type == time_final) { \
|
||||
printf ("%d Hours, %d Minutes, %d Seconds, %d Miliseconds, %d Microseconds", \
|
||||
TIME->u.time_final.hours, \
|
||||
TIME->u.time_final.minutes, \
|
||||
TIME->u.time_final.seconds, \
|
||||
TIME->u.time_final.miliseconds, \
|
||||
TIME->u.time_final.microseconds); \
|
||||
} else { \
|
||||
printf ("%d Seconds, %d Microseconds", \
|
||||
TIME->u.time_copy.tv_sec, \
|
||||
TIME->u.time_copy.tv_usec); \
|
||||
}
|
||||
|
||||
|
||||
#define MYDDAS_STATS_INITIALIZE_TIME_STRUCT(TIME,TYPE) \
|
||||
TIME = (MYDDAS_STATS_TIME) malloc (sizeof(struct myddas_stats_time_struct)); \
|
||||
\
|
||||
if (TYPE == time_copy){ \
|
||||
TIME->type = TYPE; \
|
||||
TIME->u.time_copy.tv_sec = 0; \
|
||||
TIME->u.time_copy.tv_usec = 0; \
|
||||
} else { \
|
||||
TIME->type = TYPE; \
|
||||
TIME->u.time_final.hours = 0; \
|
||||
TIME->u.time_final.minutes = 0; \
|
||||
TIME->u.time_final.seconds = 0; \
|
||||
TIME->u.time_final.miliseconds = 0; \
|
||||
TIME->u.time_final.microseconds = 0; \
|
||||
}
|
||||
|
||||
|
||||
MYDDAS_STATS_TIME
|
||||
myddas_stats_walltime(void);
|
||||
void
|
||||
myddas_stats_add_time(MYDDAS_STATS_TIME, MYDDAS_STATS_TIME,MYDDAS_STATS_TIME);
|
||||
void
|
||||
myddas_stats_subtract_time(MYDDAS_STATS_TIME, MYDDAS_STATS_TIME,MYDDAS_STATS_TIME);
|
||||
void
|
||||
myddas_stats_move_time(MYDDAS_STATS_TIME,MYDDAS_STATS_TIME);
|
||||
MYDDAS_STATS_TIME
|
||||
myddas_stats_time_copy_to_final(MYDDAS_STATS_TIME);
|
||||
#endif
|
||||
|
||||
|
||||
#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);
|
||||
#define MYDDAS_STATS_CON_GET_TOTAL_ROWS(NODE,NUMBER) \
|
||||
NUMBER = NODE->totalNumberOfRows;
|
||||
#define MYDDAS_STATS_CON_SET_TOTAL_ROWS(NODE,NUMBER) \
|
||||
NODE->totalNumberOfRows = NUMBER;
|
||||
|
||||
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);
|
||||
#define MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(NODE,TIME) \
|
||||
TIME = NODE->totalTimeofDBServer;
|
||||
|
||||
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);
|
||||
#define MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(NODE,TIME) \
|
||||
TIME = NODE->lastTimeofDBServer;
|
||||
|
||||
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);
|
||||
#define MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(NODE,TIME) \
|
||||
TIME = NODE->totalFromDBServer;
|
||||
|
||||
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);
|
||||
#define MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(NODE,TIME) \
|
||||
TIME = NODE->lastFromDBServer;
|
||||
|
||||
unsigned long
|
||||
myddas_util_get_total_db_row_function(void);
|
||||
void
|
||||
myddas_util_set_total_db_row_function(unsigned long);
|
||||
#define MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||
NUMBER = NODE->lastBytesTransfered;
|
||||
#define MYDDAS_STATS_CON_SET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||
NODE->lastBytesTransfered = NUMBER;
|
||||
|
||||
#define MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||
NUMBER = NODE->totalBytesTransfered;
|
||||
#define MYDDAS_STATS_CON_SET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||
NODE->totalBytesTransfered = NUMBER;
|
||||
|
||||
|
||||
unsigned long
|
||||
myddas_current_time(void);
|
||||
#define MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(NODE,NUMBER) \
|
||||
NUMBER = NODE->total_querys_made;
|
||||
#define MYDDAS_STATS_CON_SET_NUMBER_QUERIES_MADE(NODE,NUMBER) \
|
||||
NODE->total_querys_made = NUMBER;
|
||||
|
||||
#define MYDDAS_STATS_GET_DB_ROW_FUNCTION(TIME) \
|
||||
TIME = Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_statistics->total_db_row;
|
||||
|
||||
#endif /* MYDDAS_STATS */
|
||||
|
||||
#endif
|
||||
|
@ -5,26 +5,18 @@
|
||||
|
||||
struct myddas_global {
|
||||
MYDDAS_UTIL_CONNECTION myddas_top_connections;
|
||||
#ifdef MYDDAS_TOP_LEVEL
|
||||
MYDDAS_UTIL_CONNECTION myddas_top_level_connection;
|
||||
#endif
|
||||
#ifdef MYDDAS_STATS
|
||||
MYDDAS_GLOBAL_STATS myddas_statistics;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct myddas_table_integers {
|
||||
unsigned int number;
|
||||
struct myddas_table_integers *next;
|
||||
};
|
||||
|
||||
struct myddas_temp_tables{
|
||||
struct myddas_table_integers *table_numbers;
|
||||
struct myddas_table_integers *last_number;
|
||||
char *default_table_name;
|
||||
};
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
/* This strucuture holds some global statistics*/
|
||||
struct myddas_global_stats {
|
||||
unsigned long total_db_row;
|
||||
MYDDAS_STATS_TIME total_db_row;
|
||||
};
|
||||
#endif /* MYDDAS_STATS */
|
||||
|
||||
@ -38,8 +30,7 @@ struct myddas_list_preds {
|
||||
|
||||
struct myddas_list_connection {
|
||||
void *connection;
|
||||
MYDDAS_TEMP_TABLES temporary_tables;
|
||||
|
||||
|
||||
/*If variable env is NULL, then it's a
|
||||
MySQL connection, if not then it as the pointer
|
||||
to the ODBC enviromment variable */
|
||||
@ -50,17 +41,17 @@ struct myddas_list_connection {
|
||||
|
||||
/* Total Time spent by the DataBase Server
|
||||
processing all querys */
|
||||
unsigned long totalTimeofDBServer;
|
||||
MYDDAS_STATS_TIME totalTimeofDBServer;
|
||||
/* Time spent by the DataBase Server, processing
|
||||
the last query */
|
||||
unsigned long lastTimeofDBServer;
|
||||
MYDDAS_STATS_TIME lastTimeofDBServer;
|
||||
|
||||
/* Total Time spent by the DataBase Server,
|
||||
transfering all the data to the client */
|
||||
unsigned long totalFromDBServer;
|
||||
MYDDAS_STATS_TIME totalFromDBServer;
|
||||
/* Time spent by the DataBase Server,
|
||||
transfering the data of the last query */
|
||||
unsigned long lastFromDBServer;
|
||||
MYDDAS_STATS_TIME lastFromDBServer;
|
||||
|
||||
/* Last bytes transfered from the server */
|
||||
unsigned long totalBytesTransfered;
|
||||
@ -68,17 +59,19 @@ struct myddas_list_connection {
|
||||
unsigned long lastBytesTransfered;
|
||||
|
||||
/* Total Time spent on the db_row function */
|
||||
unsigned long total_db_row;
|
||||
MYDDAS_STATS_TIME total_db_row;
|
||||
|
||||
/* Number of querys made to the Server*/
|
||||
unsigned long total_querys_made;
|
||||
#endif
|
||||
MYDDAS_UTIL_PREDICATE predicates;
|
||||
|
||||
/*Multi Queries Section */
|
||||
/* Multi Queries Section */
|
||||
unsigned long total_number_queries;
|
||||
unsigned long actual_number_queries;
|
||||
MYDDAS_UTIL_QUERY *queries;
|
||||
|
||||
/* List Integrety */
|
||||
MYDDAS_UTIL_CONNECTION next;
|
||||
MYDDAS_UTIL_CONNECTION previous;
|
||||
};
|
||||
@ -88,4 +81,26 @@ struct myddas_util_query{
|
||||
MYDDAS_UTIL_QUERY next;
|
||||
};
|
||||
|
||||
|
||||
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||
struct myddas_stats_time_struct{
|
||||
enum {time_copy,
|
||||
time_final} type;
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned long tv_sec;
|
||||
unsigned long tv_usec;
|
||||
} time_copy;
|
||||
struct {
|
||||
unsigned short hours;
|
||||
unsigned short minutes; //Max 59
|
||||
unsigned short seconds; //Max 59
|
||||
unsigned short miliseconds; //Max 999
|
||||
unsigned short microseconds; //Max 999
|
||||
} time_final;
|
||||
} u;
|
||||
};
|
||||
#endif /* MYDDAS_STATS || MYDDAS_TOP_LEVEL */
|
||||
|
||||
#endif
|
||||
|
@ -1,393 +0,0 @@
|
||||
|
||||
#if (defined MYDDAS_MYSQL || defined MYDDAS_ODBC) && defined CUT_C
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mysql/mysql.h>
|
||||
#include "Yap.h"
|
||||
#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 || \
|
||||
FIELD == FIELD_TYPE_LONGLONG || \
|
||||
FIELD == FIELD_TYPE_SHORT || \
|
||||
FIELD == FIELD_TYPE_TINY
|
||||
|
||||
#define IS_SQL_FLOAT(FIELD) FIELD == FIELD_TYPE_DECIMAL || \
|
||||
FIELD == FIELD_TYPE_DOUBLE || \
|
||||
FIELD == FIELD_TYPE_FLOAT
|
||||
|
||||
|
||||
static int null_id = 0;
|
||||
|
||||
|
||||
STATIC_PROTO(int c_db_my_query_no_result,(void));
|
||||
STATIC_PROTO(int c_db_my_query_result,(void));
|
||||
|
||||
STATIC_PROTO(int c_db_my_row,(void));
|
||||
STATIC_PROTO(int c_db_my_row_cut,(void));
|
||||
STATIC_PROTO(int c_db_my_row_unify,(void));
|
||||
|
||||
static int
|
||||
c_db_my_query_no_result(void) {
|
||||
Term arg_sql_query = Deref(ARG1);
|
||||
Term arg_conn = Deref(ARG2);
|
||||
|
||||
char *sql = AtomName(AtomOfTerm(arg_sql_query));
|
||||
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
|
||||
|
||||
int length=strlen(sql);
|
||||
if (mysql_real_query(conn, sql, length) != 0){
|
||||
printf("Erro na query!\n");
|
||||
return FALSE;
|
||||
}
|
||||
/* With an INSERT statement,
|
||||
mysql_(use or store)_result() returns
|
||||
a NULL pointer, so it isn't necessary to
|
||||
use mysql_(use or store)_result*/
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Only use this function, with querys that return result sets*/
|
||||
/* db_query: SQLQuery x ResultSet x Connection */
|
||||
static int
|
||||
c_db_my_query_result(void) {
|
||||
Term arg_sql_query = Deref(ARG1);
|
||||
Term arg_result_set = Deref(ARG2);
|
||||
Term arg_conn = Deref(ARG3);
|
||||
Term arg_mode = Deref(ARG4);
|
||||
|
||||
char *sql = AtomName(AtomOfTerm(arg_sql_query));
|
||||
char *mode = AtomName(AtomOfTerm(arg_mode));
|
||||
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
|
||||
|
||||
MYSQL_RES *res_set;
|
||||
|
||||
int length=strlen(sql);
|
||||
|
||||
/* executar a query SQL */
|
||||
if (mysql_real_query(conn, sql, length) != 0)
|
||||
{
|
||||
printf("Erro na query!\n");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* guardar os tuplos do lado do cliente */
|
||||
if (strcmp(mode,"store_result")!=0) //Verdadeiro
|
||||
{
|
||||
res_set = mysql_use_result(conn);
|
||||
}
|
||||
else
|
||||
{
|
||||
res_set = mysql_store_result(conn);
|
||||
|
||||
int count = mysql_num_rows(res_set);
|
||||
if (count == 0){
|
||||
mysql_free_result(res_set);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
MYDDAS_UTIL_CONNECTION node =
|
||||
myddas_util_search_connection(conn);
|
||||
|
||||
/* This only works if we use mysql_store_result */
|
||||
int numberRows = mysql_num_rows(res_set);
|
||||
numberRows = numberRows + myddas_util_get_conn_total_rows(node);
|
||||
myddas_util_set_conn_total_rows(node,numberRows);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
Bind(VarOfTerm(arg_result_set), MkIntegerTerm((int) res_set));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
c_db_my_row_cut(void) {
|
||||
MYSQL_RES *mysql_res=NULL;
|
||||
|
||||
mysql_res = (MYSQL_RES *) IntegerOfTerm(EXTRA_CBACK_CUT_ARG(Term,1));
|
||||
mysql_free_result(mysql_res);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* db_row: ResultSet x Arity_ListOfArgs x ListOfArgs -> */
|
||||
static int
|
||||
c_db_my_row(void) {
|
||||
Term arg_result_set = Deref(ARG1);
|
||||
Term arg_arity = Deref(ARG2);
|
||||
Term arg_list_args = Deref(ARG3);
|
||||
|
||||
MYSQL_RES *res_set = (MYSQL_RES *) IntegerOfTerm(arg_result_set);
|
||||
EXTRA_CBACK_ARG(3,1)=(CELL) MkIntegerTerm((int)res_set);
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *field;
|
||||
|
||||
Term head, list, null_atom[1];
|
||||
int i, arity;
|
||||
|
||||
arity = IntegerOfTerm(arg_arity);
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
if ((row = mysql_fetch_row(res_set)) != NULL)
|
||||
{
|
||||
mysql_field_seek(res_set,0);
|
||||
list = arg_list_args;
|
||||
|
||||
for (i = 0; i < arity; i++)
|
||||
{
|
||||
/* Aqui sero feitas as converses de tipos de dados */
|
||||
field = mysql_fetch_field(res_set);
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
|
||||
if (row[i] == NULL)
|
||||
{
|
||||
null_atom[0] = MkIntegerTerm(null_id++);
|
||||
|
||||
//if (!Yap_unify(head, Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("null"),1),1,null_atom)))
|
||||
Bind(VarOfTerm(head), Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("null"),1),1,null_atom));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IS_SQL_INT(field->type))
|
||||
{
|
||||
//if (!Yap_unify(head, MkIntegerTerm(atoi(row[i])))){
|
||||
Bind(VarOfTerm(head), MkIntegerTerm(atoi(row[i])));
|
||||
continue;
|
||||
}
|
||||
else if (IS_SQL_FLOAT(field->type))
|
||||
{
|
||||
//if (!Yap_unify(head, MkFloatTerm(atof(row[i]))))
|
||||
Bind(VarOfTerm(head), MkFloatTerm(atof(row[i])));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (!Yap_unify(head, MkAtomTerm(Yap_LookupAtom(row[i]))))
|
||||
Bind(VarOfTerm(head), MkAtomTerm(Yap_LookupAtom(row[i])));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_free_result(res_set);
|
||||
cut_fail();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* db_row: ResultSet x Arity_ListOfArgs x ListOfArgs -> */
|
||||
static int
|
||||
c_db_my_row_unify(void) {
|
||||
Term arg_result_set = Deref(ARG1);
|
||||
Term arg_arity = Deref(ARG2);
|
||||
Term arg_list_args = Deref(ARG3);
|
||||
|
||||
MYSQL_RES *res_set = (MYSQL_RES *) IntegerOfTerm(arg_result_set);
|
||||
EXTRA_CBACK_ARG(3,1)=(CELL) MkIntegerTerm((int)res_set);
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *field;
|
||||
|
||||
Term head, list, null_atom[1];
|
||||
int i, arity;
|
||||
|
||||
arity = IntegerOfTerm(arg_arity);
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
if ((row = mysql_fetch_row(res_set)) != NULL)
|
||||
{
|
||||
mysql_field_seek(res_set,0);
|
||||
list = arg_list_args;
|
||||
|
||||
for (i = 0; i < arity; i++)
|
||||
{
|
||||
/* Aqui sero feitas as converses de tipos de dados */
|
||||
field = mysql_fetch_field(res_set);
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
|
||||
if (row[i] == NULL)
|
||||
{
|
||||
null_atom[0] = MkIntegerTerm(null_id++);
|
||||
|
||||
if (!Yap_unify(head, Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("null"),1),1,null_atom)))
|
||||
//Bind(VarOfTerm(head), Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("null"),1),1,null_atom));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (IS_SQL_INT(field->type))
|
||||
{
|
||||
if (!Yap_unify(head, MkIntegerTerm(atoi(row[i]))))
|
||||
//Bind(VarOfTerm(head), MkIntegerTerm(atoi(row[i])));
|
||||
continue;
|
||||
}
|
||||
else if (IS_SQL_FLOAT(field->type))
|
||||
{
|
||||
if (!Yap_unify(head, MkFloatTerm(atof(row[i]))))
|
||||
//Bind(VarOfTerm(head), MkFloatTerm(atof(row[i])));
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!Yap_unify(head, MkAtomTerm(Yap_LookupAtom(row[i]))))
|
||||
//Bind(VarOfTerm(head), MkAtomTerm(Yap_LookupAtom(row[i])));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_free_result(res_set);
|
||||
cut_fail();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* static int */
|
||||
/* c_db_my_row_term_cut(void) { */
|
||||
/* MYSQL_RES *mysql_res=NULL; */
|
||||
|
||||
/* mysql_res = (MYSQL_RES *) IntegerOfTerm(EXTRA_CBACK_CUT_ARG(Term,1)); */
|
||||
/* mysql_free_result(mysql_res); */
|
||||
/* return TRUE; */
|
||||
/* } */
|
||||
|
||||
/* /\* db_row: ResultSet x ListOfArgs -> *\/ */
|
||||
/* static int */
|
||||
/* c_db_my_row_term(void) { */
|
||||
/* Term arg_result_set = Deref(ARG1); */
|
||||
/* Term arg_functor_name = Deref(ARG2); */
|
||||
/* Term arg_term = Deref(ARG3); */
|
||||
|
||||
/* MYSQL_RES *res_set = (MYSQL_RES *) IntegerOfTerm(arg_result_set); */
|
||||
/* EXTRA_CBACK_ARG(3,1)=(CELL) MkIntegerTerm((int)res_set); */
|
||||
/* MYSQL_ROW row; */
|
||||
/* MYSQL_FIELD *field; */
|
||||
/* char *functor_name = AtomName(AtomOfTerm(arg_functor_name)); */
|
||||
/* Term null_atom[1]; */
|
||||
|
||||
/* int i, arity; */
|
||||
/* arity = mysql_num_fields(res_set); */
|
||||
|
||||
/* Functor functor = Yap_MkFunctor(Yap_LookupAtom(functor_name),arity); */
|
||||
/* Term properties[arity]; */
|
||||
|
||||
/* while(TRUE) */
|
||||
/* { */
|
||||
/* if ((row = mysql_fetch_row(res_set)) != NULL) */
|
||||
/* { */
|
||||
/* mysql_field_seek(res_set,0); */
|
||||
/* for (i = 0; i < arity; i++) */
|
||||
/* { */
|
||||
/* /\* Aqui serão feitas as conversões de tipos de dados *\/ */
|
||||
/* field = mysql_fetch_field(res_set); */
|
||||
|
||||
/* if (row[i] == NULL) */
|
||||
/* { */
|
||||
/* null_atom[0] = MkIntegerTerm(null_id++); */
|
||||
/* properties[i]= Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("null"),1),1,null_atom); */
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* if (IS_SQL_INT(field->type)) */
|
||||
/* { */
|
||||
/* properties[i]= MkIntegerTerm(atoi(row[i])); */
|
||||
/* } */
|
||||
/* else if (IS_SQL_FLOAT(field->type)) */
|
||||
/* { */
|
||||
/* properties[i]= MkFloatTerm(atof(row[i])); */
|
||||
/* } */
|
||||
/* /\* This if is for case if we have a data type */
|
||||
/* like int(11)*\/ */
|
||||
/* else if (strchr(row[i],'(') && strchr(row[i],')')) */
|
||||
/* { */
|
||||
/* char *type = strtok(row[i],"("); */
|
||||
/* char *num = strtok(NULL,")"); */
|
||||
/* Term size[1]; */
|
||||
/* size[0] = MkIntegerTerm(atoi(num)); */
|
||||
/* properties[i]= Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(type),1),1,size); */
|
||||
|
||||
/* //printf ("-->%s %s %s\n",row[i],type,num); */
|
||||
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* properties[i]= MkAtomTerm(Yap_LookupAtom(row[i])); */
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
/* if (!Yap_unify(arg_term, Yap_MkApplTerm(functor,arity,properties))){ */
|
||||
/* mysql_free_result(res_set); */
|
||||
/* cut_fail(); */
|
||||
/* return FALSE; */
|
||||
/* } */
|
||||
/* return TRUE; */
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* mysql_free_result(res_set); */
|
||||
/* cut_fail(); */
|
||||
/* return FALSE; */
|
||||
/* } */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
|
||||
|
||||
|
||||
void Yap_InitMYDDAS_testPreds(void)
|
||||
{
|
||||
|
||||
/* db_query: SQLQuery x ResultSet x Connection */
|
||||
Yap_InitCPred("c_db_my_query_result", 4, c_db_my_query_result, 0);
|
||||
/* db_query: SQLQuery x ResultSet x Connection */
|
||||
Yap_InitCPred("c_db_my_query_no_result", 2, c_db_my_query_no_result, 0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Yap_InitBackMYDDAS_testPreds(void)
|
||||
{
|
||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
||||
Yap_InitCPredBackCut("c_db_my_row_bind", 3, sizeof(int),
|
||||
c_db_my_row,
|
||||
c_db_my_row,
|
||||
c_db_my_row_cut, 0);
|
||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
||||
Yap_InitCPredBackCut("c_db_my_row_unify", 3, sizeof(int),
|
||||
c_db_my_row_unify,
|
||||
c_db_my_row_unify,
|
||||
c_db_my_row_cut, 0);
|
||||
/* /\* db_row_term: ResultSet x NameFunctor x Term *\/ */
|
||||
/* Yap_InitCPredBackCut("c_db_my_row_term", 3, sizeof(int), */
|
||||
/* c_db_my_row_term, */
|
||||
/* c_db_my_row_term, */
|
||||
/* c_db_my_row_term_cut, 0); */
|
||||
}
|
||||
|
||||
#endif /*MYDDAS_MYSQL && CUT_C*/
|
154
MYDDAS/myddas_top_level.c
Normal file
154
MYDDAS/myddas_top_level.c
Normal file
@ -0,0 +1,154 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: myddas_top_level.c *
|
||||
* Last rev: 27/01/06 *
|
||||
* mods: *
|
||||
* comments: Top Level of the MYDDAS Interface *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#if defined MYDDAS_TOP_LEVEL && defined MYDDAS_MYSQL
|
||||
|
||||
#include "Yap.h"
|
||||
#include "Yatom.h"
|
||||
#include "myddas_util.h"
|
||||
#include "myddas_structs.h"
|
||||
#include <mysql/mysql.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
//void myddas_top_level_preprocess(char *);
|
||||
STATIC_PROTO(ulong start_timer,(void));
|
||||
STATIC_PROTO(int com_quit,(char *,char*));
|
||||
STATIC_PROTO(int myddas_top_level_command,(char *,char *));
|
||||
STATIC_PROTO(int c_db_top_level,(void));
|
||||
|
||||
typedef struct {
|
||||
const char *name; /* User printable name of the function. */
|
||||
char cmd_char; /* msql command character */
|
||||
int (*func)(char *str,char *); /* Function to call to do the job. */
|
||||
//bool takes_params; /* Max parameters for command */
|
||||
const char *doc; /* Documentation for this function. */
|
||||
} COMMANDS;
|
||||
|
||||
|
||||
static COMMANDS commands[] = {
|
||||
// { "?", '?', com_help, 1, "Synonym for `help'." },
|
||||
{ "exit", 'q', com_quit, "Exit MYDDAS Top Level. Same as quit."},
|
||||
{ "quit", 'q', com_quit, "Quit MYDDAS Top Level." },
|
||||
// End of the vector
|
||||
{ (char *)NULL, 0, 0, ""}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static int
|
||||
c_db_top_level(void) {
|
||||
Term arg_conn = Deref(ARG1);
|
||||
Term arg_res_set_mode = Deref(ARG2);
|
||||
|
||||
MYSQL *con = (MYSQL *) IntegerOfTerm(arg_conn);
|
||||
char *res_set_mode = AtomName(AtomOfTerm(arg_res_set_mode));
|
||||
char *line;
|
||||
int quit;
|
||||
|
||||
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_level_connection = myddas_util_search_connection(con);
|
||||
|
||||
printf ("\n");
|
||||
for (;;) {
|
||||
/* Ignore empty lines */
|
||||
while (strlen(line = readline("mysql> ")) == 0) {
|
||||
free(line);
|
||||
}
|
||||
//myddas_top_level_preprocess(line);
|
||||
|
||||
add_history(line);
|
||||
quit = myddas_top_level_command(line,res_set_mode);
|
||||
free(line);
|
||||
if (quit == -1)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static
|
||||
ulong start_timer(void){
|
||||
struct tms tms_tmp;
|
||||
return times(&tms_tmp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* void */
|
||||
/* myddas_top_level_preprocess(char *line); */
|
||||
|
||||
static int
|
||||
myddas_top_level_command(char *line,char *res_set_mode){
|
||||
|
||||
int i;
|
||||
MYSQL *conn;
|
||||
MYSQL_RES *res_set;
|
||||
|
||||
if ( (line[0] == '#' ||
|
||||
(line[0] == '-' && line[1] == '-') ||
|
||||
line[0] == 0))
|
||||
return 0; // Skip comment lines
|
||||
|
||||
|
||||
for (i=0;commands[i].name!=NULL;i++)
|
||||
if (!strcmp(commands[i].name,line))
|
||||
{
|
||||
int quit = (*(commands[i].func))(NULL,NULL);
|
||||
if (quit == -1)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int length=strlen(line);
|
||||
|
||||
conn = (MYSQL *) (Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_level_connection->connection);
|
||||
|
||||
ulong start = start_timer();
|
||||
if (mysql_real_query(conn, line, length) != 0){
|
||||
printf ("ERROR %d (%s): %s\n",mysql_errno(conn),mysql_sqlstate(conn),mysql_error(conn));
|
||||
|
||||
}
|
||||
else{
|
||||
if (strcmp(res_set_mode,"store_result")==0) //True
|
||||
res_set = mysql_store_result(conn);
|
||||
else
|
||||
res_set = mysql_use_result(conn);
|
||||
ulong end = start_timer();
|
||||
myddas_util_table_write(res_set);
|
||||
printf ("%lld rows in set (%ld sec)\n",mysql_num_rows(res_set),end-start);
|
||||
mysql_free_result(res_set);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int com_quit(char *nill,char *null){
|
||||
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_level_connection = NULL;
|
||||
printf ("Bye\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Yap_InitMYDDAS_TopLevelPreds(void)
|
||||
{
|
||||
Yap_InitCPred("c_db_top_level", 2, c_db_top_level, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -6,10 +6,16 @@
|
||||
#include "cut_c.h"
|
||||
#include "myddas_util.h"
|
||||
#include "myddas_structs.h"
|
||||
#ifdef MYDDAS_STATS
|
||||
#include "myddas_statistics.h"
|
||||
#endif
|
||||
#include "myddas_initialization.c"
|
||||
#ifdef MYDDAS_ODBC
|
||||
#include <sql.h>
|
||||
#endif /*MYDDAS_ODBC*/
|
||||
#ifdef MYDDAS_MYSQL
|
||||
#include <mysql/mysql.h>
|
||||
#endif /*MYDDAS_MYSQL*/
|
||||
#include "Yap.h"
|
||||
|
||||
|
||||
@ -25,6 +31,11 @@ static void
|
||||
myddas_util_error_message(char *,int,char *);
|
||||
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
/* Auxilary function to table_write*/
|
||||
static void
|
||||
n_print(int , char );
|
||||
#endif
|
||||
|
||||
/* Type: MYSQL->1 ODBC->2*/
|
||||
short int
|
||||
@ -192,6 +203,14 @@ myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION con,
|
||||
con->total_number_queries = number;
|
||||
}
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
/* Auxilary function to table_write*/
|
||||
static void
|
||||
n_print(int n, char c)
|
||||
{
|
||||
for(;n>0;n--) printf("%c",c);
|
||||
}
|
||||
#endif
|
||||
|
||||
static
|
||||
void myddas_util_error_message(char *message,int line,char *file){
|
||||
@ -230,6 +249,69 @@ myddas_util_delete_predicate_list(MYDDAS_UTIL_PREDICATE preds_list){
|
||||
}
|
||||
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
void
|
||||
myddas_util_table_write(MYSQL_RES *res_set){
|
||||
|
||||
MYSQL_ROW row;
|
||||
MYSQL_FIELD *fields;
|
||||
int i,f;
|
||||
|
||||
f = mysql_num_fields(res_set);
|
||||
|
||||
fields = mysql_fetch_field(res_set);
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
if (strlen(fields[i].name)>fields[i].max_length) fields[i].max_length=strlen(fields[i].name);
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("|");
|
||||
printf(" %s ",fields[i].name);
|
||||
n_print(fields[i].max_length - strlen(fields[i].name),' ');
|
||||
}
|
||||
printf("|\n");
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
while ((row = mysql_fetch_row(res_set)) != NULL)
|
||||
{
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("|");
|
||||
if (row[i] != NULL)
|
||||
{
|
||||
printf(" %s ",row[i]);
|
||||
n_print(fields[i].max_length - strlen(row[i]),' ');
|
||||
}
|
||||
else
|
||||
{
|
||||
printf(" NULL ");
|
||||
n_print(fields[i].max_length - 4,' ');
|
||||
}
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
|
||||
for(i=0;i<f;i++)
|
||||
{
|
||||
printf("+");
|
||||
n_print(fields[i].max_length+2,'-');
|
||||
}
|
||||
printf("+\n");
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
//DELETE THIS WHEN DB_STATS IS COMPLETED
|
||||
int
|
||||
get_myddas_top(){
|
||||
|
@ -6,27 +6,39 @@
|
||||
#include <sql.h>
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
#include <mysql/mysql.h>
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
typedef struct myddas_global *MYDDAS_GLOBAL;
|
||||
#ifdef MYDDAS_STATS
|
||||
typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS;
|
||||
#endif
|
||||
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;
|
||||
|
||||
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||
typedef struct myddas_stats_time_struct *MYDDAS_STATS_TIME;
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS;
|
||||
#endif
|
||||
|
||||
MYDDAS_GLOBAL
|
||||
myddas_util_initialize_myddas(void);
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
void
|
||||
myddas_util_table_write(MYSQL_RES *);
|
||||
#endif
|
||||
|
||||
/* Returns the connection type (mysql -> 1 or odbc -> 2) */
|
||||
short int
|
||||
myddas_util_connection_type(void *);
|
||||
|
||||
/* Adds a connection identifier to the MYDDAS connections list*/
|
||||
MYDDAS_UTIL_CONNECTION
|
||||
myddas_util_add_connection(void *,void *);
|
||||
|
Reference in New Issue
Block a user