new version of myddas
fix modules integrated myydas_driver.ypp for common stuff test sqlite3
This commit is contained in:
parent
84d5974cca
commit
728edb6b0a
15
.gitignore
vendored
15
.gitignore
vendored
@ -165,4 +165,17 @@ android
|
||||
yap.prj
|
||||
|
||||
yap.VITORs-MBP.vsc.pui
|
||||
vc
|
||||
vc
|
||||
packages/myddas/pl/myddas_odbc.yap
|
||||
|
||||
packages/myddas/pl/myddas_postgres.yap
|
||||
|
||||
packages/myddas/pl/myddas_sqlite3.ypp
|
||||
|
||||
packages/myddas/pl/#myddas_postgres.ypp#
|
||||
|
||||
packages/myddas/hh
|
||||
|
||||
packages/myddas/DaysInHospital_Y3.csv
|
||||
|
||||
packages/myddas/agile.csv
|
||||
|
@ -1,61 +1,59 @@
|
||||
SET( CMAKE_FIND_FRAMEWORK LAST)
|
||||
SET( CMAKE_FIND_APPBUNDLE LAST)
|
||||
SET(CMAKE_FIND_FRAMEWORK LAST)
|
||||
SET(CMAKE_FIND_APPBUNDLE LAST)
|
||||
|
||||
# Be sure to also update these in Makefile!
|
||||
set(SO_MAJOR 1)
|
||||
set(SO_MINOR 0)
|
||||
set(SO_PATCH 0)
|
||||
|
||||
set( MYDDAS_SOURCES
|
||||
myddas_initialization.c
|
||||
myddas_shared.c
|
||||
myddas_statistics.c
|
||||
myddas_top_level.c
|
||||
)
|
||||
set(MYDDAS_SOURCES
|
||||
myddas_initialization.c
|
||||
myddas_shared.c
|
||||
myddas_statistics.c
|
||||
myddas_top_level.c
|
||||
|
||||
include_directories (. sqlite3)
|
||||
)
|
||||
|
||||
include_directories(. sqlite3)
|
||||
|
||||
|
||||
set( MYDDAS_HEADERS
|
||||
myddas.h
|
||||
myddas_statistics.h
|
||||
myddas_statistics_structs.h
|
||||
myddas_structs.h
|
||||
myddas_top_level.c
|
||||
myddas_types.h )
|
||||
set(MYDDAS_HEADERS
|
||||
myddas.h
|
||||
myddas_statistics.h
|
||||
myddas_statistics_structs.h
|
||||
myddas_structs.h
|
||||
myddas_top_level.c
|
||||
myddas_types.h)
|
||||
|
||||
set( MYDDAS_UTIL_SOURCES
|
||||
myddas_util.c
|
||||
myddas_initialization.c )
|
||||
set(MYDDAS_UTIL_SOURCES
|
||||
myddas_util.c
|
||||
myddas_initialization.c)
|
||||
|
||||
set_property( GLOBAL
|
||||
APPEND PROPERTY COMPILE_DEFINITIONS USE_MYDDAS=1)
|
||||
set (MYDDAS_FLAGS -DUSE_MYDDAS=1)
|
||||
set_property(GLOBAL
|
||||
APPEND PROPERTY
|
||||
COMPILE_DEFINITIONS
|
||||
-DUSE_MYDDAS=1)
|
||||
|
||||
# internal MYDDAS flag, used to preprocess ypp files.
|
||||
set (MYDDAS_FLAGS -DUSE_MYDDAS=1)
|
||||
add_subdirectory(sqlite3)
|
||||
|
||||
add_subdirectory (mysql)
|
||||
add_subdirectory (odbc)
|
||||
add_subdirectory (postgres)
|
||||
add_subdirectory (sqlite3)
|
||||
MY_add_subdirectory(mysql)
|
||||
MY_add_subdirectory(odbc)
|
||||
MY_add_subdirectory(postgres)
|
||||
|
||||
|
||||
add_subdirectory (pl)
|
||||
add_component(myddas
|
||||
${MYDDAS_SOURCES}
|
||||
${MYDDAS_UTIL_SOURCES}
|
||||
${MYDDAS_HEADERS}
|
||||
)
|
||||
MY_add_dependencies(myddas plmyddas)
|
||||
add_subdirectory(pl)
|
||||
|
||||
MY_set_target_properties(myddas PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
add_library (myddas OBJECT
|
||||
${MYDDAS_SOURCES}
|
||||
${MYDDAS_UTIL_SOURCES}
|
||||
${MYDDAS_HEADERS}
|
||||
)
|
||||
|
||||
|
||||
add_dependencies(myddas plmyddas)
|
||||
|
||||
set_target_properties (myddas PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
)
|
||||
|
||||
cmake_dependent_option (USE_MYDDAS_Stats
|
||||
"enable the MYDDAS library statistics support" OFF
|
||||
USE_MYDDAS OFF)
|
||||
cmake_dependent_option(USE_MYDDAS_Stats
|
||||
"enable the MYDDAS library statistics support" OFF
|
||||
USE_MYDDAS OFF)
|
||||
|
@ -3,80 +3,90 @@
|
||||
#ifdef USE_MYDDAS
|
||||
|
||||
/* myddas_initialization.c */
|
||||
MYDDAS_GLOBAL myddas_init_initialize_myddas(void);
|
||||
MYDDAS_UTIL_CONNECTION
|
||||
myddas_init_initialize_connection(void *, void *, MYDDAS_API,
|
||||
MYDDAS_UTIL_CONNECTION);
|
||||
MYDDAS_UTIL_PREDICATE myddas_init_initialize_predicate(const char *, int,
|
||||
const char *,
|
||||
MYDDAS_UTIL_PREDICATE);
|
||||
extern MYDDAS_GLOBAL myddas_init_initialize_myddas(void);
|
||||
extern MYDDAS_UTIL_CONNECTION
|
||||
myddas_init_initialize_connection(void *, void *, MYDDAS_API,
|
||||
MYDDAS_UTIL_CONNECTION);
|
||||
extern MYDDAS_UTIL_PREDICATE myddas_init_initialize_predicate(const char *, int,
|
||||
const char *,
|
||||
MYDDAS_UTIL_PREDICATE);
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
/* myddas_statistics.c */
|
||||
MYDDAS_GLOBAL myddas_stats_initialize_global_stats(MYDDAS_GLOBAL);
|
||||
MYDDAS_STATS_STRUCT myddas_stats_initialize_connection_stats(void);
|
||||
void myddas_stats_delete_stats_list(MYDDAS_STATS_STRUCT);
|
||||
extern MYDDAS_GLOBAL myddas_stats_initialize_global_stats(MYDDAS_GLOBAL);
|
||||
extern MYDDAS_STATS_STRUCT myddas_stats_initialize_connection_stats(void);
|
||||
extern void myddas_stats_delete_stats_list(MYDDAS_STATS_STRUCT);
|
||||
#endif /* MYDDAS_STATS */
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
/* myddas_util.c */
|
||||
void myddas_util_table_write(MYSQL_RES *);
|
||||
extern void init_mysq( void );
|
||||
extern void myddas_util_table_write(MYSQL_RES *);
|
||||
extern MYDDAS_UTIL_CONNECTION myddas_util_add_connection(void *, void *, MYDDAS_API);
|
||||
#endif
|
||||
MYDDAS_UTIL_CONNECTION myddas_util_search_connection(void *con);
|
||||
MYDDAS_UTIL_CONNECTION myddas_util_add_connection(void *, void *, MYDDAS_API);
|
||||
MYDDAS_UTIL_CONNECTION myddas_util_search_connection(void *);
|
||||
void myddas_util_delete_connection(void *);
|
||||
MYDDAS_UTIL_CONNECTION myddas_util_add_predicate(const char *, Int,
|
||||
const char *, void *);
|
||||
MYDDAS_UTIL_PREDICATE myddas_util_search_predicate(const char *, Int,
|
||||
const char *);
|
||||
void myddas_util_delete_predicate(MYDDAS_UTIL_PREDICATE);
|
||||
extern MYDDAS_UTIL_CONNECTION myddas_util_search_connection(void *con);
|
||||
extern MYDDAS_UTIL_CONNECTION myddas_util_search_connection(void *);
|
||||
extern void myddas_util_delete_connection(void *);
|
||||
extern MYDDAS_UTIL_CONNECTION myddas_util_add_predicate(const char *, Int,
|
||||
const char *, void *);
|
||||
extern MYDDAS_UTIL_PREDICATE myddas_util_search_predicate(const char *, Int,
|
||||
const char *);
|
||||
extern void myddas_util_delete_predicate(MYDDAS_UTIL_PREDICATE);
|
||||
|
||||
/* Get's the number of queries to save */
|
||||
UInt myddas_util_get_total_multi_queries_number(MYDDAS_UTIL_CONNECTION);
|
||||
void myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION, UInt);
|
||||
extern UInt myddas_util_get_total_multi_queries_number(MYDDAS_UTIL_CONNECTION);
|
||||
extern void myddas_util_set_total_multi_queries_number(MYDDAS_UTIL_CONNECTION, UInt);
|
||||
|
||||
void *myddas_util_get_list_pred(MYDDAS_UTIL_CONNECTION);
|
||||
void *myddas_util_get_pred_next(void *);
|
||||
const char *myddas_util_get_pred_module(void *);
|
||||
const char *myddas_util_get_pred_name(void *);
|
||||
MyddasInt myddas_util_get_pred_arity(void *);
|
||||
extern void *myddas_util_get_list_pred(MYDDAS_UTIL_CONNECTION);
|
||||
extern void *myddas_util_get_pred_next(void *);
|
||||
extern const char *myddas_util_get_pred_module(void *);
|
||||
extern const char *myddas_util_get_pred_name(void *);
|
||||
extern MyddasInt myddas_util_get_pred_arity(void *);
|
||||
// DELETE THIS WHEN DB_STATS IS COMPLETED
|
||||
MyddasInt get_myddas_top(void);
|
||||
extern MyddasInt get_myddas_top(void);
|
||||
|
||||
#ifdef DEBUG
|
||||
void check_int(void);
|
||||
extern void check_int(void);
|
||||
#endif
|
||||
|
||||
#endif /* MYDDAS_MYSQL || MYDDAS_ODBC */
|
||||
|
||||
/* myddas_mysql.c */
|
||||
#if defined MYDDAS_MYSQL
|
||||
void Yap_InitMYDDAS_MySQLPreds(void);
|
||||
void Yap_InitBackMYDDAS_MySQLPreds(void);
|
||||
extern void Yap_InitMYDDAS_MySQLPreds(void);
|
||||
extern void Yap_InitBackMYDDAS_MySQLPreds(void);
|
||||
#endif
|
||||
|
||||
/* myddas_odbc.c */
|
||||
#if defined MYDDAS_ODBC
|
||||
void Yap_InitMYDDAS_ODBCPreds(void);
|
||||
void Yap_InitBackMYDDAS_ODBCPreds(void);
|
||||
extern void init_odbc( void );
|
||||
extern void Yap_InitMYDDAS_ODBCPreds(void);
|
||||
extern void Yap_InitBackMYDDAS_ODBCPreds(void);
|
||||
#endif
|
||||
|
||||
/* myddas_odbc.c */
|
||||
/* myddas_postgres.c */
|
||||
#if defined MYDDAS_POSTGRES
|
||||
extern void init_postgres( void );
|
||||
extern void Yap_InitMYDDAS_PostgresPreds(void);
|
||||
extern void Yap_InitBackMYDDAS_PostgresPreds(void);
|
||||
#endif
|
||||
|
||||
/* myddas_sqlite3.c */
|
||||
#if defined MYDDAS_SQLITE3
|
||||
void Yap_InitMYDDAS_SQLITE3Preds(void);
|
||||
void Yap_InitBackMYDDAS_SQLITE3Preds(void);
|
||||
extern void init_sqlite3( void );
|
||||
extern void Yap_InitMYDDAS_SQLITE3Preds(void);
|
||||
extern void Yap_InitBackMYDDAS_SQLITE3Preds(void);
|
||||
#endif
|
||||
|
||||
/* Myddas_shared.c */
|
||||
#if defined USE_MYDDAS
|
||||
void Yap_MYDDAS_delete_all_myddas_structs(void);
|
||||
void Yap_InitMYDDAS_SharedPreds(void);
|
||||
void Yap_InitBackMYDDAS_SharedPreds(void);
|
||||
extern void Yap_MYDDAS_delete_all_myddas_structs(void);
|
||||
extern void Yap_InitMYDDAS_SharedPreds(void);
|
||||
extern void Yap_InitBackMYDDAS_SharedPreds(void);
|
||||
#endif
|
||||
|
||||
/* myddas_top_level.c */
|
||||
#if defined MYDDAS_TOP_LEVEL && \
|
||||
defined MYDDAS_MYSQL //&& defined HAVE_LIBREADLINE
|
||||
void Yap_InitMYDDAS_TopLevelPreds(void);
|
||||
defined MYDDAS_MYSQL //&& defined HAVE_LIBREADLINE
|
||||
extern void Yap_InitMYDDAS_TopLevelPreds(void);
|
||||
#endif
|
||||
|
@ -2,19 +2,21 @@
|
||||
sqlite3 side:
|
||||
create table test (id integer, x integer, y integer);
|
||||
.separator ","
|
||||
.import /home/vsc/Yap/ILP/HH/DaysInHospital_Y3.csv test
|
||||
.import DaysInHospital_Y3.csv hh
|
||||
.export hh
|
||||
.save hh
|
||||
|
||||
myddas side:
|
||||
use_module(library(myddas)).
|
||||
db_open(sqlite3,con,'../hh',x,x).
|
||||
db_open(sqlite3,con,'.hh',x,x).
|
||||
db_close(con).
|
||||
|
||||
test 2:
|
||||
|
||||
use_module(library(myddas)).
|
||||
assert((
|
||||
t2 :-
|
||||
db_open(sqlite3,con,'../hh',x,x),
|
||||
t2 :-
|
||||
db_open(sqlite3,con,'hh',x,x),
|
||||
db_import(con,test,test),
|
||||
test(A,B,C),
|
||||
writeln(test(A,B,C)),
|
||||
@ -22,4 +24,3 @@ fail
|
||||
)).
|
||||
trace.
|
||||
t2.
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
* *
|
||||
*************************************************************************/
|
||||
#include "Yap.h"
|
||||
|
||||
#ifdef USE_MYDDAS
|
||||
|
||||
#include "Yatom.h"
|
||||
@ -26,7 +25,7 @@
|
||||
#include "myddas_statistics.h"
|
||||
#endif
|
||||
|
||||
void init_myddas(void);
|
||||
extern void init_myddas(void);
|
||||
|
||||
static Int c_db_initialize_myddas(USES_REGS1);
|
||||
static Int c_db_connection_type(USES_REGS1);
|
||||
@ -95,8 +94,13 @@ void Yap_InitBackMYDDAS_SharedPreds(void) {
|
||||
c_db_connection_continue, 0);
|
||||
}
|
||||
|
||||
static bool myddas_initialised;
|
||||
|
||||
/* Initialize all of the MYDDAS global structures */
|
||||
static Int c_db_initialize_myddas(USES_REGS1) {
|
||||
if (!myddas_initialised) {
|
||||
init_myddas();
|
||||
}
|
||||
Yap_REGS.MYDDAS_GLOBAL_POINTER = myddas_init_initialize_myddas();
|
||||
#ifdef MYDDAS_STATS
|
||||
Yap_REGS.MYDDAS_GLOBAL_POINTER =
|
||||
@ -675,6 +679,9 @@ void Yap_MYDDAS_delete_all_myddas_structs(void) {
|
||||
|
||||
void init_myddas(void) {
|
||||
CACHE_REGS
|
||||
if (myddas_initialised)
|
||||
return;
|
||||
myddas_initialised = TRUE;
|
||||
#if defined MYDDAS_ODBC
|
||||
Yap_InitBackMYDDAS_ODBCPreds();
|
||||
#endif
|
||||
|
@ -1,47 +1,52 @@
|
||||
|
||||
set( YAPMYSQL_SOURCES
|
||||
myddas_mysql.c
|
||||
myddas_util.c
|
||||
myddas_util.c
|
||||
myddas_wkb2prolog.c
|
||||
)
|
||||
set(MYSQL_SOURCES
|
||||
myddas_mysql.c
|
||||
myddas_util.c
|
||||
myddas_util.c
|
||||
myddas_wkb2prolog.c
|
||||
)
|
||||
|
||||
set(SO_MAJOR 1)
|
||||
set(SO_MINOR 0)
|
||||
set(SO_PATCH 0)
|
||||
set(SO_MAJOR 1)
|
||||
set(SO_MINOR 0)
|
||||
set(SO_PATCH 0)
|
||||
|
||||
macro_optional_find_package(MySQL ON)
|
||||
macro_optional_find_package(MySQL ON)
|
||||
|
||||
macro_log_feature (MYSQL_FOUND "MySQL"
|
||||
"MYSQL Driver for MYDDAS Data-Base Interface "
|
||||
"http://www.mysql.org" FALSE)
|
||||
macro_log_feature(MYSQL_FOUND "MySQL"
|
||||
"MYSQL Driver for MYDDAS Data-Base Interface "
|
||||
"http://www.mysql.org" FALSE)
|
||||
|
||||
if (MYSQL_FOUND)
|
||||
# MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
|
||||
# MYSQL_LIBRARIES - List of libraries when using MySQL.
|
||||
# MYSQL_FOUND - True if MySQL found.
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} -DMYDDAS_MYSQL=1 PARENT_SCOPE)
|
||||
set_property( DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS MYDDAS_MYSQL=1 )
|
||||
add_library (Yapmysql SHARED ${YAPMYSQL_SOURCES})
|
||||
target_link_libraries(Yapmysql ${MYSQL_LIBRARIES} libYap)
|
||||
include_directories (${MYSQL_INCLUDE_DIR} ..)
|
||||
set_target_properties (Yapmysql PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}"
|
||||
SOVERSION ${SO_MAJOR}
|
||||
)
|
||||
# MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
|
||||
# MYSQL_LIBRARIES - List of libraries when using MySQL.
|
||||
# MYSQL_FOUND - True if MySQL found.
|
||||
|
||||
set_property(GLOBAL
|
||||
APPEND PROPERTY COMPILE_DEFINITIONS -DMYDDAS_MYSQL=1)
|
||||
add_library(Yapmysql SHARED ${MYSQL_SOURCES})
|
||||
target_link_libraries(Yapmysql ${MYSQL_LIBRARIES} libYap)
|
||||
include_directories(${MYSQL_INCLUDE_DIR} ..)
|
||||
set_target_properties(Yapmysql PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
PREFIX ""
|
||||
)
|
||||
|
||||
list (APPEND MYDDAS_FLAGS -DMYDDAS_MYSQL=1)
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE)
|
||||
set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
-DMYDDAS_MYSQL=1)
|
||||
|
||||
|
||||
install(TARGETS Yapmysql
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
ARCHIVE DESTINATION ${libdir}
|
||||
)
|
||||
install(TARGETS Yapmysql
|
||||
LIBRARY DESTINATION ${dlls}
|
||||
ARCHIVE DESTINATION ${dlls}
|
||||
)
|
||||
|
||||
else()
|
||||
add_definitions (-DMYDDAS_MYSQL=0)
|
||||
else ()
|
||||
add_definitions(-DMYDDAS_MYSQL=0)
|
||||
endif (MYSQL_FOUND)
|
||||
|
||||
cmake_dependent_option (USE_MYDDAS_top_level
|
||||
"enable the MYDDAS top-level (REPL) support for MySQL" OFF
|
||||
'USE_MYDDAS AND MYSQL_FOUND' OFF)
|
||||
#TODO:
|
||||
cmake_dependent_option(USE_MYDDAS_top_level
|
||||
"enable the MYDDAS top-level (REPL) support for MySQL" OFF
|
||||
'USE_MYDDAS AND MYSQL_FOUND' OFF)
|
||||
#TODO:
|
||||
|
@ -736,3 +736,31 @@ void Yap_InitBackMYDDAS_MySQLPreds(void)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void init_mysql( void )
|
||||
{
|
||||
Yap_InitMYDDAS_MySQLPreds();
|
||||
Yap_InitBackMYDDAS_MySQLPreds();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int WINAPI win_mysql(HANDLE hinst, DWORD reason, LPVOID reserved);
|
||||
|
||||
int WINAPI win_mysql(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||
switch (reason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -17,21 +17,24 @@ if (ODBC_FOUND)
|
||||
# ODBC_INCLUDE_DIRECTORIES, where to find sql.h
|
||||
# ODBC_LIBRARIES, the libraries to link against to use ODBC
|
||||
# ODBC_FOUND. If false, you cannot build anything that requires Odbc.
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} -DMYDDAS_ODBC=1 PARENT_SCOPE)
|
||||
set_property( DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS MYDDAS_ODBC=1 )
|
||||
add_library (Yapodbc SHARED ${YAPODBC_SOURCES})
|
||||
target_link_libraries(Yapodbc libYap ${ODBC_LIBRARIES})
|
||||
include_directories (${ODBC_INCLUDE_DIRECTORIES} ..)
|
||||
|
||||
set_target_properties (Yapodbc PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}"
|
||||
SOVERSION ${SO_MAJOR}
|
||||
PREFIX ""
|
||||
)
|
||||
|
||||
install(TARGETS Yapodbc
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
ARCHIVE DESTINATION ${libdir}
|
||||
list (APPEND MYDDAS_FLAGS -DMYDDAS_ODBC=1)
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE)
|
||||
set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
-DMYDDAS_ODBC=1)
|
||||
|
||||
|
||||
install(TARGETS Yapodbc
|
||||
LIBRARY DESTINATION ${dlls}
|
||||
ARCHIVE DESTINATION ${dlls}
|
||||
)
|
||||
|
||||
else()
|
||||
|
@ -801,5 +801,38 @@ void Yap_InitBackMYDDAS_ODBCPreds(void) {
|
||||
Yap_InitCPredBackCut("c_db_odbc_row", 3, sizeof(Int), c_db_odbc_row,
|
||||
c_db_odbc_row, c_db_odbc_row_cut, 0);
|
||||
}
|
||||
#else
|
||||
|
||||
#endif /*MYDDAS_ODBC*/
|
||||
void Yap_InitMYDDAS_ODBCPreds(void) {}
|
||||
void Yap_InitBackMYDDAS_ODBCPreds(void) {}
|
||||
|
||||
#endif
|
||||
|
||||
void init_odbc( void )
|
||||
{
|
||||
Yap_InitMYDDAS_ODBCPreds();
|
||||
Yap_InitBackMYDDAS_ODBCPreds();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int WINAPI win_odbc(HANDLE hinst, DWORD reason, LPVOID reserved);
|
||||
|
||||
int WINAPI win_odbc(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||
switch (reason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
/*MYDDAS_ODBC*/
|
||||
|
@ -1,248 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_mysql.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: MySQL Predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef MYDDAS_MYSQL
|
||||
|
||||
:- module(myddas_mysql,[
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
db_datalog_describe/2,
|
||||
db_describe/3,
|
||||
db_describe/2,
|
||||
db_datalog_show_tables/1,
|
||||
db_datalog_show_tables/0,
|
||||
db_show_tables/2,
|
||||
db_show_tables/1,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_call_procedure/4,
|
||||
db_call_procedure/3,
|
||||
db_my_sql_mode/1,
|
||||
db_my_sql_mode/2,
|
||||
db_sql_mode/1,
|
||||
db_sql_mode/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_sql/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$get_value'/2,
|
||||
'$make_atom'/2,
|
||||
'$make_atom_args'/2,
|
||||
'$make_a_list'/2,
|
||||
'$write_or_not'/1
|
||||
]).
|
||||
|
||||
|
||||
%--------------------------------------------------------
|
||||
% Public Predicates
|
||||
%--------------------------------------------------------
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_result_set/1
|
||||
%
|
||||
%
|
||||
db_my_result_set(X):-
|
||||
var(X),!,
|
||||
get_value(db_my_result_set,X).
|
||||
db_my_result_set(use_result):-
|
||||
set_value(db_my_result_set,use_result).
|
||||
db_my_result_set(store_result):-
|
||||
set_value(db_my_result_set,store_result).
|
||||
%default value
|
||||
:- db_my_result_set(store_result).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_describe/2
|
||||
%
|
||||
%
|
||||
db_datalog_describe(Relation):-
|
||||
db_datalog_describe(myddas,Relation).
|
||||
db_datalog_describe(Connection,Relation) :-
|
||||
'$error_checks'(db_datalog_describe(Relation,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_describe/3
|
||||
% db_describe/2
|
||||
% gives the results of the DESCRIBE statement
|
||||
% by backtracking
|
||||
db_describe(Relation,TableInfo) :-
|
||||
db_describe(myddas,Relation,TableInfo).
|
||||
db_describe(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$error_checks'(db_describe(Relation,Connection,_)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_my_query(SQL,ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_datalog_show_tables/1
|
||||
%
|
||||
%
|
||||
db_datalog_show_tables:-
|
||||
db_datalog_show_tables(myddas).
|
||||
db_datalog_show_tables(Connection) :-
|
||||
'$error_checks'(db_my_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_db_my_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_tables/2
|
||||
% db_show_tables/1
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
db_show_tables(Table) :-
|
||||
db_show_tables(myddas,Table).
|
||||
db_show_tables(Connection,table(Table)) :-
|
||||
'$error_checks'(db_my_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_db_my_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_database/2
|
||||
%
|
||||
%
|
||||
db_show_database(Connection,Database) :-
|
||||
'$error_checks'(db_show_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_db_my_get_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/2
|
||||
%
|
||||
%
|
||||
db_show_databases(Connection,database(Databases)) :-
|
||||
%'$error_checks'(db_show_databases(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
db_show_databases(Connection) :-
|
||||
'$error_checks'(db_my_show_databases(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_change_database/2
|
||||
%
|
||||
%
|
||||
db_change_database(Connection,Database) :-
|
||||
'$error_checks'(db_change_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_my_change_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_call_procedure/4
|
||||
% db_call_procedure/3
|
||||
% db_call_procedure(+,+,+,?)
|
||||
% Only support in MySQL 5.0 an above
|
||||
% Called procedure must return results via MyxSQL result set
|
||||
db_call_procedure(Procedure,Args,Result) :-
|
||||
db_call_procedure(myddas,Procedure,Args,Result).
|
||||
db_call_procedure(Connection,Procedure,Args,LA) :-
|
||||
'$error_checks'(db_call_procedure(Connection,Procedure,Args,LA)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
db_sql(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_sql_mode/1
|
||||
% db_my_sql_mode/2
|
||||
% Possible values : traditional,ansi,strict_trans_tables or '' (empty)
|
||||
db_sql_mode(SQLMode):-
|
||||
db_my_sql_mode(SQLMode).
|
||||
db_sql_mode(Connection,SQLMode):-
|
||||
db_my_sql_mode(Connection,SQLMode).
|
||||
|
||||
db_my_sql_mode(SQLMode):-
|
||||
db_my_sql_mode(myddas,SQLMode).
|
||||
db_my_sql_mode(Connection,SQLMode):-
|
||||
var(SQLMode),!,
|
||||
'$error_checks'(db_my_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,mysql), %must be a mysql connection
|
||||
db_sql(Connection,'SELECT @@session.sql_mode',[SQLMode]).
|
||||
db_my_sql_mode(Connection,SQLMode):-
|
||||
'$error_checks'(db_my_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,mysql), %must be a mysql connection
|
||||
'$make_atom'(['SET SESSION sql_mode=`',SQLMode,'`'],FinalSQL),
|
||||
'$write_or_not'(FinalSQL),
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(FinalSQL,_,Con,Mode,_).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
#endif /* MYDDAS_MYSQL*/
|
@ -1,45 +1,73 @@
|
||||
set( MYDDAS_YPP
|
||||
myddas.ypp
|
||||
myddas_assert_predicates.ypp
|
||||
myddas_top_level.ypp
|
||||
myddas_errors.ypp
|
||||
myddas_prolog2sql.ypp
|
||||
myddas_mysql.ypp
|
||||
myddas_postgres.ypp
|
||||
myddas_sqlite3.ypp
|
||||
myddas_util_predicates.ypp
|
||||
myddas_prolog2sql_optimizer.ypp )
|
||||
set(MYDDAS_YPP
|
||||
myddas.ypp
|
||||
myddas_assert_predicates.ypp
|
||||
myddas_top_level.ypp
|
||||
myddas_errors.ypp
|
||||
myddas_prolog2sql.ypp
|
||||
myddas_mysql.ypp
|
||||
myddas_util_predicates.ypp
|
||||
myddas_prolog2sql_optimizer.ypp)
|
||||
|
||||
set (MYDDAS_YAP "")
|
||||
set(MYDDAS_DRIVERS
|
||||
myddas_driver.ypp
|
||||
)
|
||||
|
||||
|
||||
|
||||
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
|
||||
|
||||
function(cpp_compile output filename)
|
||||
get_filename_component(base ${filename} NAME_WE)
|
||||
set(base_abs ${CMAKE_CURRENT_BINARY_DIR}/${base})
|
||||
set(outfile ${base_abs}.yap)
|
||||
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
||||
IF(MSVC)
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
else()
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
ENDIF(MSVC)
|
||||
get_filename_component(base ${filename} NAME_WE)
|
||||
set(base_abs ${CMAKE_CURRENT_BINARY_DIR}/${base})
|
||||
set(outfile ${base_abs}.yap)
|
||||
message(${outfile})
|
||||
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
||||
IF (MSVC)
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
else ()
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
ENDIF (MSVC)
|
||||
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
||||
endfunction()
|
||||
|
||||
foreach(file ${MYDDAS_YPP})
|
||||
cpp_compile( MYDDAS_YAP ${file})
|
||||
#message("outfiles=${MYDDAS_YAP}\n")
|
||||
endforeach()
|
||||
function(cpp_driver output dbms filename)
|
||||
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/myddas_${dbms}.yap)
|
||||
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
||||
message(${outfile})
|
||||
|
||||
IF (MSVC)
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} -D${dbms} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
else ()
|
||||
add_custom_command(
|
||||
OUTPUT ${outfile}
|
||||
COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile}
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}")
|
||||
ENDIF (MSVC)
|
||||
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
||||
endfunction()
|
||||
|
||||
set(MYDDAS_DBMS sqlite3 postgres odbc)
|
||||
|
||||
Add_custom_target (plmyddas ALL DEPENDS ${MYDDAS_YPP} ${MYDDAS_YAP} ) # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
foreach (file ${MYDDAS_YPP})
|
||||
cpp_compile(MYDDAS_YAP ${file})
|
||||
endforeach ()
|
||||
foreach (driver ${MYDDAS_DBMS})
|
||||
cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp)
|
||||
endforeach ()
|
||||
|
||||
install(FILES ${MYDDAS_YAP}
|
||||
DESTINATION ${libpl}
|
||||
)
|
||||
MY_add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP}
|
||||
|
||||
) # WORKING_DIRECTORY ${CMAKE_BINARY_DIR} )
|
||||
|
||||
MY_install(FILES ${MYDDAS_YAP}
|
||||
DESTINATION ${libpl}
|
||||
)
|
||||
|
@ -17,6 +17,11 @@
|
||||
|
||||
#if USE_MYDDAS
|
||||
|
||||
//:- load_foreign_files([myddas], [], init_myddas).
|
||||
|
||||
/* Initialize MYDDAS GLOBAL STRUCTURES */
|
||||
:- c_db_initialize_myddas.
|
||||
|
||||
#ifdef DEBUG
|
||||
:- yap_flag(single_var_warnings,on).
|
||||
#endif
|
||||
@ -24,6 +29,8 @@
|
||||
:- module(myddas,[
|
||||
db_open/5,
|
||||
db_open/4,
|
||||
db_open/1,
|
||||
db_open/0,
|
||||
db_close/1,
|
||||
db_close/0,
|
||||
|
||||
@ -800,8 +807,6 @@
|
||||
]).
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
:- load_foreign_files([], [], init_mysql).
|
||||
|
||||
:- use_module(myddas_mysql,[
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
@ -824,6 +829,18 @@
|
||||
db_sql_mode/2
|
||||
]).
|
||||
#endif /* MYDDAS_MYSQL */
|
||||
#ifdef MYDDAS_SQLITE3
|
||||
:- use_module(myddas_sqlite3,[
|
||||
% myddas_mysql.ypp
|
||||
c_sqlite3_connect/4,
|
||||
c_sqlite3_disconnect/1,
|
||||
c_sqlite3_query/5,
|
||||
sqlite3_result_set/1,
|
||||
c_sqlite3_number_of_fields/3
|
||||
|
||||
]).
|
||||
#endif /* MYDDAS_MYSQL */
|
||||
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$prolog2sql'/3,
|
||||
@ -858,7 +875,6 @@
|
||||
append/3
|
||||
]).
|
||||
|
||||
:- use_module(library(parameters)).
|
||||
|
||||
|
||||
|
||||
@ -867,7 +883,10 @@
|
||||
% db_open/4
|
||||
%
|
||||
|
||||
#if MYDDAS_DECLARATIONS
|
||||
#if 0 // MYDDAS_DECLARATIONS
|
||||
|
||||
:- use_module(library(parameters)).
|
||||
|
||||
:- db_open(Protocol) extra_arguments
|
||||
db=Db,
|
||||
port=Port,
|
||||
@ -955,13 +974,13 @@ i_integer(X) =:= integer(X) \/ i_var(X) \/ err(integer(X)),
|
||||
list( Protocol ) .
|
||||
|
||||
/*
|
||||
c_db_c_db_odbc_connect_connect ==> c_db_odbc_connect,
|
||||
c_db_c_odbc_connect_connect ==> c_odbc_connect,
|
||||
c_db_my_connect ==> c_db_connect,
|
||||
c_c_postgres_connect_connect ==> c_postgres_connect,
|
||||
c_sqlite3_connect ==> sqlite3.
|
||||
*/
|
||||
|
||||
%c_db_odbc_connect ==> i_atom( Password ) * i_atom( User ) *
|
||||
%c_odbc_connect ==> i_atom( Password ) * i_atom( User ) *
|
||||
|
||||
|
||||
|
||||
@ -982,7 +1001,7 @@ Protocol = odbc
|
||||
% i_atom(Db) *
|
||||
% i_atom(Socket)
|
||||
|
||||
( c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) ==
|
||||
( c^c_odbc_connect(ODBCEntry,User,Password,Handle) ==
|
||||
(Protocol = odbc)*
|
||||
-(Protocol = mysql) *
|
||||
-(Protocol = sqlite3)*
|
||||
@ -994,7 +1013,7 @@ Protocol = odbc
|
||||
-(Protocol = odbc)*
|
||||
-(Protocol = mysql) *
|
||||
-(Protocol = sqlite3)*
|
||||
(Protocol = posgrtgres) ),
|
||||
(Protocol = posgres) ),
|
||||
|
||||
% t_internet_host(Host)*
|
||||
% i_atom(User) *
|
||||
@ -1018,7 +1037,7 @@ Protocol = odbc
|
||||
/*
|
||||
integer(Handle) ==
|
||||
c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle) +
|
||||
c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) +
|
||||
c^c_odbc_connect(ODBCEntry,User,Password,Handle) +
|
||||
c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) +
|
||||
c^c_sqlite3_connect(File,User,Password,Handle).
|
||||
*/
|
||||
@ -1026,24 +1045,55 @@ db_open(Protocol) :- true.
|
||||
|
||||
#else
|
||||
|
||||
db_open:-
|
||||
db_open(myddas).
|
||||
|
||||
db_open(Protocol) :-
|
||||
'$error_checks'(db_open(Protocol)),
|
||||
get_value(Protocol,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
c_db_my_disconnect(Con)
|
||||
;ConType == postgres ->
|
||||
c_postgres_disconnect(Con)
|
||||
;ConType == sqlite3 ->
|
||||
c_sqlite3_disconnect(Con)
|
||||
;
|
||||
c_db_odbc_disconnect(Con)
|
||||
),
|
||||
set_value(Protocol,[]). % "deletes" atom
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_open/5
|
||||
% db_open/4
|
||||
%
|
||||
db_open(Interface,HostDb,User,Password):-
|
||||
db_open(Interface,myddas,HostDb,User,Password).
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
db_open(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
||||
'$error_checks'(db_open(mysql,Connection,Host/Db/Port/Socket,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
||||
set_value(Connection,Con).
|
||||
db_open(mysql,Connection,Host/Db/Port,User,Password) :-
|
||||
integer(Port),!,
|
||||
db_open(mysql,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
||||
db_open(mysql,Connection,Host/Db/Socket,User,Password) :- !,
|
||||
db_open(mysql,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
||||
db_open(mysql,Connection,Host/Db,User,Password) :-
|
||||
db_open(mysql,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_POSTGRES
|
||||
db_open(postgres,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
||||
'$error_checks'(db_open(postgres,Connection,Host/Db/Port/Socket,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
||||
set_value(Connection,Con).
|
||||
db_open(postgres,Connection,Host/Db/Port,User,Password) :-
|
||||
integer(Port),!,
|
||||
db_open(postgres,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
||||
db_open(postgres,Connection,Host/Db/Socket,User,Password) :- !,
|
||||
db_open(postgres,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
||||
db_open(postgres,Connection,Host/Db,User,Password) :-
|
||||
db_open(postgres,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_ODBC
|
||||
db_open(odbc,Connection,ODBCEntry,User,Password) :-
|
||||
'$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)),
|
||||
c_odbc_connect(ODBCEntry,User,Password,Con),
|
||||
set_value(Connection,Con).
|
||||
#endif
|
||||
#ifdef MYDDAS_SQLITE3
|
||||
db_open(sqlite3,Connection,File,User,Password) :-
|
||||
'$error_checks'(db_open(sqlite3,Connection,File,User,Password)),
|
||||
c_sqlite3_connect(File,User,Password,Con),
|
||||
set_value(Connection,Con).
|
||||
#endif
|
||||
#endif
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1070,7 +1120,7 @@ db_close(Protocol) :-
|
||||
;ConType == sqlite3 ->
|
||||
c_sqlite3_disconnect(Con)
|
||||
;
|
||||
c_db_odbc_disconnect(Con)
|
||||
c_odbc_disconnect(Con)
|
||||
),
|
||||
set_value(Protocol,[]). % "deletes" atom
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -1176,15 +1226,15 @@ db_sql(Connection,SQL,LA):-
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,ResultSet,Con,Mode,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields_in_query(SQL,Con,Arity)
|
||||
c_odbc_number_of_fields_in_query(SQL,Con,Arity)
|
||||
),
|
||||
'$make_a_list'(Arity,LA),
|
||||
( ConType == mysql ->
|
||||
!,c_db_my_row(ResultSet,Arity,LA)
|
||||
;
|
||||
'$make_a_list'(Arity,BindList),
|
||||
c_db_odbc_query(SQL,ResultSet,Arity,BindList,Con),!,
|
||||
c_db_odbc_row(ResultSet,BindList,LA)
|
||||
c_odbc_query(SQL,ResultSet,Arity,BindList,Con),!,
|
||||
c_odbc_row(ResultSet,BindList,LA)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1212,6 +1262,18 @@ db_prolog_select(Connection,LA,DbGoal):-
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,ResultSet,Con,Mode,_),
|
||||
!,c_db_my_row(ResultSet,Arity,LA)
|
||||
; ConType == postgres ->
|
||||
postgres_result_set(Mode),
|
||||
c_postgres_query(SQL,ResultSet,Con,Mode,_),
|
||||
!,c_postgres_row(ResultSet,Arity,LA)
|
||||
; ConType == odbc ->
|
||||
odbc_result_set(Mode),
|
||||
c_odbc_query(SQL,ResultSet,Con,Mode,_),
|
||||
!,c_odbc_row(ResultSet,Arity,LA)
|
||||
; ConType == sqlite3 ->
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,ResultSet,Con,Mode,_),
|
||||
!,c_sqlite3_row(ResultSet,Arity,LA)
|
||||
;
|
||||
true
|
||||
).
|
||||
@ -1233,6 +1295,18 @@ db_prolog_select_multi(Connection,DbGoalsList,ListOfResults) :-
|
||||
( ConType == mysql ->
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,ResultSet,Con,Mode,_)
|
||||
;
|
||||
ConType == postgres ->
|
||||
postgres_result_set(Mode),
|
||||
c_postgres_query(SQL,ResultSet,Con,Mode,_)
|
||||
;
|
||||
ConType == mysql ->
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,ResultSet,Con,Mode,_)
|
||||
;
|
||||
ConType == mysql ->
|
||||
odbc_result_set(Mode),
|
||||
c_odbc_query(SQL,ResultSet,Con,Mode,_)
|
||||
;
|
||||
true
|
||||
),
|
||||
@ -1285,7 +1359,7 @@ db_assert(Connection,PredName):-
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(SQL,_,_,_,Con)
|
||||
c_odbc_query(SQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1314,7 +1388,7 @@ db_create_table(Connection,TableName,FieldsInf):-
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(FinalSQL,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(FinalSQL,_,_,_,Con)
|
||||
c_odbc_query(FinalSQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1344,7 +1418,7 @@ db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf):-
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(FinalSQL,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(FinalSQL,_,_,_,Con)
|
||||
c_odbc_query(FinalSQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1377,10 +1451,24 @@ db_update(Connection,WherePred-SetPred):-
|
||||
append(SetCondition,WhereCondition,Conditions),
|
||||
'$make_atom'(['UPDATE `',TableName,'` '|Conditions],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,_,Conn,Mode,_).
|
||||
|
||||
|
||||
c_db_my_query(SQL,_,Conn,Mode,_)
|
||||
;
|
||||
ConType == mysql ->
|
||||
postgres_result_set(Mode),
|
||||
c_postgres_query(SQL,_,Conn,Mode,_)
|
||||
;
|
||||
ConType == sqlite3 ->
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,_,Conn,Mode,_)
|
||||
;
|
||||
ConType == odbc ->
|
||||
odbc_result_set(Mode),
|
||||
c_odbc_query(SQL,_,Conn,Mode,_)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_get_attributes_types/3
|
||||
% db_get_attributes_types/2
|
||||
@ -1394,7 +1482,14 @@ db_get_attributes_types(Connection,RelationName,TypesList) :-
|
||||
( ConType == mysql ->
|
||||
c_db_my_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
ConType == postgres ->
|
||||
c_postgres_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
ConType == sqlite3 ->
|
||||
c_sqlite3_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
ConType == odbc ->
|
||||
c_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
),
|
||||
Size is 2*Arity,
|
||||
'$make_a_list'(Size,TypesList),
|
||||
@ -1402,7 +1497,8 @@ db_get_attributes_types(Connection,RelationName,TypesList) :-
|
||||
( ConType == mysql ->
|
||||
c_db_my_get_attributes_types(RelationName,Con,TypesList)
|
||||
;
|
||||
c_db_odbc_get_attributes_types(RelationName,Con,TypesList)
|
||||
ConType == odbc ->
|
||||
c_odbc_get_attributes_types(RelationName,Con,TypesList)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -1424,7 +1520,7 @@ db_number_of_fields(Connection,RelationName,Arity) :-
|
||||
;ConType == sqlite3 ->
|
||||
c_sqlite3_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
c_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
@ -55,11 +55,34 @@
|
||||
db_my_result_set/1
|
||||
]).
|
||||
|
||||
|
||||
:- use_module(myddas_sqlite3,[
|
||||
sqlite3_result_set/1
|
||||
sqlite3_result_set/1,
|
||||
c_sqlite3_change_database/2,
|
||||
c_sqlite3_connect/4,
|
||||
c_sqlite3_disconnect/1,
|
||||
c_sqlite3_get_attributes_types/3,
|
||||
c_sqlite3_get_database/2,
|
||||
c_sqlite3_get_fields_properties/3,
|
||||
c_sqlite3_get_next_result_set/3,
|
||||
c_sqlite3_query/5,
|
||||
c_sqlite3_number_of_fields/3,
|
||||
c_sqlite3_row/3
|
||||
]).
|
||||
:- use_module(myddas_odbc,[
|
||||
odbc_result_set/1,
|
||||
c_odbc_change_database/2,
|
||||
c_odbc_connect/4,
|
||||
c_odbc_disconnect/1,
|
||||
c_odbc_get_attributes_types/3,
|
||||
c_odbc_get_database/2,
|
||||
c_odbc_get_fields_properties/3,
|
||||
c_odbc_get_next_result_set/3,
|
||||
c_odbc_query/5,
|
||||
c_odbc_number_of_fields/3,
|
||||
c_odbc_row/3
|
||||
]).
|
||||
|
||||
:- meta_predicate db_import(+,+,:), db_import(+,:).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_import/3
|
||||
@ -67,11 +90,11 @@
|
||||
%
|
||||
db_import(RelationName,PredName):-
|
||||
db_import(myddas,RelationName,PredName).
|
||||
db_import(Connection,RelationName,PredName) :-
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName)),
|
||||
db_import(Connection,RelationName,PredName0) :-
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName0)),
|
||||
get_value(Connection,Con),
|
||||
table_arity( Con, ConType, RelationName, Arity ),
|
||||
db_module(Module),
|
||||
strip_module(PredName0, Module, PredName),
|
||||
not c_db_check_if_exists_pred(PredName,Arity,Module),
|
||||
|
||||
R=..[relation,PredName,Arity,RelationName],
|
||||
@ -244,7 +267,7 @@ table_arity( Con, ConType, RelationName, Arity ) :-
|
||||
c_postgres_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
ConType == odbc ->
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
c_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_sqlite3_number_of_fields(RelationName,Con,Arity))
|
||||
.
|
||||
@ -257,7 +280,7 @@ table_attributes( postgres, Con, RelationName, TypesList ) :-
|
||||
c_postgres_get_attributes_types(RelationName,Con,TypesList).
|
||||
|
||||
table_attributes( odbc, Con, RelationName, TypesList ) :-
|
||||
c_db_odbc_get_attributes_types(RelationName,Con,TypesList).
|
||||
c_odbc_get_attributes_types(RelationName,Con,TypesList).
|
||||
|
||||
table_attributes( sqlite3, Con, RelationName, TypesList ) :-
|
||||
c_sqlite3_get_attributes_types(RelationName,Con,TypesList).
|
||||
@ -299,11 +322,11 @@ table_access_predicate( odbc, Con, Arity, P, LA, M,
|
||||
( P :- M:('$copy_term_nv'(P,[],G,_),
|
||||
translate(G,G,Code),
|
||||
queries_atom(Code,FinalSQL),
|
||||
c_db_odbc_result_set(Mode),
|
||||
c_odbc_result_set(Mode),
|
||||
'$write_or_not'(FinalSQL),
|
||||
c_db_odbc_query(FinalSQL,ResultSet,Con,Mode,_),
|
||||
c_odbc_query(FinalSQL,ResultSet,Con,Mode,_),
|
||||
!,
|
||||
c_db_odbc_row(ResultSet,Arity,LA)
|
||||
c_odbc_row(ResultSet,Arity,LA)
|
||||
) )).
|
||||
|
||||
table_insert( mysql, Con, RelationName, TypesList, Predicate, LA,
|
||||
@ -328,7 +351,7 @@ table_insert( sqlite3, Con, RelationName, TypesList, Predicate, LA,
|
||||
( Predicate :- myddas_assert_predicates:
|
||||
( '$get_values_for_insert'(TypesList,LA,ValuesList),
|
||||
'$make_atom'(['INSERT INTO `',RelationName,'` VALUES ('|ValuesList],SQL),
|
||||
db_my_result_set(Mode),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_sqlite3_query(SQL,_,Con,Mode,_)))
|
||||
).
|
||||
@ -374,9 +397,9 @@ table_view( odbc, Con, CopyView, CopyGoal, Arity, LA, M,
|
||||
length(BindList, Arity ),
|
||||
queries_atom(Code,FinalSQL),
|
||||
'$write_or_not'(FinalSQL),
|
||||
c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
|
||||
c_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
|
||||
!,
|
||||
c_db_my_row(ResultSet,Arity,LA) ))).
|
||||
c_odbc_row(ResultSet,Arity,LA) ))).
|
||||
|
||||
table_view( sqlite3, Con, CopyView, CopyGoal, Arity, LA, M,
|
||||
( CopyView :-
|
||||
@ -387,4 +410,4 @@ table_view( sqlite3, Con, CopyView, CopyGoal, Arity, LA, M,
|
||||
'$write_or_not'(FinalSQL),
|
||||
c_sqlite3_query(FinalSQL,ResultSet,Con,_,_),
|
||||
!,
|
||||
c_db_my_row(ResultSet,Arity,LA) ))).
|
||||
c_sqlite3_row(ResultSet,Arity,LA) ))).
|
||||
|
249
packages/myddas/pl/myddas_driver.ypp
Normal file
249
packages/myddas/pl/myddas_driver.ypp
Normal file
@ -0,0 +1,249 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_mysql.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: MySQL Predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef sqlite3
|
||||
#undef sqlite3
|
||||
#define DBMS(x) sqlite3_##x
|
||||
#define c_DBMS(x) c_sqlite3_##x
|
||||
#define NAME() 'Yapsqlite3'
|
||||
#define MODULE() myddas_sqlite3
|
||||
#define INIT() init_sqlite3
|
||||
#elif defined( odbc )
|
||||
#undef odbc
|
||||
#define DBMS(x) odbc_##x
|
||||
#define c_DBMS(x) c_odbc_##x
|
||||
#define NAME() 'Yapodbc'
|
||||
#define MODULE() myddas_odbc
|
||||
#define INIT() init_odbc
|
||||
#elif defined( postgres )
|
||||
#undef postgres
|
||||
#define DBMS(x) postgres_##x
|
||||
#define c_DBMS(x) c_postgres_##x
|
||||
#define NAME() 'Yappostgres'
|
||||
#define MODULE() myddas_postgres
|
||||
#define INIT() init_odbc
|
||||
#endif
|
||||
|
||||
#if defined(DBMS)
|
||||
|
||||
:- module(MODULE(),[
|
||||
DBMS(result_set)/1,
|
||||
DBMS(datalog_describe)/1,
|
||||
DBMS(datalog_describe)/2,
|
||||
DBMS(describe)/3,
|
||||
DBMS(describe)/2,
|
||||
DBMS(datalog_show_tables)/1,
|
||||
DBMS(datalog_show_tables)/0,
|
||||
DBMS(show_tables)/2,
|
||||
DBMS(show_tables)/1,
|
||||
DBMS(show_database)/2,
|
||||
DBMS(show_databases)/2,
|
||||
DBMS(show_databases)/1,
|
||||
DBMS(change_database)/2,
|
||||
DBMS(call_procedure)/4,
|
||||
DBMS(call_procedure)/3,
|
||||
c_DBMS(change_database)/2,
|
||||
c_DBMS(connect)/4,
|
||||
c_DBMS(disconnect)/1,
|
||||
c_DBMS(get_attributes_types)/3,
|
||||
c_DBMS(get_database)/2,
|
||||
c_DBMS(get_fields_properties)/3,
|
||||
c_DBMS(get_next_result_set)/3,
|
||||
c_DBMS(query)/5,
|
||||
c_DBMS(number_of_fields)/3,
|
||||
c_DBMS(row)/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_sql/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$get_value'/2,
|
||||
'$make_atom'/2,
|
||||
'$make_atom_args'/2,
|
||||
'$make_a_list'/2,
|
||||
'$write_or_not'/1
|
||||
]).
|
||||
:- load_foreign_files( [NAME()], [], INIT()).
|
||||
|
||||
%--------------------------------------------------------
|
||||
% Public Predicates
|
||||
%--------------------------------------------------------
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(result_set)/1
|
||||
%
|
||||
%
|
||||
DBMS(result_set)(X):-
|
||||
var(X),!,
|
||||
get_value(DBMS(result_set),X).
|
||||
DBMS(result_set)(use_result):-
|
||||
set_value(DBMS(result_set),use_result).
|
||||
DBMS(result_set)(store_result):-
|
||||
set_value(DBMS(result_set),store_result).
|
||||
%default value
|
||||
:- DBMS(result_set)(use_result).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(describe)/2
|
||||
%
|
||||
%
|
||||
DBMS(datalog_describe)(Relation):-
|
||||
DBMS(datalog_describe)(myddas,Relation).
|
||||
DBMS(datalog_describe)(Connection,Relation) :-
|
||||
'$error_checks'(DBMS(datalog_describe)(Relation,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
DBMS(result_set)(Mode),
|
||||
c_DBMS(query)(SQL,ResultSet,Conn,Mode,_),
|
||||
c_DBMS(table_write)(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(describe)/3
|
||||
% DBMS(describe)/2
|
||||
% gives the results of the DESCRIBE statement
|
||||
% by backtracking
|
||||
DBMS(describe)(Relation,TableInfo) :-
|
||||
DBMS(describe)(myddas,Relation,TableInfo).
|
||||
DBMS(describe)(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$error_checks'(DBMS(describe)(Relation,Connection,_)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
DBMS(result_set)(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_DBMS(query)(SQL,ResultSet,Conn,Mode,_),
|
||||
!,
|
||||
c_DBMS(row)(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(datalog_show_tables)/1
|
||||
%
|
||||
%
|
||||
DBMS(datalog_show_tables):-
|
||||
DBMS(datalog_show_tables)(myddas).
|
||||
DBMS(datalog_show_tables)(Connection) :-
|
||||
'$error_checks'(DBMS(show_tables)(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
DBMS(result_set)(Mode),
|
||||
'$write_or_not'('.tables'),
|
||||
c_DBMS(query)('.tables',ResultSet,Conn,Mode,_),
|
||||
c_DBMS(table_write)(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(show_tables)/2
|
||||
% DBMS(show_tables)/1
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
DBMS(show_tables)(Table) :-
|
||||
DBMS(show_tables)(myddas,Table).
|
||||
DBMS(show_tables)(Connection,table(Table)) :-
|
||||
'$error_checks'(DBMS(show_tables)(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
DBMS(result_set)(Mode),
|
||||
'$write_or_not'('.tables'),
|
||||
c_DBMS(query)('.tables',ResultSet,Conn,Mode,_),
|
||||
!,c_DBMS(row)(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(show_database)/2
|
||||
%
|
||||
%
|
||||
DBMS(show_database)(Connection,Database) :-
|
||||
'$error_checks'(DBMS(show_database)(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_DBMS(get_database)(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(show_databases)/2
|
||||
%
|
||||
%
|
||||
DBMS(show_databases)(Connection,database(Databases)) :-
|
||||
%'$error_checks'(DBMS(show_databases)(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
DBMS(result_set)(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_DBMS(query)('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_DBMS(row)(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(show_databases)/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
DBMS(show_databases)(Connection) :-
|
||||
'$error_checks'(DBMS(show_databases)(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
DBMS(result_set)(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_DBMS(query)('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_DBMS(table_write)(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(change_database)/2
|
||||
%
|
||||
%
|
||||
DBMS(change_database)(Connection,Database) :-
|
||||
'$error_checks'(DBMS(change_database)(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_DBMS(change_database)(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% DBMS(call_procedure)/4
|
||||
% DBMS(call_procedure)/3
|
||||
% DBMS(call_procedure)(+,+,+,?)
|
||||
% Only support in MySQL 5.0 an above
|
||||
% Called procedure must return results via MySQL result set
|
||||
DBMS(call_procedure)(Procedure,Args,Result) :-
|
||||
DBMS(call_procedure)(myddas,Procedure,Args,Result).
|
||||
DBMS(call_procedure)(Connection,Procedure,Args,LA) :-
|
||||
'$error_checks'(DBMS(call_procedure)(Connection,Procedure,Args,LA)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
DBMS(sql)(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
#endif /* MYDDAS_DBMS */
|
@ -138,9 +138,11 @@
|
||||
Pred =.. [_|_],
|
||||
DbGoal =.. [_|_].
|
||||
%'$check_list_on_list'(PredArgs,DbGoalArgs).
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName)) :- !,
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName0)) :- !,
|
||||
atom(Connection),
|
||||
strip_module(PredName0, Module, PredName),
|
||||
atom(RelationName),
|
||||
atom(Module),
|
||||
atom(PredName).
|
||||
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
|
||||
atom(Connection),
|
||||
|
@ -55,6 +55,9 @@
|
||||
]).
|
||||
|
||||
|
||||
:- load_foreign_files( ['Yapmysql'], [], init_mysql).
|
||||
|
||||
|
||||
%--------------------------------------------------------
|
||||
% Public Predicates
|
||||
%--------------------------------------------------------
|
||||
|
@ -19,21 +19,20 @@ if (PostgreSQL_FOUND)
|
||||
# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
|
||||
# PostgreSQL_LIBRARIES - The PostgreSQL libraries.
|
||||
add_library (Yappostgres SHARED ${YAPPOSTGRES_SOURCES})
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} -DMYDDAS_POSTGRES=1 PARENT_SCOPE)
|
||||
set_property( DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS MYDDAS_POSTGRES=1 )
|
||||
|
||||
target_link_libraries(Yappostgres libYap ${PostgreSQL_LIBRARIES})
|
||||
include_directories (${PostgreSQL_INCLUDE_DIRS} ..)
|
||||
set_target_properties (Yappostgres PROPERTIES
|
||||
set_target_properties (Yappostgres PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ON
|
||||
VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}"
|
||||
SOVERSION ${SO_MAJOR}
|
||||
PREFIX ""
|
||||
)
|
||||
|
||||
install(TARGETS Yappostgres
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
ARCHIVE DESTINATION ${libdir}
|
||||
list (APPEND MYDDAS_FLAGS -DMYDDAS_POSTGRES=1)
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE)
|
||||
set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
-DMYDDAS_POSTGRES=1)
|
||||
|
||||
install(TARGETS Yappostgres
|
||||
LIBRARY DESTINATION ${dlls}
|
||||
ARCHIVE DESTINATION ${dlls}
|
||||
)
|
||||
else()
|
||||
add_definitions (-DMYDDAS_PostgreSQL=0)
|
||||
endif (PostgreSQL_FOUND)
|
||||
|
@ -900,3 +900,31 @@ void Yap_InitBackMYDDAS_PGPreds(void)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void init_pg( void )
|
||||
{
|
||||
Yap_InitMYDDAS_PGPreds();
|
||||
Yap_InitBackMYDDAS_PGPreds();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int WINAPI win_pg(HANDLE hinst, DWORD reason, LPVOID reserved);
|
||||
|
||||
int WINAPI win_pg(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||
switch (reason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
@ -6,7 +6,6 @@ set( YAPSQLITE3_SOURCES
|
||||
)
|
||||
|
||||
set( YAPSQLITE3_ANDROID_SOURCES
|
||||
Android/jni/sqlite/ALog-priv.h
|
||||
Android/jni/sqlite/JNIHelp.cpp
|
||||
Android/jni/sqlite/JniConstants.cpp
|
||||
Android/jni/sqlite/android_database_SQLiteCommon.cpp
|
||||
@ -14,37 +13,35 @@ Android/jni/sqlite/android_database_SQLiteCommon.h
|
||||
Android/jni/sqlite/android_database_SQLiteConnection.cpp
|
||||
Android/jni/sqlite/android_database_SQLiteDebug.cpp
|
||||
Android/jni/sqlite/android_database_SQLiteGlobal.cpp
|
||||
Android/jni/sqlite/nativehelper/JNIHelp.h
|
||||
Android/jni/sqlite/nativehelper/JniConstants.h
|
||||
Android/jni/sqlite/nativehelper/ScopedLocalRef.h
|
||||
Android/jni/sqlite/nativehelper/jni.h
|
||||
)
|
||||
|
||||
#sqlite3 is now in the system
|
||||
|
||||
set (SQLITE3_FOUND ON PARENT_SCOPE)
|
||||
macro_log_feature (SQLITE3_FOUND "Sqlite3"
|
||||
"Sqlite3 Data-Base "
|
||||
"http://www.sqlite3ql.org" FALSE)
|
||||
set (SQLITE3_FOUND ON CACHE PRIVATE "")
|
||||
message (
|
||||
" * Sqlite3 Data-Base (http://www.sqlite3ql.org) is distributed with
|
||||
MYDDAS" )
|
||||
|
||||
include_directories ( .. . Android/jni/sqlite Android/jni/sqlite/nativehelper)
|
||||
|
||||
include_directories (${SQLITE3_INCLUDE_DIRECTORIES} .. . Android/jni/sqlite Android/jni/sqlite/nativehelper)
|
||||
list (APPEND MYDDAS_FLAGS -DMYDDAS_SQLITE3=1)
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE)
|
||||
set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
|
||||
-DMYDDAS_SQLITE3=1)
|
||||
|
||||
set (MYDDAS_FLAGS ${MYDDAS_FLAGS} -DMYDDAS_SQLITE3=1 PARENT_SCOPE)
|
||||
set_property( DIRECTORY .. APPEND PROPERTY COMPILE_DEFINITIONS MYDDAS_SQLITE3=1 )
|
||||
if (ANDROID)
|
||||
add_external (Yapsqlite3 ${YAPSQLITE3_SOURCES} ${YAPSQLITE3_ANDROID_SOURCES})
|
||||
else()
|
||||
add_component (Yapsqlite3 ${YAPSQLITE3_SOURCES} )
|
||||
|
||||
if (YAP_SINGLE_FILE)
|
||||
add_library (Yapsqlite3 OBJECT ${YAPSQLITE3_SOURCES} ${YAPSQLITE3_ANDROID_SOURCES})
|
||||
else(YAP_SINGLE_FILE)
|
||||
add_library (Yapsqlite3 SHARED ${YAPSQLITE3_SOURCES})
|
||||
target_link_libraries(Yapsqlite3 libYap)
|
||||
#xtarget_link_libraries(Yapsqlite3 libYap)
|
||||
set_target_properties (Yapsqlite3 PROPERTIES
|
||||
VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}"
|
||||
SOVERSION ${SO_MAJOR}
|
||||
PREFIX ""
|
||||
)
|
||||
|
||||
install(TARGETS Yapsqlite3
|
||||
LIBRARY DESTINATION ${libdir}
|
||||
ARCHIVE DESTINATION ${libdir}
|
||||
)
|
||||
endif(YAP_SINGLE_FILE)
|
||||
# install(TARGETS Yapsqlite3
|
||||
# LIBRARY DESTINATION ${dlls}
|
||||
# ARCHIVE DESTINATION ${dlls}
|
||||
# )
|
||||
endif()
|
||||
|
||||
|
0
packages/myddas/sqlite3/hh
Normal file
0
packages/myddas/sqlite3/hh
Normal file
@ -60,7 +60,6 @@ static Int null_id = 0;
|
||||
typedef struct result_set {
|
||||
sqlite3_stmt *stmt;
|
||||
sqlite3 *db;
|
||||
char **res_set;
|
||||
int nrows;
|
||||
int length;
|
||||
} resultSet;
|
||||
@ -298,13 +297,12 @@ static Int c_sqlite3_query(USES_REGS1) {
|
||||
start = myddas_stat_init_query(db);
|
||||
#endif
|
||||
|
||||
|
||||
// printf("Query %s\n", sql);
|
||||
/* Send query to server and process it */
|
||||
if (strcmp(mode, "store_result") != 0) {
|
||||
// Leave data for extraction
|
||||
printf(" SQL 0: %s\n", sql);
|
||||
CALL_SQLITE(prepare_v2(db, sql, -1, &stmt, NULL));
|
||||
rs->stmt = stmt;
|
||||
rs->res_set = NULL;
|
||||
rs->nrows = -1;
|
||||
rs->length = sqlite3_column_count(stmt);
|
||||
if (!Yap_unify(arg_arity, MkIntegerTerm(rs->length))) {
|
||||
@ -313,44 +311,10 @@ static Int c_sqlite3_query(USES_REGS1) {
|
||||
}
|
||||
if (!Yap_unify(arg_result_set, MkAddressTerm(rs))) {
|
||||
free(rs);
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
// construct an intermediate table, res_set
|
||||
char **res_set;
|
||||
char *msg;
|
||||
int nrows;
|
||||
|
||||
CALL_SQLITE(get_table(db, sql, &res_set, &nrows, &length, &msg));
|
||||
|
||||
// end = myddas_stat_end_query( start );
|
||||
if (res_set == NULL) {
|
||||
#ifdef DEBUG
|
||||
printf("Empty Query!\n");
|
||||
#endif
|
||||
return TRUE;
|
||||
}
|
||||
// INSERT statements don't return any res_set
|
||||
if (nrows == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
if (!Yap_unify(arg_arity, MkIntegerTerm(nrows))) {
|
||||
free(rs);
|
||||
sqlite3_free_table(res_set);
|
||||
return FALSE;
|
||||
}
|
||||
rs->stmt = NULL;
|
||||
rs->res_set = res_set;
|
||||
rs->nrows = nrows;
|
||||
rs->length = length;
|
||||
if (!Yap_unify(arg_result_set, MkAddressTerm(rs))) {
|
||||
free(rs);
|
||||
sqlite3_free_table(res_set);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static Int c_sqlite3_number_of_fields(USES_REGS1) {
|
||||
@ -367,7 +331,6 @@ static Int c_sqlite3_number_of_fields(USES_REGS1) {
|
||||
sprintf(sql, "SELECT * FROM `%s`", relation);
|
||||
|
||||
/* executar a query SQL */
|
||||
printf(" SQL 1: %s\n", sql);
|
||||
CALL_SQLITE(prepare_v2(db, sql, -1, &stmt, NULL));
|
||||
|
||||
int fields = sqlite3_column_count(stmt);
|
||||
@ -395,7 +358,6 @@ static Int c_sqlite3_get_attributes_types(USES_REGS1) {
|
||||
sprintf(sql, "SELECT * FROM `%s`", relation);
|
||||
|
||||
/* executar a query SQL */
|
||||
printf(" SQL 3: %s\n", sql);
|
||||
CALL_SQLITE(prepare_v2(db, sql, -1, &stmt, NULL));
|
||||
|
||||
int fields = sqlite3_column_count(stmt);
|
||||
@ -534,7 +496,6 @@ static Int c_sqlite3_get_next_result_set(USES_REGS1) {
|
||||
if (!rs)
|
||||
return FALSE;
|
||||
rs->stmt = stmt;
|
||||
rs->res_set = NULL;
|
||||
rs->nrows = -1;
|
||||
rs->length = sqlite3_column_count(stmt);
|
||||
rs->db = db;
|
||||
@ -603,33 +564,7 @@ static Int c_sqlite3_row(USES_REGS1) {
|
||||
list = arg_list_args;
|
||||
arity = IntegerOfTerm(arg_arity);
|
||||
sqlite3 *db = res_set->db;
|
||||
if (res_set->stmt == NULL) {
|
||||
CACHE_REGS
|
||||
Int indx = IntegerOfTerm(EXTRA_CBACK_ARG(3, 2));
|
||||
Int rc = true;
|
||||
// data needs to be copied to Prolog
|
||||
// row by row
|
||||
#ifdef MYDDAS_STATS
|
||||
MYDDAS_STATS_TIME diff;
|
||||
|
||||
MYDDAS_STATS_INITIALIZE_TIME_STRUCT(diff, time_copy);
|
||||
#endif
|
||||
while (indx / arity < res_set->nrows) {
|
||||
for (i = 0; i < arity; i++) {
|
||||
/* Ts -> List */
|
||||
const char *field = res_set->res_set[indx++];
|
||||
head = HeadOfTerm(list);
|
||||
list = TailOfTerm(list);
|
||||
rc = (rc && Yap_unify(head, cvt(field)));
|
||||
}
|
||||
if (rc)
|
||||
return rc;
|
||||
}
|
||||
#ifdef MYDDAS_STATS
|
||||
myddas_stat_transfer_query(diff);
|
||||
#endif
|
||||
cut_fail();
|
||||
}
|
||||
// busy-waiting
|
||||
int res;
|
||||
while ((res = sqlite3_step(res_set->stmt)) == SQLITE_BUSY)
|
||||
@ -725,3 +660,31 @@ void Yap_InitMYDDAS_SQLITE3Preds(void) {}
|
||||
void Yap_InitBackMYDDAS_SQLITE3Preds(void) {}
|
||||
|
||||
#endif
|
||||
|
||||
void init_sqlite3( void )
|
||||
{
|
||||
Yap_InitMYDDAS_SQLITE3Preds();
|
||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
int WINAPI win_sqlite3(HANDLE hinst, DWORD reason, LPVOID reserved);
|
||||
|
||||
int WINAPI win_sqlite3(HANDLE hinst, DWORD reason, LPVOID reserved) {
|
||||
switch (reason) {
|
||||
case DLL_PROCESS_ATTACH:
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
case DLL_THREAD_ATTACH:
|
||||
break;
|
||||
case DLL_THREAD_DETACH:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user