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_initialize_predicate(char *, int,char *,
|
||||||
MYDDAS_UTIL_PREDICATE);
|
MYDDAS_UTIL_PREDICATE);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
MYDDAS_GLOBAL
|
MYDDAS_GLOBAL
|
||||||
myddas_util_initialize_myddas(){
|
myddas_util_initialize_myddas(){
|
||||||
MYDDAS_GLOBAL global = NULL;
|
MYDDAS_GLOBAL global = NULL;
|
||||||
@ -15,16 +17,18 @@ myddas_util_initialize_myddas(){
|
|||||||
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
|
global = (MYDDAS_GLOBAL) malloc (sizeof(struct myddas_global));
|
||||||
|
|
||||||
global->myddas_top_connections = NULL;
|
global->myddas_top_connections = NULL;
|
||||||
|
#ifdef MYDDAS_TOP_LEVEL
|
||||||
|
global->myddas_top_level_connection = NULL;
|
||||||
|
#endif
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
global->myddas_statistics = (MYDDAS_GLOBAL_STATS) malloc (sizeof(struct myddas_global_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
|
#endif
|
||||||
return global;
|
return global;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Inserts the new node on the front of the list */
|
/* Inserts the new node on the front of the list */
|
||||||
static MYDDAS_UTIL_CONNECTION
|
static MYDDAS_UTIL_CONNECTION
|
||||||
myddas_util_initialize_connection(void *conn,void *enviromment,
|
myddas_util_initialize_connection(void *conn,void *enviromment,
|
||||||
@ -37,7 +41,6 @@ myddas_util_initialize_connection(void *conn,void *enviromment,
|
|||||||
}
|
}
|
||||||
new->predicates=NULL;
|
new->predicates=NULL;
|
||||||
new->connection=conn;
|
new->connection=conn;
|
||||||
new->temporary_tables=NULL;
|
|
||||||
new->odbc_enviromment=enviromment;
|
new->odbc_enviromment=enviromment;
|
||||||
|
|
||||||
/* It saves n queries, doing at once n+1 queries */
|
/* 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
|
#ifdef MYDDAS_STATS
|
||||||
new->totalNumberOfRows=0;
|
new->totalNumberOfRows=0;
|
||||||
new->totalTimeofDBServer=0;
|
|
||||||
new->lastTimeofDBServer=0;
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->totalTimeofDBServer,time_final);
|
||||||
new->totalFromDBServer=0;
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->lastTimeofDBServer,time_final);
|
||||||
new->lastFromDBServer=0;
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->totalFromDBServer,time_final);
|
||||||
new->total_db_row=0;
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->lastFromDBServer,time_final);
|
||||||
|
|
||||||
new->lastBytesTransfered=0;
|
new->lastBytesTransfered=0;
|
||||||
new->totalBytesTransfered=0;
|
new->totalBytesTransfered=0;
|
||||||
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(new->total_db_row,time_final);
|
||||||
new->total_querys_made=0;
|
new->total_querys_made=0;
|
||||||
#endif
|
#endif
|
||||||
return new;
|
return new;
|
||||||
@ -89,3 +94,4 @@ myddas_util_initialize_predicate(char *pred_name, int pred_arity,
|
|||||||
|
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "cut_c.h"
|
#include "cut_c.h"
|
||||||
#include "myddas_util.h"
|
#include "myddas_util.h"
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
|
#include "myddas_structs.h"
|
||||||
#include "myddas_statistics.h"
|
#include "myddas_statistics.h"
|
||||||
#endif
|
#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_get_fields_properties,(void));
|
||||||
STATIC_PROTO(int c_db_my_number_of_fields_in_query,(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_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);
|
||||||
|
|
||||||
|
|
||||||
static void n_print(int, char);
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
static int
|
||||||
c_db_my_connect(void) {
|
c_db_my_connect(void) {
|
||||||
@ -121,13 +169,14 @@ c_db_my_query(void) {
|
|||||||
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
MYDDAS_UTIL_CONNECTION node = myddas_util_search_connection(conn);
|
||||||
|
|
||||||
/* Count the number of querys made to the server */
|
/* Count the number of querys made to the server */
|
||||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
unsigned long number_querys;
|
||||||
myddas_util_set_conn_number_querys_made(node,++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
|
/* Measure time spent by the MySQL Server
|
||||||
processing the SQL Query */
|
processing the SQL Query */
|
||||||
unsigned long start,end,total_time,last_time;
|
MYDDAS_STATS_TIME start,end,total_time,diff;
|
||||||
start = myddas_current_time();
|
start = myddas_stats_walltime();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* executar a query SQL */
|
/* executar a query SQL */
|
||||||
@ -142,13 +191,21 @@ c_db_my_query(void) {
|
|||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
/* Measure time spent by the MySQL Server
|
/* Measure time spent by the MySQL Server
|
||||||
processing the SQL Query */
|
processing the SQL Query */
|
||||||
end = myddas_current_time();
|
end = myddas_stats_walltime();
|
||||||
|
|
||||||
last_time = (end-start);
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||||
total_time = last_time + myddas_util_get_conn_total_time_DBServer(node);
|
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);
|
free(end);
|
||||||
myddas_util_set_conn_total_time_DBServer(node,total_time);
|
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
|
#endif
|
||||||
|
|
||||||
/* guardar os tuplos do lado do cliente */
|
/* guardar os tuplos do lado do cliente */
|
||||||
@ -160,33 +217,42 @@ c_db_my_query(void) {
|
|||||||
/* Measure time spent by the MySQL Server
|
/* 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 */
|
back to the client */
|
||||||
start = myddas_current_time();
|
start = myddas_stats_walltime();
|
||||||
#endif
|
#endif
|
||||||
res_set = mysql_store_result(conn);
|
res_set = mysql_store_result(conn);
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
/* Measure time spent by the MySQL Server
|
/* 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 */
|
back to the client */
|
||||||
end = myddas_current_time();
|
end = myddas_stats_walltime();
|
||||||
|
|
||||||
node = myddas_util_search_connection(conn);
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||||
last_time = (end-start);
|
myddas_stats_subtract_time(diff,end,start);
|
||||||
total_time = last_time + myddas_util_get_conn_total_transfering_from_DBServer(node);
|
diff = myddas_stats_time_copy_to_final(diff);
|
||||||
|
|
||||||
myddas_util_set_conn_last_transfering_from_DBServer(node,last_time);
|
free(end);
|
||||||
myddas_util_set_conn_total_transfering_from_DBServer(node,total_time);
|
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 */
|
/* Measure the number of Rows returned from the server */
|
||||||
if (res_set != NULL)
|
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*/
|
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);
|
unsigned long numberRows = mysql_num_rows(res_set);
|
||||||
numberRows = numberRows + myddas_util_get_conn_total_rows(node);
|
unsigned long rows;
|
||||||
myddas_util_set_conn_total_rows(node,numberRows);
|
|
||||||
|
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 */
|
/* 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);
|
||||||
@ -201,9 +267,12 @@ c_db_my_query(void) {
|
|||||||
total = total + strlen(row[i]);
|
total = total + strlen(row[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
myddas_util_set_conn_last_bytes_transfering_from_DBserver(node,total);
|
MYDDAS_STATS_CON_SET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node,total);
|
||||||
total = total + myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
unsigned long bytes;
|
||||||
myddas_util_set_conn_total_bytes_transfering_from_DBserver(node,total);
|
|
||||||
|
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);
|
mysql_data_seek(res_set,0);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -354,74 +423,13 @@ c_db_my_table_write(void) {
|
|||||||
Term arg_res_set = Deref(ARG1);
|
Term arg_res_set = Deref(ARG1);
|
||||||
|
|
||||||
MYSQL_RES *res_set = (MYSQL_RES *) IntegerOfTerm(arg_res_set);
|
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);
|
mysql_free_result(res_set);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auxilary function to table_write*/
|
|
||||||
static void
|
|
||||||
n_print(int n, char c)
|
|
||||||
{
|
|
||||||
for(;n>0;n--) printf("%c",c);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
c_db_my_row_cut(void) {
|
c_db_my_row_cut(void) {
|
||||||
MYSQL_RES *mysql_res=NULL;
|
MYSQL_RES *mysql_res=NULL;
|
||||||
@ -437,8 +445,8 @@ c_db_my_row(void) {
|
|||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
/* Measure time used by the
|
/* Measure time used by the
|
||||||
c_db_my_row function */
|
c_db_my_row function */
|
||||||
unsigned long start,end,total_time,last_time;
|
MYDDAS_STATS_TIME start,end,total_time,diff;
|
||||||
start = myddas_current_time();
|
start = myddas_stats_walltime();
|
||||||
#endif
|
#endif
|
||||||
Term arg_result_set = Deref(ARG1);
|
Term arg_result_set = Deref(ARG1);
|
||||||
Term arg_arity = Deref(ARG2);
|
Term arg_arity = Deref(ARG2);
|
||||||
@ -496,12 +504,19 @@ c_db_my_row(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
end = myddas_current_time();
|
end = myddas_stats_walltime();
|
||||||
|
|
||||||
last_time = (end-start);
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||||
total_time = last_time + myddas_util_get_total_db_row_function();
|
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 */
|
#endif /* MYDDAS_STATS */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -510,12 +525,19 @@ c_db_my_row(void) {
|
|||||||
mysql_free_result(res_set);
|
mysql_free_result(res_set);
|
||||||
cut_fail();
|
cut_fail();
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
end = myddas_current_time();
|
end = myddas_stats_walltime();
|
||||||
|
|
||||||
last_time = (end-start);
|
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff,time_copy);
|
||||||
total_time = last_time + myddas_util_get_total_db_row_function();
|
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 */
|
#endif /* MYDDAS_STATS */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -656,44 +678,32 @@ c_db_my_get_next_result_set(void) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_InitMYDDAS_MySQLPreds(void)
|
static int
|
||||||
{
|
c_db_my_get_database(void) {
|
||||||
/* db_connect: Host x User x Passwd x Database x Connection x ERROR_CODE */
|
Term arg_con = Deref(ARG1);
|
||||||
Yap_InitCPred("c_db_my_connect", 5, c_db_my_connect, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Term arg_database = Deref(ARG2);
|
||||||
|
|
||||||
/* db_number_of_fields: Relation x Connection x NumberOfFields */
|
MYSQL *con = (MYSQL *) (IntegerOfTerm(arg_con));
|
||||||
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 */
|
if (!Yap_unify(arg_database,MkAtomTerm(Yap_LookupAtom(con->db))))
|
||||||
Yap_InitCPred("c_db_my_number_of_fields_in_query",3, c_db_my_number_of_fields_in_query, 0);
|
return FALSE;
|
||||||
|
|
||||||
/* db_get_attributes_types: Relation x TypesList */
|
return TRUE;
|
||||||
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)
|
static int
|
||||||
{
|
c_db_my_change_database(void) {
|
||||||
/* db_row: ResultSet x Arity x ListOfArgs */
|
Term arg_con = Deref(ARG1);
|
||||||
Yap_InitCPredBackCut("c_db_my_row", 3, sizeof(int),
|
Term arg_database = Deref(ARG2);
|
||||||
c_db_my_row,
|
|
||||||
c_db_my_row,
|
|
||||||
c_db_my_row_cut, 0);
|
|
||||||
|
|
||||||
|
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*/
|
#endif /*MYDDAS_MYSQL && CUT_C*/
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "myddas_util.h"
|
#include "myddas_util.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
|
#include "myddas_structs.h"
|
||||||
#include "myddas_statistics.h"
|
#include "myddas_statistics.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -253,94 +254,112 @@ c_db_stats(void) {
|
|||||||
Term head, list;
|
Term head, list;
|
||||||
list = arg_list;
|
list = arg_list;
|
||||||
|
|
||||||
|
MYDDAS_STATS_TIME time;
|
||||||
|
unsigned long number;
|
||||||
|
|
||||||
|
|
||||||
//[Index 1] -> Total Number of Rows by connection
|
//[Index 1] -> Total Number of Rows by connection
|
||||||
//Total number of Rows returned by the server
|
//Total number of Rows returned by the server
|
||||||
//WARNING: only works with store_result
|
//WARNING: only works with store_result
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long totalRows = myddas_util_get_conn_total_rows(node);
|
MYDDAS_STATS_CON_GET_TOTAL_ROWS(node,number);
|
||||||
Yap_unify(head, MkIntegerTerm(totalRows));
|
Yap_unify(head, MkIntegerTerm(number));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 2] -> Total of Time Spent by the DB Server
|
//[Index 2] -> Total of Time Spent by the DB Server
|
||||||
// processing all the SQL Querys
|
// processing all the SQL Querys
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long totalTimeDBServer = myddas_util_get_conn_total_time_DBServer(node);
|
MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(node,time);
|
||||||
Yap_unify(head, MkIntegerTerm(totalTimeDBServer));
|
Yap_unify(head, MkIntegerTerm((int)time));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 3] -> Total of Time Spent by the DB Server
|
//[Index 3] -> Total of Time Spent by the DB Server
|
||||||
// processing a the last SQL Query
|
// processing a the last SQL Query
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long lastTimeDBServer = myddas_util_get_conn_last_time_DBServer(node);
|
MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(node,time);
|
||||||
Yap_unify(head, MkIntegerTerm(lastTimeDBServer));
|
Yap_unify(head, MkIntegerTerm((int)time));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 4] -> Total of Time Spent by the DB Server
|
//[Index 4] -> Total of Time Spent by the DB Server
|
||||||
// transfering all the results of the SQL Querys
|
// transfering all the results of the SQL Querys
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long totalFromDBServer = myddas_util_get_conn_total_transfering_from_DBServer(node);
|
MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(node,time);
|
||||||
Yap_unify(head, MkIntegerTerm(totalFromDBServer));
|
Yap_unify(head, MkIntegerTerm((int)time));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 5] -> Total of Time Spent by the DB Server
|
//[Index 5] -> Total of Time Spent by the DB Server
|
||||||
// transfering the result of the last SQL Query
|
// transfering the result of the last SQL Query
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long lastFromDBServer = myddas_util_get_conn_last_transfering_from_DBServer(node);
|
MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(node,time);
|
||||||
Yap_unify(head, MkIntegerTerm(lastFromDBServer));
|
Yap_unify(head, MkIntegerTerm((int)time));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 6] -> Total of Time Spent by the
|
//[Index 6] -> Total of Time Spent by the
|
||||||
// db_row_function
|
// db_row_function
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long db_row = myddas_util_get_total_db_row_function();
|
MYDDAS_STATS_GET_DB_ROW_FUNCTION(time);
|
||||||
Yap_unify(head, MkIntegerTerm(db_row));
|
Yap_unify(head, MkIntegerTerm((int)time));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 7] -> Total of Bytes Transfered by the
|
//[Index 7] -> Total of Bytes Transfered by the
|
||||||
// DB Server on all SQL Querys
|
// DB Server on all SQL Querys
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long totalBytes = myddas_util_get_conn_total_bytes_transfering_from_DBserver(node);
|
MYDDAS_STATS_CON_GET_TOTAL_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
||||||
Yap_unify(head, MkIntegerTerm(totalBytes));
|
Yap_unify(head, MkIntegerTerm(number));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 8] -> Total of Bytes Transfered by the
|
//[Index 8] -> Total of Bytes Transfered by the
|
||||||
// DB Server on the last SQL Query
|
// DB Server on the last SQL Query
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long lastBytes = myddas_util_get_conn_last_bytes_transfering_from_DBserver(node);
|
MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(node,number);
|
||||||
Yap_unify(head, MkIntegerTerm(lastBytes));
|
Yap_unify(head, MkIntegerTerm(number));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
//[Index 9] -> Number of querys made to the DBserver
|
//[Index 9] -> Number of querys made to the DBserver
|
||||||
head = HeadOfTerm(list);
|
head = HeadOfTerm(list);
|
||||||
list = TailOfTerm(list);
|
list = TailOfTerm(list);
|
||||||
unsigned long number_querys = myddas_util_get_conn_number_querys_made(node);
|
MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(node,number);
|
||||||
Yap_unify(head, MkIntegerTerm(number_querys));
|
Yap_unify(head, MkIntegerTerm(number));
|
||||||
#ifdef DEBUG
|
#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
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
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
|
#ifdef CUT_C
|
||||||
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL
|
#if defined MYDDAS_ODBC || defined MYDDAS_MYSQL
|
||||||
|
|
||||||
|
|
||||||
#include "myddas_structs.h"
|
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||||
#include "myddas_statistics.h"
|
static void
|
||||||
#include "Yap.h"
|
myddas_stats_time_subtract (unsigned long *, unsigned long *, MYDDAS_STATS_TIME, MYDDAS_STATS_TIME);
|
||||||
|
static void
|
||||||
#ifdef MYDDAS_STATS
|
myddas_stats_add_seconds_time(MYDDAS_STATS_TIME,unsigned long, unsigned long);
|
||||||
int
|
static void
|
||||||
myddas_util_get_conn_total_rows(MYDDAS_UTIL_CONNECTION node){
|
myddas_stats_integrity_of_time(MYDDAS_STATS_TIME);
|
||||||
return node->totalNumberOfRows;
|
#endif
|
||||||
}
|
|
||||||
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
|
/* Documentation: Time Units
|
||||||
myddas_current_time(void) {
|
------------------------------------------------------------------------
|
||||||
/* to get time as Yap */
|
*****| 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 |
|
||||||
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
Int now, interval;
|
------
|
||||||
//Yap_cputime_interval(&now, &interval);
|
|
||||||
|
|
||||||
//milliseconds
|
The struct timeval structure represents an elapsed time. It is
|
||||||
Yap_walltime_interval(&now, &interval);
|
declared in `sys/time.h' and has the following members:
|
||||||
//return ((realtime)now);
|
|
||||||
return (now);
|
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.
|
||||||
|
|
||||||
/*Fine grained time
|
|
||||||
tv_usec -> microseconds [0-999999]
|
|
||||||
*/
|
*/
|
||||||
/*Fine grained time
|
|
||||||
sec -> [0-999]
|
#if defined MYDDAS_STATS || defined MYDDAS_TOP_LEVEL
|
||||||
tv_usec -> microseconds [0-99999] -> last digit is negleted
|
|
||||||
-> max execution time: 16minutes
|
|
||||||
milliseconds -> s/1000
|
/* Be shore to delete MYDDAS_STATS_TIME structure */
|
||||||
microseconds -> s/1000000
|
MYDDAS_STATS_TIME
|
||||||
*/
|
myddas_stats_walltime(void) {
|
||||||
/* struct timeval tempo; */
|
|
||||||
/* if (!gettimeofday(&tempo, NULL)) */
|
MYDDAS_STATS_TIME myddas_time;
|
||||||
/* //returns time in microseconds */
|
myddas_time = (MYDDAS_STATS_TIME) malloc (sizeof(struct timeval));
|
||||||
/* return (tempo.tv_sec %1000)*1000000+tempo.tv_usec; */
|
myddas_time->type = time_copy;
|
||||||
/* //return (tempo.tv_sec %1000)*1000+tempo.tv_usec; */
|
|
||||||
return 0;
|
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_stats_add_time(MYDDAS_STATS_TIME sum, MYDDAS_STATS_TIME time1,MYDDAS_STATS_TIME time2){
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* MYDDAS_STATS */
|
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);
|
||||||
|
|
||||||
|
result->u.time_copy.tv_sec = sec;
|
||||||
|
result->u.time_copy.tv_usec = usec;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
#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
|
#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
|
#define MYDDAS_STATS_CON_GET_TOTAL_ROWS(NODE,NUMBER) \
|
||||||
myddas_util_get_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION);
|
NUMBER = NODE->totalNumberOfRows;
|
||||||
void
|
#define MYDDAS_STATS_CON_SET_TOTAL_ROWS(NODE,NUMBER) \
|
||||||
myddas_util_set_conn_total_time_DBServer(MYDDAS_UTIL_CONNECTION,unsigned long);
|
NODE->totalNumberOfRows = NUMBER;
|
||||||
|
|
||||||
unsigned long
|
#define MYDDAS_STATS_CON_GET_TOTAL_TIME_DBSERVER(NODE,TIME) \
|
||||||
myddas_util_get_conn_last_time_DBServer(MYDDAS_UTIL_CONNECTION);
|
TIME = NODE->totalTimeofDBServer;
|
||||||
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
|
#define MYDDAS_STATS_CON_GET_LAST_TIME_DBSERVER(NODE,TIME) \
|
||||||
myddas_util_get_conn_last_transfering_from_DBServer(MYDDAS_UTIL_CONNECTION);
|
TIME = NODE->lastTimeofDBServer;
|
||||||
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
|
#define MYDDAS_STATS_CON_GET_TOTAL_TIME_TRANSFERING(NODE,TIME) \
|
||||||
myddas_util_get_conn_last_bytes_transfering_from_DBserver(MYDDAS_UTIL_CONNECTION);
|
TIME = NODE->totalFromDBServer;
|
||||||
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
|
#define MYDDAS_STATS_CON_GET_LAST_TIME_TRANSFERING(NODE,TIME) \
|
||||||
myddas_util_get_conn_number_querys_made(MYDDAS_UTIL_CONNECTION);
|
TIME = NODE->lastFromDBServer;
|
||||||
void
|
|
||||||
myddas_util_set_conn_number_querys_made(MYDDAS_UTIL_CONNECTION, unsigned long);
|
|
||||||
|
|
||||||
unsigned long
|
#define MYDDAS_STATS_CON_GET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||||
myddas_util_get_total_db_row_function(void);
|
NUMBER = NODE->lastBytesTransfered;
|
||||||
void
|
#define MYDDAS_STATS_CON_SET_LAST_BYTES_TRANSFERING_FROM_DBSERVER(NODE,NUMBER) \
|
||||||
myddas_util_set_total_db_row_function(unsigned long);
|
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
|
#define MYDDAS_STATS_CON_GET_NUMBER_QUERIES_MADE(NODE,NUMBER) \
|
||||||
myddas_current_time(void);
|
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 /* MYDDAS_STATS */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
@ -5,26 +5,18 @@
|
|||||||
|
|
||||||
struct myddas_global {
|
struct myddas_global {
|
||||||
MYDDAS_UTIL_CONNECTION myddas_top_connections;
|
MYDDAS_UTIL_CONNECTION myddas_top_connections;
|
||||||
|
#ifdef MYDDAS_TOP_LEVEL
|
||||||
|
MYDDAS_UTIL_CONNECTION myddas_top_level_connection;
|
||||||
|
#endif
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
MYDDAS_GLOBAL_STATS myddas_statistics;
|
MYDDAS_GLOBAL_STATS myddas_statistics;
|
||||||
#endif
|
#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
|
#ifdef MYDDAS_STATS
|
||||||
/* This strucuture holds some global statistics*/
|
/* This strucuture holds some global statistics*/
|
||||||
struct myddas_global_stats {
|
struct myddas_global_stats {
|
||||||
unsigned long total_db_row;
|
MYDDAS_STATS_TIME total_db_row;
|
||||||
};
|
};
|
||||||
#endif /* MYDDAS_STATS */
|
#endif /* MYDDAS_STATS */
|
||||||
|
|
||||||
@ -38,7 +30,6 @@ struct myddas_list_preds {
|
|||||||
|
|
||||||
struct myddas_list_connection {
|
struct myddas_list_connection {
|
||||||
void *connection;
|
void *connection;
|
||||||
MYDDAS_TEMP_TABLES temporary_tables;
|
|
||||||
|
|
||||||
/*If variable env is NULL, then it's a
|
/*If variable env is NULL, then it's a
|
||||||
MySQL connection, if not then it as the pointer
|
MySQL connection, if not then it as the pointer
|
||||||
@ -50,17 +41,17 @@ struct myddas_list_connection {
|
|||||||
|
|
||||||
/* Total Time spent by the DataBase Server
|
/* Total Time spent by the DataBase Server
|
||||||
processing all querys */
|
processing all querys */
|
||||||
unsigned long totalTimeofDBServer;
|
MYDDAS_STATS_TIME totalTimeofDBServer;
|
||||||
/* Time spent by the DataBase Server, processing
|
/* Time spent by the DataBase Server, processing
|
||||||
the last query */
|
the last query */
|
||||||
unsigned long lastTimeofDBServer;
|
MYDDAS_STATS_TIME lastTimeofDBServer;
|
||||||
|
|
||||||
/* Total Time spent by the DataBase Server,
|
/* Total Time spent by the DataBase Server,
|
||||||
transfering all the data to the client */
|
transfering all the data to the client */
|
||||||
unsigned long totalFromDBServer;
|
MYDDAS_STATS_TIME totalFromDBServer;
|
||||||
/* Time spent by the DataBase Server,
|
/* Time spent by the DataBase Server,
|
||||||
transfering the data of the last query */
|
transfering the data of the last query */
|
||||||
unsigned long lastFromDBServer;
|
MYDDAS_STATS_TIME lastFromDBServer;
|
||||||
|
|
||||||
/* Last bytes transfered from the server */
|
/* Last bytes transfered from the server */
|
||||||
unsigned long totalBytesTransfered;
|
unsigned long totalBytesTransfered;
|
||||||
@ -68,8 +59,9 @@ struct myddas_list_connection {
|
|||||||
unsigned long lastBytesTransfered;
|
unsigned long lastBytesTransfered;
|
||||||
|
|
||||||
/* Total Time spent on the db_row function */
|
/* 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;
|
unsigned long total_querys_made;
|
||||||
#endif
|
#endif
|
||||||
MYDDAS_UTIL_PREDICATE predicates;
|
MYDDAS_UTIL_PREDICATE predicates;
|
||||||
@ -79,6 +71,7 @@ struct myddas_list_connection {
|
|||||||
unsigned long actual_number_queries;
|
unsigned long actual_number_queries;
|
||||||
MYDDAS_UTIL_QUERY *queries;
|
MYDDAS_UTIL_QUERY *queries;
|
||||||
|
|
||||||
|
/* List Integrety */
|
||||||
MYDDAS_UTIL_CONNECTION next;
|
MYDDAS_UTIL_CONNECTION next;
|
||||||
MYDDAS_UTIL_CONNECTION previous;
|
MYDDAS_UTIL_CONNECTION previous;
|
||||||
};
|
};
|
||||||
@ -88,4 +81,26 @@ struct myddas_util_query{
|
|||||||
MYDDAS_UTIL_QUERY next;
|
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
|
#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 "cut_c.h"
|
||||||
#include "myddas_util.h"
|
#include "myddas_util.h"
|
||||||
#include "myddas_structs.h"
|
#include "myddas_structs.h"
|
||||||
|
#ifdef MYDDAS_STATS
|
||||||
|
#include "myddas_statistics.h"
|
||||||
|
#endif
|
||||||
#include "myddas_initialization.c"
|
#include "myddas_initialization.c"
|
||||||
#ifdef MYDDAS_ODBC
|
#ifdef MYDDAS_ODBC
|
||||||
#include <sql.h>
|
#include <sql.h>
|
||||||
#endif /*MYDDAS_ODBC*/
|
#endif /*MYDDAS_ODBC*/
|
||||||
|
#ifdef MYDDAS_MYSQL
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
#endif /*MYDDAS_MYSQL*/
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
|
|
||||||
|
|
||||||
@ -25,6 +31,11 @@ static void
|
|||||||
myddas_util_error_message(char *,int,char *);
|
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*/
|
/* Type: MYSQL->1 ODBC->2*/
|
||||||
short int
|
short int
|
||||||
@ -192,6 +203,14 @@ myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION con,
|
|||||||
con->total_number_queries = number;
|
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
|
static
|
||||||
void myddas_util_error_message(char *message,int line,char *file){
|
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
|
//DELETE THIS WHEN DB_STATS IS COMPLETED
|
||||||
int
|
int
|
||||||
get_myddas_top(){
|
get_myddas_top(){
|
||||||
|
@ -6,27 +6,39 @@
|
|||||||
#include <sql.h>
|
#include <sql.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MYDDAS_MYSQL
|
||||||
|
#include <mysql/mysql.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MYDDAS_STATS
|
#ifdef MYDDAS_STATS
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct myddas_global *MYDDAS_GLOBAL;
|
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_util_query *MYDDAS_UTIL_QUERY;
|
||||||
typedef struct myddas_list_connection *MYDDAS_UTIL_CONNECTION;
|
typedef struct myddas_list_connection *MYDDAS_UTIL_CONNECTION;
|
||||||
typedef struct myddas_list_preds *MYDDAS_UTIL_PREDICATE;
|
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_GLOBAL
|
||||||
myddas_util_initialize_myddas(void);
|
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) */
|
/* Returns the connection type (mysql -> 1 or odbc -> 2) */
|
||||||
short int
|
short int
|
||||||
myddas_util_connection_type(void *);
|
myddas_util_connection_type(void *);
|
||||||
|
|
||||||
/* Adds a connection identifier to the MYDDAS connections list*/
|
/* Adds a connection identifier to the MYDDAS connections list*/
|
||||||
MYDDAS_UTIL_CONNECTION
|
MYDDAS_UTIL_CONNECTION
|
||||||
myddas_util_add_connection(void *,void *);
|
myddas_util_add_connection(void *,void *);
|
||||||
|
Reference in New Issue
Block a user