MYDDAS: New functionalitys to the MYDDAS system
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1541 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
302495f6c4
commit
bc82175e5e
@ -311,7 +311,7 @@ c_db_my_number_of_fields(void) {
|
|||||||
|
|
||||||
MYSQL_RES *res_set;
|
MYSQL_RES *res_set;
|
||||||
|
|
||||||
sprintf(sql,"DESCRIBE %s",relation);
|
sprintf(sql,"DESCRIBE `%s`",relation);
|
||||||
|
|
||||||
/* executar a query SQL */
|
/* executar a query SQL */
|
||||||
if (mysql_query(conn, sql) != 0)
|
if (mysql_query(conn, sql) != 0)
|
||||||
@ -356,7 +356,7 @@ c_db_my_get_attributes_types(void) {
|
|||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
Term head, list;
|
Term head, list;
|
||||||
|
|
||||||
sprintf(sql,"DESCRIBE %s",relation);
|
sprintf(sql,"DESCRIBE `%s`",relation);
|
||||||
|
|
||||||
/* executar a query SQL */
|
/* executar a query SQL */
|
||||||
if (mysql_query(conn, sql) != 0)
|
if (mysql_query(conn, sql) != 0)
|
||||||
@ -598,10 +598,10 @@ c_db_my_get_fields_properties(void) {
|
|||||||
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
|
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
|
||||||
|
|
||||||
|
|
||||||
/* 1=2 -> We only need the meta information about the fields
|
/* LIMIT 0 -> We only need the meta information about the fields
|
||||||
to know their properties, we don't need the results of the
|
to know their properties, we don't need the results of the
|
||||||
query*/
|
query*/
|
||||||
sprintf (sql,"SELECT * FROM %s where 1=2",relacao);
|
sprintf (sql,"SELECT * FROM `%s` LIMIT 0",relacao);
|
||||||
|
|
||||||
/* executar a query SQL */
|
/* executar a query SQL */
|
||||||
if (mysql_query(conn, sql) != 0)
|
if (mysql_query(conn, sql) != 0)
|
||||||
|
@ -624,9 +624,9 @@ c_db_odbc_get_fields_properties(void) {
|
|||||||
SQLHDBC hdbc =(SQLHDBC) (IntegerOfTerm(arg_conn));
|
SQLHDBC hdbc =(SQLHDBC) (IntegerOfTerm(arg_conn));
|
||||||
|
|
||||||
|
|
||||||
/* 1=2 -> We don't need the results of the query,
|
/* LIMIT 0 -> We don't need the results of the query,
|
||||||
only the information about the fields of the relation*/
|
only the information about the fields of the relation*/
|
||||||
sprintf (sql,"SELECT * FROM %s where 1=2",relacao);
|
sprintf (sql,"SELECT * FROM `%s` LIMIT 0",relacao);
|
||||||
|
|
||||||
/*Allocate an handle for the query*/
|
/*Allocate an handle for the query*/
|
||||||
SQLALLOCHANDLE(SQL_HANDLE_STMT, hdbc, &hstmt, "db_get_fields_properties");
|
SQLALLOCHANDLE(SQL_HANDLE_STMT, hdbc, &hstmt, "db_get_fields_properties");
|
||||||
|
@ -27,11 +27,13 @@
|
|||||||
#include "myddas_statistics.h"
|
#include "myddas_statistics.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
STATIC_PROTO(int c_db_get_new_table_name,(void));
|
//STATIC_PROTO(int c_db_get_new_table_name,(void));
|
||||||
STATIC_PROTO(int c_db_connection_type,(void));
|
STATIC_PROTO(int c_db_connection_type,(void));
|
||||||
STATIC_PROTO(int c_db_add_preds,(void));
|
STATIC_PROTO(int c_db_add_preds,(void));
|
||||||
STATIC_PROTO(int c_db_preds_conn_start ,(void));
|
STATIC_PROTO(int c_db_preds_conn_start ,(void));
|
||||||
STATIC_PROTO(int c_db_preds_conn_continue ,(void));
|
STATIC_PROTO(int c_db_preds_conn_continue ,(void));
|
||||||
|
STATIC_PROTO(int c_db_connection_start ,(void));
|
||||||
|
STATIC_PROTO(int c_db_connection_continue ,(void));
|
||||||
STATIC_PROTO(int c_db_check_if_exists_pred,(void));
|
STATIC_PROTO(int c_db_check_if_exists_pred,(void));
|
||||||
STATIC_PROTO(int c_db_delete_predicate,(void));
|
STATIC_PROTO(int c_db_delete_predicate,(void));
|
||||||
STATIC_PROTO(int c_db_multi_queries_number,(void));
|
STATIC_PROTO(int c_db_multi_queries_number,(void));
|
||||||
@ -42,23 +44,46 @@ STATIC_PROTO(int c_db_stats,(void));
|
|||||||
STATIC_PROTO(int c_db_check,(void));
|
STATIC_PROTO(int c_db_check,(void));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* c_db_get_new_table_name: -TableName */
|
void Yap_InitMYDDAS_SharedPreds(void)
|
||||||
static int
|
{
|
||||||
c_db_get_new_table_name (void){
|
/* c_db_connection_type: Connection x Type */
|
||||||
/* Term arg_con = Deref(ARG1); */
|
Yap_InitCPred("c_db_connection_type",2,c_db_connection_type, 0);
|
||||||
/* Term arg_name = Deref(ARG2); */
|
|
||||||
|
|
||||||
/* int *con = (int *) IntegerOfTerm(arg_con); */
|
|
||||||
/* char *tableName = myddas_util_get_table_name(con); */
|
|
||||||
|
|
||||||
/* Yap_unify(arg_name, MkAtomTerm(Yap_LookupAtom(tableName))); */
|
|
||||||
|
|
||||||
/* free(tableName); */
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* CORRECT THIS: db_add_preds : PredName * Arity * Connection */
|
||||||
|
Yap_InitCPred("c_db_add_preds",4,c_db_add_preds, 0);
|
||||||
|
|
||||||
|
/* c_db_check_if_exists_pred : PredName * Arity * Connection */
|
||||||
|
Yap_InitCPred("c_db_check_if_exists_pred",3,c_db_check_if_exists_pred, 0);
|
||||||
|
|
||||||
|
/* c_db_delete_pred : Module * PredName * Arity */
|
||||||
|
Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0);
|
||||||
|
|
||||||
|
/* c_db_delete_pred : Module * PredName * Arity */
|
||||||
|
Yap_InitCPred("c_db_multi_queries_number",2,c_db_multi_queries_number, 0);
|
||||||
|
|
||||||
|
#ifdef MYDDAS_STATS
|
||||||
|
/* db_stats: Connection * Stats*/
|
||||||
|
Yap_InitCPred("c_db_stats",2, c_db_stats, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
Yap_InitCPred("c_db_check",0, c_db_check, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Yap_InitBackMYDDAS_SharedPreds(void)
|
||||||
|
{
|
||||||
|
/* Gives all the predicates associated to a given connection */
|
||||||
|
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(int),
|
||||||
|
c_db_preds_conn_start,
|
||||||
|
c_db_preds_conn_continue, 0);
|
||||||
|
/* Gives all the connections stored on the MYDDAS Structure*/
|
||||||
|
Yap_InitCPredBack("c_db_connection", 1, sizeof(int),
|
||||||
|
c_db_connection_start,
|
||||||
|
c_db_connection_continue, 0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Gives the type of a given connection,
|
/* Gives the type of a given connection,
|
||||||
in other words, type will be mysql or odbc
|
in other words, type will be mysql or odbc
|
||||||
@ -99,7 +124,7 @@ c_db_add_preds (void){
|
|||||||
if (myddas_util_add_predicate(nome,aridade,module,conn) == NULL)
|
if (myddas_util_add_predicate(nome,aridade,module,conn) == NULL)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf ("ERRO : Nao consegui adicionar predicado\n");
|
printf ("ERROR : Could not add Predicate: Line: %d File: %s\n",__LINE__,__FILE__);
|
||||||
#endif
|
#endif
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -170,14 +195,44 @@ c_db_multi_queries_number(void){
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
c_db_connection_start(void){
|
||||||
|
|
||||||
|
MYDDAS_UTIL_CONNECTION node =
|
||||||
|
Yap_regp->MYDDAS_GLOBAL_POINTER->myddas_top_connections;
|
||||||
|
|
||||||
|
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((int)node);
|
||||||
|
|
||||||
|
return (c_db_connection_continue());
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
c_db_connection_continue(void){
|
||||||
|
Term arg_conn = Deref(ARG1);
|
||||||
|
|
||||||
|
MYDDAS_UTIL_CONNECTION node;
|
||||||
|
node = (MYDDAS_UTIL_CONNECTION) IntegerOfTerm(EXTRA_CBACK_ARG(1,1));
|
||||||
|
|
||||||
|
/* There is no connections */
|
||||||
|
if (node == NULL)
|
||||||
|
{
|
||||||
|
cut_fail();
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Yap_unify(arg_conn, MkIntegerTerm((int)(node->connection)));
|
||||||
|
EXTRA_CBACK_ARG(1,1)=(CELL) MkIntegerTerm((int)(node->next));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
|
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity */
|
||||||
static int
|
static int
|
||||||
c_db_preds_conn_start (void){
|
c_db_preds_conn_start (void){
|
||||||
Term arg_conn = Deref(ARG1);
|
Term arg_conn = Deref(ARG1);
|
||||||
Term module = Deref(ARG2);
|
|
||||||
Term nome = Deref(ARG3);
|
|
||||||
Term aridade = Deref(ARG4);
|
|
||||||
|
|
||||||
int *conn = (int *) IntegerOfTerm(arg_conn);
|
int *conn = (int *) IntegerOfTerm(arg_conn);
|
||||||
MYDDAS_UTIL_CONNECTION node =
|
MYDDAS_UTIL_CONNECTION node =
|
||||||
myddas_util_search_connection(conn);
|
myddas_util_search_connection(conn);
|
||||||
@ -192,30 +247,32 @@ c_db_preds_conn_start (void){
|
|||||||
void *pointer = myddas_util_get_list_pred(node);
|
void *pointer = myddas_util_get_list_pred(node);
|
||||||
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((int)pointer);
|
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((int)pointer);
|
||||||
|
|
||||||
if (IsVarTerm(nome) && IsVarTerm(aridade) && IsVarTerm(module))
|
return (c_db_preds_conn_continue());
|
||||||
return (c_db_preds_conn_continue());
|
|
||||||
|
|
||||||
cut_fail();
|
|
||||||
return FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/
|
/* db_preds_conn : Connection(+) * Pred_name(-) * Pred_arity*/
|
||||||
static int
|
static int
|
||||||
c_db_preds_conn_continue (void){
|
c_db_preds_conn_continue (void){
|
||||||
Term module = Deref(ARG2);
|
Term module = Deref(ARG2);
|
||||||
Term nome = Deref(ARG3);
|
Term name = Deref(ARG3);
|
||||||
Term aridade = Deref(ARG4);
|
Term arity = Deref(ARG4);
|
||||||
|
|
||||||
void *pointer;
|
void *pointer;
|
||||||
pointer = (void *) IntegerOfTerm(EXTRA_CBACK_ARG(4,1));
|
pointer = (void *) IntegerOfTerm(EXTRA_CBACK_ARG(4,1));
|
||||||
|
|
||||||
if (pointer != NULL)
|
if (pointer != NULL)
|
||||||
{
|
{
|
||||||
Yap_unify(module, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_module(pointer))));
|
|
||||||
Yap_unify(nome, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_name(pointer))));
|
|
||||||
Yap_unify(aridade, MkIntegerTerm((int)myddas_util_get_pred_arity(pointer)));
|
|
||||||
|
|
||||||
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((int)myddas_util_get_pred_next(pointer));
|
EXTRA_CBACK_ARG(4,1)=(CELL) MkIntegerTerm((int)myddas_util_get_pred_next(pointer));
|
||||||
|
|
||||||
|
if (!Yap_unify(module, MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_module(pointer))))){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!Yap_unify(name,MkAtomTerm(Yap_LookupAtom(myddas_util_get_pred_name(pointer))))){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!Yap_unify(arity, MkIntegerTerm((int)myddas_util_get_pred_arity(pointer)))){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -386,43 +443,6 @@ void Yap_MyDDAS_delete_all_myddas_structs(void)
|
|||||||
/* } */
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_InitMYDDAS_SharedPreds(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
Yap_InitCPred("c_db_get_new_table_name",2,c_db_get_new_table_name, 0);
|
|
||||||
|
|
||||||
|
|
||||||
Yap_InitCPred("c_db_connection_type",2,c_db_connection_type, 0);
|
|
||||||
|
|
||||||
/* CORRECT THIS: db_add_preds : PredName * Arity * Connection */
|
|
||||||
Yap_InitCPred("c_db_add_preds",4,c_db_add_preds, 0);
|
|
||||||
|
|
||||||
/* c_db_check_if_exists_pred : PredName * Arity * Connection */
|
|
||||||
Yap_InitCPred("c_db_check_if_exists_pred",3,c_db_check_if_exists_pred, 0);
|
|
||||||
|
|
||||||
/* c_db_delete_pred : Module * PredName * Arity */
|
|
||||||
Yap_InitCPred("c_db_delete_predicate",3,c_db_delete_predicate, 0);
|
|
||||||
|
|
||||||
/* c_db_delete_pred : Module * PredName * Arity */
|
|
||||||
Yap_InitCPred("c_db_multi_queries_number",2,c_db_multi_queries_number, 0);
|
|
||||||
|
|
||||||
#ifdef MYDDAS_STATS
|
|
||||||
/* db_stats: Connection * Stats*/
|
|
||||||
Yap_InitCPred("c_db_stats",2, c_db_stats, 0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
Yap_InitCPred("c_db_check",0, c_db_check, 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Yap_InitBackMYDDAS_SharedPreds(void)
|
|
||||||
{
|
|
||||||
Yap_InitCPredBack("c_db_preds_conn", 4, sizeof(int),
|
|
||||||
c_db_preds_conn_start,
|
|
||||||
c_db_preds_conn_continue, 0);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,13 +17,17 @@
|
|||||||
|
|
||||||
:- module(myddas,[
|
:- module(myddas,[
|
||||||
db_open/5,
|
db_open/5,
|
||||||
|
db_open/4,
|
||||||
db_close/1,
|
db_close/1,
|
||||||
|
db_close/0,
|
||||||
|
|
||||||
db_verbose/1,
|
db_verbose/1,
|
||||||
db_module/1,
|
db_module/1,
|
||||||
db_is_database_predicate/3,
|
db_is_database_predicate/3,
|
||||||
db_stats/2,
|
db_stats/2,
|
||||||
|
|
||||||
|
db_sql/2,
|
||||||
|
db_sql/3,
|
||||||
db_sql_select/3,
|
db_sql_select/3,
|
||||||
db_prolog_select/3,
|
db_prolog_select/3,
|
||||||
db_prolog_select_multi/3,
|
db_prolog_select_multi/3,
|
||||||
@ -43,11 +47,15 @@
|
|||||||
db_datalog_select/3,
|
db_datalog_select/3,
|
||||||
|
|
||||||
% myddas_assert_predicates.yap
|
% myddas_assert_predicates.yap
|
||||||
|
db_import/2,
|
||||||
db_import/3,
|
db_import/3,
|
||||||
|
db_view/2,
|
||||||
db_view/3,
|
db_view/3,
|
||||||
db_insert/3,
|
db_insert/3,
|
||||||
db_abolish/2,
|
db_abolish/2,
|
||||||
|
db_listing/0,
|
||||||
|
db_listing/1,
|
||||||
|
|
||||||
% myddas_mysql.yap
|
% myddas_mysql.yap
|
||||||
db_my_open/5,
|
db_my_open/5,
|
||||||
db_my_close/1,
|
db_my_close/1,
|
||||||
@ -75,10 +83,14 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module(myddas_assert_predicates,[
|
:- use_module(myddas_assert_predicates,[
|
||||||
|
db_import/2,
|
||||||
db_import/3,
|
db_import/3,
|
||||||
|
db_view/2,
|
||||||
db_view/3,
|
db_view/3,
|
||||||
db_insert/3,
|
db_insert/3,
|
||||||
db_abolish/2
|
db_abolish/2,
|
||||||
|
db_listing/0,
|
||||||
|
db_listing/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
:- use_module(myddas_mysql,[
|
:- use_module(myddas_mysql,[
|
||||||
@ -135,9 +147,11 @@
|
|||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_open/5
|
% db_open/5
|
||||||
%
|
% db_open/4
|
||||||
%
|
%
|
||||||
|
db_open(Interface,HostDb,User,Password):-
|
||||||
|
db_open(Interface,myddas,HostDb,User,Password).
|
||||||
db_open(mysql,Connection,Host/Db,User,Password) :-
|
db_open(mysql,Connection,Host/Db,User,Password) :-
|
||||||
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
||||||
c_db_my_connect(Host,User,Password,Db,Con),
|
c_db_my_connect(Host,User,Password,Db,Con),
|
||||||
@ -153,8 +167,10 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :-
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_close/1
|
% db_close/1
|
||||||
|
% db_close/0
|
||||||
%
|
%
|
||||||
%
|
db_close:-
|
||||||
|
db_close(myddas).
|
||||||
db_close(Connection):-
|
db_close(Connection):-
|
||||||
'$error_checks'(db_close(Connection)),
|
'$error_checks'(db_close(Connection)),
|
||||||
get_value(Connection,Con),
|
get_value(Connection,Con),
|
||||||
@ -232,12 +248,18 @@ db_stats(Connection,List):-
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
db_sql_select(_,_,_):-
|
||||||
|
nl,write('Know use db_sql/3 insted of db_sql_select/3'),nl,
|
||||||
|
halt.
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_sql_select(+,+,-)
|
% db_sql(+,+,-)
|
||||||
%
|
%
|
||||||
%
|
%
|
||||||
db_sql_select(Connection,SQL,LA):-
|
db_sql(SQL,LA):-
|
||||||
'$error_checks'(db_sql_select(Connection,SQL,LA)),
|
db_sql(myddas,SQL,LA).
|
||||||
|
db_sql(Connection,SQL,LA):-
|
||||||
|
'$error_checks'(db_sql(Connection,SQL,LA)),
|
||||||
get_value(Connection,Con),
|
get_value(Connection,Con),
|
||||||
c_db_connection_type(Con,ConType),
|
c_db_connection_type(Con,ConType),
|
||||||
( ConType == mysql ->
|
( ConType == mysql ->
|
||||||
|
@ -16,10 +16,14 @@
|
|||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
:- module(myddas_assert_predicates,[
|
:- module(myddas_assert_predicates,[
|
||||||
|
db_import/2,
|
||||||
db_import/3,
|
db_import/3,
|
||||||
|
db_view/2,
|
||||||
db_view/3,
|
db_view/3,
|
||||||
db_insert/3,
|
db_insert/3,
|
||||||
db_abolish/2
|
db_abolish/2,
|
||||||
|
db_listing/0,
|
||||||
|
db_listing/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
@ -54,8 +58,10 @@
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_import/3
|
% db_import/3
|
||||||
|
% db_import/2
|
||||||
%
|
%
|
||||||
%
|
db_import(RelationName,PredName):-
|
||||||
|
db_import(myddas,Relation,PredName).
|
||||||
db_import(Connection,RelationName,PredName) :-
|
db_import(Connection,RelationName,PredName) :-
|
||||||
'$error_checks'(db_import(Connection,RelationName,PredName)),
|
'$error_checks'(db_import(Connection,RelationName,PredName)),
|
||||||
get_value(Connection,Con),
|
get_value(Connection,Con),
|
||||||
@ -90,13 +96,6 @@ db_import(Connection,RelationName,PredName) :-
|
|||||||
functor(P,PredName,Arity),
|
functor(P,PredName,Arity),
|
||||||
'$make_list_of_args'(1,Arity,P,LA),
|
'$make_list_of_args'(1,Arity,P,LA),
|
||||||
|
|
||||||
%Optimization
|
|
||||||
%'$copy_term_nv'(P,[],G,_),
|
|
||||||
|
|
||||||
%generate the SQL query
|
|
||||||
% translate(G,G,Code),
|
|
||||||
%queries_atom(Code,SQL),
|
|
||||||
|
|
||||||
M=myddas_assert_predicates,
|
M=myddas_assert_predicates,
|
||||||
%build PredName clause
|
%build PredName clause
|
||||||
( ConType == mysql ->
|
( ConType == mysql ->
|
||||||
@ -109,27 +108,10 @@ db_import(Connection,RelationName,PredName) :-
|
|||||||
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
||||||
','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))]
|
','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))]
|
||||||
|
|
||||||
% Assert =..[':-',P,','(M:'$build_query'(0,SQL,Code,LA,FinalSQL),
|
|
||||||
% ','(M:db_my_result_set(Mode),
|
|
||||||
% ','(M:'$write_or_not'(FinalSQL),
|
|
||||||
% ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
|
||||||
% ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))]
|
|
||||||
|
|
||||||
% Assert =..[':-',P,','(get_value(db_myddas_stats_count,Number),
|
|
||||||
% ','(statistics(cputime,TimeI),
|
|
||||||
% ','(M:'$build_query'(0,SQL,Code,LA,FinalSQL),
|
|
||||||
% ','(M:db_my_result_set(Mode),
|
|
||||||
% ','(M:'$write_or_not'(FinalSQL),
|
|
||||||
% ','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode),
|
|
||||||
% ','(statistics(cputime,TimeF),
|
|
||||||
% ','(Temp is TimeF - TimeI,
|
|
||||||
% ','(Temp2 is Temp + Number,
|
|
||||||
% ','(set_value(db_myddas_stats_count,Temp2),
|
|
||||||
% ','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))))))]
|
|
||||||
;
|
;
|
||||||
'$make_a_list'(Arity,BindList),
|
'$make_a_list'(Arity,BindList),
|
||||||
Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
|
Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
|
||||||
','(M:translate(G,G,Code),
|
','(M:translate(G,G,Code),
|
||||||
','(M:queries_atom(Code,FinalSQL),
|
','(M:queries_atom(Code,FinalSQL),
|
||||||
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Connection),
|
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Connection),
|
||||||
','(M:'$write_or_not'(FinalSQL),
|
','(M:'$write_or_not'(FinalSQL),
|
||||||
@ -144,8 +126,10 @@ db_import(Connection,RelationName,PredName) :-
|
|||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_view/3
|
% db_view/3
|
||||||
|
% db_view/2
|
||||||
%
|
%
|
||||||
%
|
db_view(PredName,DbGoal) :-
|
||||||
|
db_view(myddas,PredName,DbGoal).
|
||||||
db_view(Connection,PredName,DbGoal) :-
|
db_view(Connection,PredName,DbGoal) :-
|
||||||
'$error_checks'(db_view(Connection,PredName,DbGoal)),
|
'$error_checks'(db_view(Connection,PredName,DbGoal)),
|
||||||
get_value(Connection,Con),
|
get_value(Connection,Con),
|
||||||
@ -247,13 +231,61 @@ db_insert(Connection,RelationName,PredName) :-
|
|||||||
%
|
%
|
||||||
%
|
%
|
||||||
db_abolish(Module:PredName,Arity):-!,
|
db_abolish(Module:PredName,Arity):-!,
|
||||||
%'$error_checks'(db_abolish(Module:PredName,Arity)),
|
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||||
c_db_delete_predicate(Module,PredName,Arity),
|
c_db_delete_predicate(Module,PredName,Arity),
|
||||||
abolish(Module:PredName,Arity).
|
abolish(Module:PredName,Arity).
|
||||||
db_abolish(PredName,Arity):-
|
db_abolish(PredName,Arity):-
|
||||||
%'$error_checks'(db_abolish(PredName,Arity)),
|
'$error_checks'(db_abolish(PredName,Arity)),
|
||||||
db_module(Module),
|
db_module(Module),
|
||||||
c_db_delete_predicate(Module,PredName,Arity),
|
c_db_delete_predicate(Module,PredName,Arity),
|
||||||
abolish(Module:PredName,Arity).
|
abolish(Module:PredName,Arity).
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% db_abolish(+,+)
|
||||||
|
%
|
||||||
|
%
|
||||||
|
db_abolish(Module:PredName,Arity):-!,
|
||||||
|
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||||
|
c_db_delete_predicate(Module,PredName,Arity),
|
||||||
|
abolish(Module:PredName,Arity).
|
||||||
|
db_abolish(PredName,Arity):-
|
||||||
|
'$error_checks'(db_abolish(PredName,Arity)),
|
||||||
|
db_module(Module),
|
||||||
|
c_db_delete_predicate(Module,PredName,Arity),
|
||||||
|
abolish(Module:PredName,Arity).
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% db_listing.
|
||||||
|
%
|
||||||
|
%
|
||||||
|
db_listing:-
|
||||||
|
c_db_connection(Con),
|
||||||
|
c_db_preds_conn(Con,Module,Name,Arity),
|
||||||
|
listing(Module:Name/Arity),
|
||||||
|
fail.
|
||||||
|
db_listing.
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
% db_listing.
|
||||||
|
%
|
||||||
|
%
|
||||||
|
db_listing(Module:Name/Arity):-!,
|
||||||
|
c_db_connection(Con),
|
||||||
|
c_db_preds_conn(Con,Module,Name,Arity),
|
||||||
|
listing(Module:Name/Arity).
|
||||||
|
db_listing(Name/Arity):-!,
|
||||||
|
c_db_connection(Con),
|
||||||
|
c_db_preds_conn(Con,Module,Name,Arity),
|
||||||
|
listing(Module:Name/Arity).
|
||||||
|
db_listing(Name):-
|
||||||
|
c_db_connection(Con),
|
||||||
|
c_db_preds_conn(Con,Module,Name,Arity),
|
||||||
|
listing(Module:Name/Arity).
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
@ -28,6 +28,15 @@
|
|||||||
is_list/1
|
is_list/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
'$error_checks'(db_abolish(ModulePredName,Arity)):-!,
|
||||||
|
(ModulePredName = Module:PredName ->
|
||||||
|
atom(Module),
|
||||||
|
atom(PredName)
|
||||||
|
;
|
||||||
|
atom(ModulePredName)
|
||||||
|
),
|
||||||
|
number(Arity).
|
||||||
'$error_checks'(db_show_database(Connection,_)):- !,
|
'$error_checks'(db_show_database(Connection,_)):- !,
|
||||||
atom(Connection).
|
atom(Connection).
|
||||||
'$error_checks'(db_change_database(Connection,Database)):- !,
|
'$error_checks'(db_change_database(Connection,Database)):- !,
|
||||||
@ -106,7 +115,7 @@
|
|||||||
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
|
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
|
||||||
atom(Connection),
|
atom(Connection),
|
||||||
nonvar(RelationName).
|
nonvar(RelationName).
|
||||||
'$error_checks'(db_sql_select(Connection,SQL,LA)):- !,
|
'$error_checks'(db_sql(Connection,SQL,LA)):- !,
|
||||||
atom(Connection),
|
atom(Connection),
|
||||||
nonvar(SQL),
|
nonvar(SQL),
|
||||||
not ground(LA).
|
not ground(LA).
|
||||||
|
Reference in New Issue
Block a user