mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-13 14:59:32 -06:00
drop the SG library completely.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
lib_LTLIBRARIES = libgu.la libpgf.la libsg.la
|
||||
lib_LTLIBRARIES = libgu.la libpgf.la
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libgu.pc libpgf.pc libsg.pc
|
||||
pkgconfig_DATA = libgu.pc libpgf.pc
|
||||
|
||||
configincludedir = $(libdir)/libgu/include
|
||||
|
||||
@@ -37,10 +37,6 @@ pgfinclude_HEADERS = \
|
||||
pgf/pgf.h \
|
||||
pgf/data.h
|
||||
|
||||
sgincludedir=$(includedir)/sg
|
||||
sginclude_HEADERS = \
|
||||
sg/sg.h
|
||||
|
||||
libgu_la_SOURCES = \
|
||||
gu/assert.c \
|
||||
gu/bits.c \
|
||||
@@ -92,12 +88,6 @@ libpgf_la_SOURCES = \
|
||||
libpgf_la_LDFLAGS = -no-undefined
|
||||
libpgf_la_LIBADD = libgu.la
|
||||
|
||||
libsg_la_SOURCES = \
|
||||
sg/sqlite3Btree.c \
|
||||
sg/sg.c
|
||||
libsg_la_LDFLAGS = -no-undefined
|
||||
libsg_la_LIBADD = libgu.la libpgf.la
|
||||
|
||||
bin_PROGRAMS =
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign subdir-objects dist-bzip2
|
||||
@@ -105,5 +95,4 @@ ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
EXTRA_DIST = \
|
||||
libgu.pc.in \
|
||||
libpgf.pc.in \
|
||||
libsg.pc.in
|
||||
libpgf.pc.in
|
||||
|
||||
@@ -58,7 +58,6 @@ AC_CONFIG_LINKS(pgf/lightning/asm.h:$cpu_dir/asm.h dnl
|
||||
AC_CONFIG_FILES([Makefile
|
||||
libgu.pc
|
||||
libpgf.pc
|
||||
libsg.pc
|
||||
])
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -918,94 +918,6 @@ pgf_read_expr(GuIn* in, GuPool* pool, GuPool* tmp_pool, GuExn* err)
|
||||
return expr;
|
||||
}
|
||||
|
||||
PGF_API int
|
||||
pgf_read_expr_tuple(GuIn* in,
|
||||
size_t n_exprs, PgfExpr exprs[],
|
||||
GuPool* pool, GuExn* err)
|
||||
{
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
PgfExprParser* parser =
|
||||
pgf_new_parser(in, pgf_expr_parser_in_getc, pool, tmp_pool, err);
|
||||
if (parser->token_tag != PGF_TOKEN_LTRIANGLE)
|
||||
goto fail;
|
||||
pgf_expr_parser_token(parser, false);
|
||||
for (size_t i = 0; i < n_exprs; i++) {
|
||||
if (i > 0) {
|
||||
if (parser->token_tag != PGF_TOKEN_COMMA)
|
||||
goto fail;
|
||||
pgf_expr_parser_token(parser, false);
|
||||
}
|
||||
|
||||
exprs[i] = pgf_expr_parser_expr(parser, false);
|
||||
if (gu_variant_is_null(exprs[i]))
|
||||
goto fail;
|
||||
}
|
||||
if (parser->token_tag != PGF_TOKEN_RTRIANGLE)
|
||||
goto fail;
|
||||
pgf_expr_parser_token(parser, false);
|
||||
if (parser->token_tag != PGF_TOKEN_EOF)
|
||||
goto fail;
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
return 1;
|
||||
|
||||
fail:
|
||||
gu_pool_free(tmp_pool);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PGF_API GuSeq*
|
||||
pgf_read_expr_matrix(GuIn* in,
|
||||
size_t n_exprs,
|
||||
GuPool* pool, GuExn* err)
|
||||
{
|
||||
GuPool* tmp_pool = gu_new_pool();
|
||||
PgfExprParser* parser =
|
||||
pgf_new_parser(in, pgf_expr_parser_in_getc, pool, tmp_pool, err);
|
||||
if (parser->token_tag != PGF_TOKEN_LTRIANGLE)
|
||||
goto fail;
|
||||
pgf_expr_parser_token(parser, false);
|
||||
|
||||
GuBuf* buf = gu_new_buf(PgfExpr, pool);
|
||||
|
||||
if (parser->token_tag != PGF_TOKEN_RTRIANGLE) {
|
||||
for (;;) {
|
||||
PgfExpr* exprs = gu_buf_extend_n(buf, n_exprs);
|
||||
|
||||
for (size_t i = 0; i < n_exprs; i++) {
|
||||
if (i > 0) {
|
||||
if (parser->token_tag != PGF_TOKEN_COMMA)
|
||||
goto fail;
|
||||
pgf_expr_parser_token(parser, false);
|
||||
}
|
||||
|
||||
exprs[i] = pgf_expr_parser_expr(parser, false);
|
||||
if (gu_variant_is_null(exprs[i]))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (parser->token_tag != PGF_TOKEN_SEMI)
|
||||
break;
|
||||
|
||||
pgf_expr_parser_token(parser, false);
|
||||
}
|
||||
|
||||
if (parser->token_tag != PGF_TOKEN_RTRIANGLE)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
pgf_expr_parser_token(parser, false);
|
||||
if (parser->token_tag != PGF_TOKEN_EOF)
|
||||
goto fail;
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
return gu_buf_data_seq(buf);
|
||||
|
||||
fail:
|
||||
gu_pool_free(tmp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PGF_API PgfType*
|
||||
pgf_read_type(GuIn* in, GuPool* pool, GuPool* tmp_pool, GuExn* err)
|
||||
{
|
||||
|
||||
@@ -170,15 +170,6 @@ pgf_expr_unmeta(PgfExpr expr);
|
||||
PGF_API_DECL PgfExpr
|
||||
pgf_read_expr(GuIn* in, GuPool* pool, GuPool* tmp_pool, GuExn* err);
|
||||
|
||||
PGF_API_DECL int
|
||||
pgf_read_expr_tuple(GuIn* in,
|
||||
size_t n_exprs, PgfExpr exprs[],
|
||||
GuPool* pool, GuExn* err);
|
||||
|
||||
PGF_API_DECL GuSeq*
|
||||
pgf_read_expr_matrix(GuIn* in, size_t n_exprs,
|
||||
GuPool* pool, GuExn* err);
|
||||
|
||||
PGF_API_DECL PgfType*
|
||||
pgf_read_type(GuIn* in, GuPool* pool, GuPool* tmp_pool, GuExn* err);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +0,0 @@
|
||||
#ifndef SG_SG_H_
|
||||
#define SG_SG_H_
|
||||
|
||||
typedef long long int SgId;
|
||||
|
||||
#include <gu/exn.h>
|
||||
#include <pgf/pgf.h>
|
||||
|
||||
typedef struct SgSG SgSG;
|
||||
|
||||
SgSG*
|
||||
sg_open(const char *filename, GuExn* err);
|
||||
|
||||
void
|
||||
sg_close(SgSG *sg, GuExn* err);
|
||||
|
||||
void
|
||||
sg_begin_trans(SgSG* sg, GuExn* err);
|
||||
|
||||
void
|
||||
sg_commit(SgSG* sg, GuExn* err);
|
||||
|
||||
void
|
||||
sg_rollback(SgSG* sg, GuExn* err);
|
||||
|
||||
|
||||
SgId
|
||||
sg_insert_expr(SgSG *sg, PgfExpr expr, int wrFlag, GuExn* err);
|
||||
|
||||
PgfExpr
|
||||
sg_get_expr(SgSG *sg, SgId key, GuPool* out_pool, GuExn* err);
|
||||
|
||||
typedef struct SgQueryExprResult SgQueryExprResult;
|
||||
|
||||
SgQueryExprResult*
|
||||
sg_query_expr(SgSG *sg, PgfExpr expr, GuPool* pool, GuExn* err);
|
||||
|
||||
PgfExpr
|
||||
sg_query_next(SgSG *sg, SgQueryExprResult* ctxt, SgId* pKey, GuPool* pool, GuExn* err);
|
||||
|
||||
void
|
||||
sg_query_close(SgSG* sg, SgQueryExprResult* ctxt, GuExn* err);
|
||||
|
||||
void
|
||||
sg_update_fts_index(SgSG* sg, PgfPGF* pgf, GuExn* err);
|
||||
|
||||
GuSeq*
|
||||
sg_query_linearization(SgSG *sg, GuString tok, GuPool* pool, GuExn* err);
|
||||
|
||||
|
||||
typedef PgfExpr SgTriple[3];
|
||||
|
||||
SgId
|
||||
sg_insert_triple(SgSG *sg, SgTriple triple, GuExn* err);
|
||||
|
||||
int
|
||||
sg_get_triple(SgSG *sg, SgId key, SgTriple triple,
|
||||
GuPool* out_pool, GuExn* err);
|
||||
|
||||
typedef struct SgTripleResult SgTripleResult;
|
||||
|
||||
SgTripleResult*
|
||||
sg_query_triple(SgSG *sg, SgTriple triple, GuExn* err);
|
||||
|
||||
int
|
||||
sg_triple_result_fetch(SgTripleResult* tres, SgId* pKey, SgTriple triple,
|
||||
GuPool* out_pool, GuExn* err);
|
||||
|
||||
void
|
||||
sg_triple_result_get_query(SgTripleResult* tres, SgTriple triple);
|
||||
|
||||
void
|
||||
sg_triple_result_close(SgTripleResult* tres, GuExn* err);
|
||||
|
||||
typedef struct SgQueryResult SgQueryResult;
|
||||
|
||||
SgQueryResult*
|
||||
sg_query(SgSG *sg, size_t n_triples, SgTriple* triples, GuExn* err);
|
||||
|
||||
size_t
|
||||
sg_query_result_columns(SgQueryResult* qres);
|
||||
|
||||
int
|
||||
sg_query_result_fetch_columns(SgQueryResult* qres, PgfExpr* res,
|
||||
GuPool* out_pool, GuExn* err);
|
||||
|
||||
PgfExpr
|
||||
sg_query_result_fetch_expr(SgQueryResult* qres, PgfExpr expr,
|
||||
GuPool* out_pool, GuExn* err);
|
||||
|
||||
void
|
||||
sg_query_result_close(SgQueryResult* qres, GuExn* err);
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,705 +0,0 @@
|
||||
/*
|
||||
** 2001 September 15
|
||||
**
|
||||
** The author disclaims copyright to this source code. In place of
|
||||
** a legal notice, here is a blessing:
|
||||
**
|
||||
** May you do good and not evil.
|
||||
** May you find forgiveness for yourself and forgive others.
|
||||
** May you share freely, never taking more than you give.
|
||||
**
|
||||
*************************************************************************
|
||||
** This header file defines the interface that the sqlite B-Tree file
|
||||
** subsystem. See comments in the source code for a detailed description
|
||||
** of what each interface routine does.
|
||||
*/
|
||||
#ifndef _BTREE_H_
|
||||
#define _BTREE_H_
|
||||
|
||||
/*
|
||||
** The SQLITE_THREADSAFE macro must be defined as 0, 1, or 2.
|
||||
** 0 means mutexes are permanently disable and the library is never
|
||||
** threadsafe. 1 means the library is serialized which is the highest
|
||||
** level of threadsafety. 2 means the library is multithreaded - multiple
|
||||
** threads can use SQLite as long as no two threads try to use the same
|
||||
** database connection at the same time.
|
||||
**
|
||||
** Older versions of SQLite used an optional THREADSAFE macro.
|
||||
** We support that for legacy.
|
||||
*/
|
||||
#if !defined(SQLITE_THREADSAFE)
|
||||
# if defined(THREADSAFE)
|
||||
# define SQLITE_THREADSAFE THREADSAFE
|
||||
# else
|
||||
# define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** CAPI3REF: 64-Bit Integer Types
|
||||
** KEYWORDS: sqlite_int64 sqlite_uint64
|
||||
**
|
||||
** Because there is no cross-platform way to specify 64-bit integer types
|
||||
** SQLite includes typedefs for 64-bit signed and unsigned integers.
|
||||
**
|
||||
** The sqlite3_int64 and sqlite3_uint64 are the preferred type definitions.
|
||||
** The sqlite_int64 and sqlite_uint64 types are supported for backwards
|
||||
** compatibility only.
|
||||
**
|
||||
** ^The sqlite3_int64 and sqlite_int64 types can store integer values
|
||||
** between -9223372036854775808 and +9223372036854775807 inclusive. ^The
|
||||
** sqlite3_uint64 and sqlite_uint64 types can store integer values
|
||||
** between 0 and +18446744073709551615 inclusive.
|
||||
*/
|
||||
#ifdef SQLITE_INT64_TYPE
|
||||
typedef SQLITE_INT64_TYPE sqlite_int64;
|
||||
typedef unsigned SQLITE_INT64_TYPE sqlite_uint64;
|
||||
#elif defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 sqlite_int64;
|
||||
typedef unsigned __int64 sqlite_uint64;
|
||||
#else
|
||||
typedef long long int sqlite_int64;
|
||||
typedef unsigned long long int sqlite_uint64;
|
||||
#endif
|
||||
typedef sqlite_int64 sqlite3_int64;
|
||||
typedef sqlite_uint64 sqlite3_uint64;
|
||||
|
||||
/*
|
||||
** Integers of known sizes. These typedefs might change for architectures
|
||||
** where the sizes very. Preprocessor macros are available so that the
|
||||
** types can be conveniently redefined at compile-type. Like this:
|
||||
**
|
||||
** cc '-DUINTPTR_TYPE=long long int' ...
|
||||
*/
|
||||
#ifndef UINT32_TYPE
|
||||
# ifdef HAVE_UINT32_T
|
||||
# define UINT32_TYPE uint32_t
|
||||
# else
|
||||
# define UINT32_TYPE unsigned int
|
||||
# endif
|
||||
#endif
|
||||
#ifndef UINT16_TYPE
|
||||
# ifdef HAVE_UINT16_T
|
||||
# define UINT16_TYPE uint16_t
|
||||
# else
|
||||
# define UINT16_TYPE unsigned short int
|
||||
# endif
|
||||
#endif
|
||||
#ifndef INT16_TYPE
|
||||
# ifdef HAVE_INT16_T
|
||||
# define INT16_TYPE int16_t
|
||||
# else
|
||||
# define INT16_TYPE short int
|
||||
# endif
|
||||
#endif
|
||||
#ifndef UINT8_TYPE
|
||||
# ifdef HAVE_UINT8_T
|
||||
# define UINT8_TYPE uint8_t
|
||||
# else
|
||||
# define UINT8_TYPE unsigned char
|
||||
# endif
|
||||
#endif
|
||||
#ifndef INT8_TYPE
|
||||
# ifdef HAVE_INT8_T
|
||||
# define INT8_TYPE int8_t
|
||||
# else
|
||||
# define INT8_TYPE signed char
|
||||
# endif
|
||||
#endif
|
||||
#ifndef LONGDOUBLE_TYPE
|
||||
# define LONGDOUBLE_TYPE long double
|
||||
#endif
|
||||
typedef sqlite_int64 i64; /* 8-byte signed integer */
|
||||
typedef sqlite_uint64 u64; /* 8-byte unsigned integer */
|
||||
typedef UINT32_TYPE u32; /* 4-byte unsigned integer */
|
||||
typedef UINT16_TYPE u16; /* 2-byte unsigned integer */
|
||||
typedef INT16_TYPE i16; /* 2-byte signed integer */
|
||||
typedef UINT8_TYPE u8; /* 1-byte unsigned integer */
|
||||
typedef INT8_TYPE i8; /* 1-byte signed integer */
|
||||
|
||||
/* TODO: This definition is just included so other modules compile. It
|
||||
** needs to be revisited.
|
||||
*/
|
||||
#define SQLITE_N_BTREE_META 16
|
||||
|
||||
/*
|
||||
** If defined as non-zero, auto-vacuum is enabled by default. Otherwise
|
||||
** it must be turned on for each database using "PRAGMA auto_vacuum = 1".
|
||||
*/
|
||||
#ifndef SQLITE_DEFAULT_AUTOVACUUM
|
||||
#define SQLITE_DEFAULT_AUTOVACUUM 0
|
||||
#endif
|
||||
|
||||
#define BTREE_AUTOVACUUM_NONE 0 /* Do not do auto-vacuum */
|
||||
#define BTREE_AUTOVACUUM_FULL 1 /* Do full auto-vacuum */
|
||||
#define BTREE_AUTOVACUUM_INCR 2 /* Incremental vacuum */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Initialize The SQLite Library
|
||||
**
|
||||
** ^The sqlite3BtreeInitialize() routine initializes the
|
||||
** SQLite library. ^The sqlite3BtreeShutdown() routine
|
||||
** deallocates any resources that were allocated by sqlite3BtreeInitialize().
|
||||
** These routines are designed to aid in process initialization and
|
||||
** shutdown on embedded systems. Workstation applications using
|
||||
** SQLite normally do not need to invoke either of these routines.
|
||||
**
|
||||
** A call to sqlite3BtreeInitialize() is an "effective" call if it is
|
||||
** the first time sqlite3BtreeInitialize() is invoked during the lifetime of
|
||||
** the process, or if it is the first time sqlite3BtreeInitialize() is invoked
|
||||
** following a call to sqlite3BtreeShutdown(). ^(Only an effective call
|
||||
** of sqlite3BtreeInitialize() does any initialization. All other calls
|
||||
** are harmless no-ops.)^
|
||||
**
|
||||
** A call to sqlite3BtreeShutdown() is an "effective" call if it is the first
|
||||
** call to sqlite3BtreeShutdown() since the last sqlite3BtreeInitialize(). ^(Only
|
||||
** an effective call to sqlite3BtreeShutdown() does any deinitialization.
|
||||
** All other valid calls to sqlite3BtreeShutdown() are harmless no-ops.)^
|
||||
**
|
||||
** The sqlite3BtreeInitialize() interface is threadsafe, but sqlite3BtreeShutdown()
|
||||
** is not. The sqlite3BtreeShutdown() interface must only be called from a
|
||||
** single thread. All open [database connections] must be closed and all
|
||||
** other SQLite resources must be deallocated prior to invoking
|
||||
** sqlite3BtreeShutdown().
|
||||
**
|
||||
** Among other things, ^sqlite3BtreeInitialize() will invoke
|
||||
** sqlite3_os_init(). Similarly, ^sqlite3BtreeShutdown()
|
||||
** will invoke sqlite3_os_end().
|
||||
**
|
||||
** ^The sqlite3BtreeInitialize() routine returns [SQLITE_OK] on success.
|
||||
** ^If for some reason, sqlite3BtreeInitialize() is unable to initialize
|
||||
** the library (perhaps it is unable to allocate a needed resource such
|
||||
** as a mutex) it returns an [error code] other than [SQLITE_OK].
|
||||
**
|
||||
** ^The sqlite3BtreeInitialize() routine is called internally by many other
|
||||
** SQLite interfaces so that an application usually does not need to
|
||||
** invoke sqlite3BtreeInitialize() directly. For example, [sqlite3_open()]
|
||||
** calls sqlite3BtreeInitialize() so the SQLite library will be automatically
|
||||
** initialized when [sqlite3_open()] is called if it has not be initialized
|
||||
** already. ^However, if SQLite is compiled with the [SQLITE_OMIT_AUTOINIT]
|
||||
** compile-time option, then the automatic calls to sqlite3BtreeInitialize()
|
||||
** are omitted and the application must call sqlite3BtreeInitialize() directly
|
||||
** prior to using any other SQLite interface. For maximum portability,
|
||||
** it is recommended that applications always invoke sqlite3BtreeInitialize()
|
||||
** directly prior to using any other SQLite interface. Future releases
|
||||
** of SQLite may require this. In other words, the behavior exhibited
|
||||
** when SQLite is compiled with [SQLITE_OMIT_AUTOINIT] might become the
|
||||
** default behavior in some future release of SQLite.
|
||||
**
|
||||
** The sqlite3_os_init() routine does operating-system specific
|
||||
** initialization of the SQLite library. The sqlite3_os_end()
|
||||
** routine undoes the effect of sqlite3_os_init(). Typical tasks
|
||||
** performed by these routines include allocation or deallocation
|
||||
** of static resources, initialization of global variables,
|
||||
** setting up a default [sqlite3_vfs] module, or setting up
|
||||
** a default configuration using [sqlite3_config()].
|
||||
**
|
||||
** The application should never invoke either sqlite3_os_init()
|
||||
** or sqlite3_os_end() directly. The application should only invoke
|
||||
** sqlite3BtreeInitialize() and sqlite3BtreeShutdown(). The sqlite3_os_init()
|
||||
** interface is called automatically by sqlite3BtreeInitialize() and
|
||||
** sqlite3_os_end() is called by sqlite3BtreeShutdown(). Appropriate
|
||||
** implementations for sqlite3_os_init() and sqlite3_os_end()
|
||||
** are built into SQLite when it is compiled for Unix, Windows, or OS/2.
|
||||
** When [custom builds | built for other platforms]
|
||||
** (using the [SQLITE_OS_OTHER=1] compile-time
|
||||
** option) the application must supply a suitable implementation for
|
||||
** sqlite3_os_init() and sqlite3_os_end(). An application-supplied
|
||||
** implementation of sqlite3_os_init() or sqlite3_os_end()
|
||||
** must return [SQLITE_OK] on success and some other [error code] upon
|
||||
** failure.
|
||||
*/
|
||||
int sqlite3BtreeInitialize(void);
|
||||
int sqlite3BtreeShutdown(void);
|
||||
|
||||
/*
|
||||
** CAPI3REF: Result Codes
|
||||
** KEYWORDS: {result code definitions}
|
||||
**
|
||||
** Many SQLite functions return an integer result code from the set shown
|
||||
** here in order to indicate success or failure.
|
||||
**
|
||||
** New error codes may be added in future versions of SQLite.
|
||||
**
|
||||
** See also: [extended result code definitions]
|
||||
*/
|
||||
#define SQLITE_OK 0 /* Successful result */
|
||||
/* beginning-of-error-codes */
|
||||
#define SQLITE_ERROR 1 /* SQL error or missing database */
|
||||
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
|
||||
#define SQLITE_PERM 3 /* Access permission denied */
|
||||
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
|
||||
#define SQLITE_BUSY 5 /* The database file is locked */
|
||||
#define SQLITE_LOCKED 6 /* A table in the database is locked */
|
||||
#define SQLITE_NOMEM 7 /* A malloc() failed */
|
||||
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
|
||||
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
|
||||
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
|
||||
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
|
||||
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
|
||||
#define SQLITE_FULL 13 /* Insertion failed because database is full */
|
||||
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
|
||||
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
|
||||
#define SQLITE_EMPTY 16 /* Database is empty */
|
||||
#define SQLITE_SCHEMA 17 /* The database schema changed */
|
||||
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
|
||||
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
|
||||
#define SQLITE_MISMATCH 20 /* Data type mismatch */
|
||||
#define SQLITE_MISUSE 21 /* Library used incorrectly */
|
||||
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
|
||||
#define SQLITE_AUTH 23 /* Authorization denied */
|
||||
#define SQLITE_FORMAT 24 /* Auxiliary database format error */
|
||||
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
|
||||
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
|
||||
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
|
||||
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
|
||||
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
|
||||
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
|
||||
/* end-of-error-codes */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Extended Result Codes
|
||||
** KEYWORDS: {extended result code definitions}
|
||||
**
|
||||
** In its default configuration, SQLite API routines return one of 30 integer
|
||||
** [result codes]. However, experience has shown that many of
|
||||
** these result codes are too coarse-grained. They do not provide as
|
||||
** much information about problems as programmers might like. In an effort to
|
||||
** address this, newer versions of SQLite (version 3.3.8 and later) include
|
||||
** support for additional result codes that provide more detailed information
|
||||
** about errors. These [extended result codes] are enabled or disabled
|
||||
** on a per database connection basis using the
|
||||
** [sqlite3_extended_result_codes()] API. Or, the extended code for
|
||||
** the most recent error can be obtained using
|
||||
** [sqlite3_extended_errcode()].
|
||||
*/
|
||||
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
|
||||
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
|
||||
#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
|
||||
#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
|
||||
#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
|
||||
#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
|
||||
#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
|
||||
#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
|
||||
#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
|
||||
#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
|
||||
#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
|
||||
#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
|
||||
#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
|
||||
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
|
||||
#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
|
||||
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
|
||||
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
|
||||
#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
|
||||
#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
|
||||
#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
|
||||
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
|
||||
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
|
||||
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
|
||||
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
|
||||
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
|
||||
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
|
||||
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
|
||||
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
|
||||
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
|
||||
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
|
||||
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
|
||||
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
|
||||
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
|
||||
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
|
||||
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
|
||||
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
|
||||
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
|
||||
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
|
||||
#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
|
||||
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
|
||||
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
|
||||
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
|
||||
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
|
||||
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
|
||||
#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
|
||||
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
|
||||
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
|
||||
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
|
||||
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
|
||||
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
|
||||
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
|
||||
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
|
||||
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
|
||||
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
|
||||
|
||||
/* Reserved: 0x00F00000 */
|
||||
|
||||
/*
|
||||
** Forward declarations of structure
|
||||
*/
|
||||
typedef struct Btree Btree;
|
||||
typedef struct BtCursor BtCursor;
|
||||
typedef struct BtShared BtShared;
|
||||
typedef struct Mem Mem;
|
||||
typedef struct KeyInfo KeyInfo;
|
||||
typedef struct UnpackedRecord UnpackedRecord;
|
||||
|
||||
|
||||
int sqlite3BtreeOpen(
|
||||
const char *zVfs, /* VFS to use with this b-tree */
|
||||
const char *zFilename, /* Name of database file to open */
|
||||
Btree **ppBtree, /* Return open Btree* here */
|
||||
int flags, /* Flags */
|
||||
int vfsFlags /* Flags passed through to VFS open */
|
||||
);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeOpen can be the bitwise or of the
|
||||
** following values.
|
||||
**
|
||||
** NOTE: These values must match the corresponding PAGER_ values in
|
||||
** pager.h.
|
||||
*/
|
||||
#define BTREE_OMIT_JOURNAL 1 /* Do not create or use a rollback journal */
|
||||
#define BTREE_MEMORY 2 /* This is an in-memory DB */
|
||||
#define BTREE_SINGLE 4 /* The file contains at most 1 b-tree */
|
||||
#define BTREE_UNORDERED 8 /* Use of a hash implementation is OK */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Flags For File Open Operations
|
||||
**
|
||||
** These bit values are intended for use in the
|
||||
** 3rd parameter to the [sqlite3_open_v2()] interface and
|
||||
** in the 4th parameter to the [sqlite3_vfs.xOpen] method.
|
||||
*/
|
||||
#define SQLITE_OPEN_READONLY 0x00000001 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_READWRITE 0x00000002 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_CREATE 0x00000004 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_DELETEONCLOSE 0x00000008 /* VFS only */
|
||||
#define SQLITE_OPEN_EXCLUSIVE 0x00000010 /* VFS only */
|
||||
#define SQLITE_OPEN_AUTOPROXY 0x00000020 /* VFS only */
|
||||
#define SQLITE_OPEN_URI 0x00000040 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_MEMORY 0x00000080 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_MAIN_DB 0x00000100 /* VFS only */
|
||||
#define SQLITE_OPEN_TEMP_DB 0x00000200 /* VFS only */
|
||||
#define SQLITE_OPEN_TRANSIENT_DB 0x00000400 /* VFS only */
|
||||
#define SQLITE_OPEN_MAIN_JOURNAL 0x00000800 /* VFS only */
|
||||
#define SQLITE_OPEN_TEMP_JOURNAL 0x00001000 /* VFS only */
|
||||
#define SQLITE_OPEN_SUBJOURNAL 0x00002000 /* VFS only */
|
||||
#define SQLITE_OPEN_MASTER_JOURNAL 0x00004000 /* VFS only */
|
||||
#define SQLITE_OPEN_NOMUTEX 0x00008000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_FULLMUTEX 0x00010000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_SHAREDCACHE 0x00020000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_PRIVATECACHE 0x00040000 /* Ok for sqlite3_open_v2() */
|
||||
#define SQLITE_OPEN_WAL 0x00080000 /* VFS only */
|
||||
|
||||
int sqlite3BtreeClose(Btree*);
|
||||
int sqlite3BtreeSetCacheSize(Btree*,int);
|
||||
#if SQLITE_MAX_MMAP_SIZE>0
|
||||
int sqlite3BtreeSetMmapLimit(Btree*,sqlite3_int64);
|
||||
#endif
|
||||
int sqlite3BtreeSetPagerFlags(Btree*,unsigned);
|
||||
int sqlite3BtreeSyncDisabled(Btree*);
|
||||
int sqlite3BtreeSetPageSize(Btree *p, int nPagesize, int nReserve, int eFix);
|
||||
int sqlite3BtreeGetPageSize(Btree*);
|
||||
int sqlite3BtreeMaxPageCount(Btree*,int);
|
||||
u32 sqlite3BtreeLastPage(Btree*);
|
||||
int sqlite3BtreeSecureDelete(Btree*,int);
|
||||
int sqlite3BtreeGetOptimalReserve(Btree*);
|
||||
int sqlite3BtreeGetReserveNoMutex(Btree *p);
|
||||
int sqlite3BtreeSetAutoVacuum(Btree *, int);
|
||||
int sqlite3BtreeGetAutoVacuum(Btree *);
|
||||
int sqlite3BtreeBeginTrans(Btree*,int);
|
||||
int sqlite3BtreeCommitPhaseOne(Btree*, const char *zMaster);
|
||||
int sqlite3BtreeCommitPhaseTwo(Btree*, int);
|
||||
int sqlite3BtreeCommit(Btree*);
|
||||
int sqlite3BtreeRollback(Btree*,int,int);
|
||||
int sqlite3BtreeBeginStmt(Btree*,int);
|
||||
int sqlite3BtreeCreateTable(Btree*, int*, int flags);
|
||||
int sqlite3BtreeIsInTrans(Btree*);
|
||||
int sqlite3BtreeIsInReadTrans(Btree*);
|
||||
int sqlite3BtreeIsInBackup(Btree*);
|
||||
void *sqlite3BtreeSchema(Btree *, int, void(*)(void *));
|
||||
int sqlite3BtreeSchemaLocked(Btree *pBtree);
|
||||
int sqlite3BtreeLockTable(Btree *pBtree, int iTab, u8 isWriteLock);
|
||||
int sqlite3BtreeSavepoint(Btree *, int, int);
|
||||
|
||||
int sqlite3BtreeFileFormat(Btree *);
|
||||
const char *sqlite3BtreeGetFilename(Btree *);
|
||||
const char *sqlite3BtreeGetJournalname(Btree *);
|
||||
int sqlite3BtreeCopyFile(Btree *, Btree *);
|
||||
|
||||
int sqlite3BtreeIncrVacuum(Btree *);
|
||||
|
||||
/* The flags parameter to sqlite3BtreeCreateTable can be the bitwise OR
|
||||
** of the flags shown below.
|
||||
**
|
||||
** Every SQLite table must have either BTREE_INTKEY or BTREE_BLOBKEY set.
|
||||
** With BTREE_INTKEY, the table key is a 64-bit integer and arbitrary data
|
||||
** is stored in the leaves. (BTREE_INTKEY is used for SQL tables.) With
|
||||
** BTREE_BLOBKEY, the key is an arbitrary BLOB and no content is stored
|
||||
** anywhere - the key is the content. (BTREE_BLOBKEY is used for SQL
|
||||
** indices.)
|
||||
*/
|
||||
#define BTREE_INTKEY 1 /* Table has only 64-bit signed integer keys */
|
||||
#define BTREE_BLOBKEY 2 /* Table has keys only - no data */
|
||||
|
||||
int sqlite3BtreeDropTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTable(Btree*, int, int*);
|
||||
int sqlite3BtreeClearTableOfCursor(BtCursor*);
|
||||
int sqlite3BtreeTripAllCursors(Btree*, int, int);
|
||||
|
||||
void sqlite3BtreeGetMeta(Btree *pBtree, int idx, u32 *pValue);
|
||||
int sqlite3BtreeUpdateMeta(Btree*, int idx, u32 value);
|
||||
|
||||
int sqlite3BtreeNewDb(Btree *p);
|
||||
|
||||
/*
|
||||
** The second parameter to sqlite3BtreeGetMeta or sqlite3BtreeUpdateMeta
|
||||
** should be one of the following values. The integer values are assigned
|
||||
** to constants so that the offset of the corresponding field in an
|
||||
** SQLite database header may be found using the following formula:
|
||||
**
|
||||
** offset = 36 + (idx * 4)
|
||||
**
|
||||
** For example, the free-page-count field is located at byte offset 36 of
|
||||
** the database file header. The incr-vacuum-flag field is located at
|
||||
** byte offset 64 (== 36+4*7).
|
||||
**
|
||||
** The BTREE_DATA_VERSION value is not really a value stored in the header.
|
||||
** It is a read-only number computed by the pager. But we merge it with
|
||||
** the header value access routines since its access pattern is the same.
|
||||
** Call it a "virtual meta value".
|
||||
*/
|
||||
#define BTREE_FREE_PAGE_COUNT 0
|
||||
#define BTREE_SCHEMA_VERSION 1
|
||||
#define BTREE_FILE_FORMAT 2
|
||||
#define BTREE_DEFAULT_CACHE_SIZE 3
|
||||
#define BTREE_LARGEST_ROOT_PAGE 4
|
||||
#define BTREE_TEXT_ENCODING 5
|
||||
#define BTREE_USER_VERSION 6
|
||||
#define BTREE_INCR_VACUUM 7
|
||||
#define BTREE_APPLICATION_ID 8
|
||||
#define BTREE_DATA_VERSION 15 /* A virtual meta-value */
|
||||
|
||||
/*
|
||||
** An instance of the following structure holds information about a
|
||||
** single index record that has already been parsed out into individual
|
||||
** values.
|
||||
**
|
||||
** A record is an object that contains one or more fields of data.
|
||||
** Records are used to store the content of a table row and to store
|
||||
** the key of an index. A blob encoding of a record is created by
|
||||
** the OP_MakeRecord opcode of the VDBE and is disassembled by the
|
||||
** OP_Column opcode.
|
||||
**
|
||||
** This structure holds a record that has already been disassembled
|
||||
** into its constituent fields.
|
||||
**
|
||||
** The r1 and r2 member variables are only used by the optimized comparison
|
||||
** functions vdbeRecordCompareInt() and vdbeRecordCompareString().
|
||||
*/
|
||||
struct UnpackedRecord {
|
||||
KeyInfo *pKeyInfo; /* Collation and sort-order information */
|
||||
u16 nField; /* Number of entries in apMem[] */
|
||||
i8 default_rc; /* Comparison result if keys are equal */
|
||||
u8 errCode; /* Error detected by xRecordCompare (CORRUPT or NOMEM) */
|
||||
Mem *aMem; /* Values */
|
||||
int r1; /* Value to return if (lhs > rhs) */
|
||||
int r2; /* Value to return if (rhs < lhs) */
|
||||
};
|
||||
|
||||
/* One or more of the following flags are set to indicate the validOK
|
||||
** representations of the value stored in the Mem struct.
|
||||
**
|
||||
** If the MEM_Null flag is set, then the value is an SQL NULL value.
|
||||
** No other flags may be set in this case.
|
||||
**
|
||||
** If the MEM_Str flag is set then Mem.z points at a string representation.
|
||||
** Usually this is encoded in the same unicode encoding as the main
|
||||
** database (see below for exceptions). If the MEM_Term flag is also
|
||||
** set, then the string is nul terminated. The MEM_Int and MEM_Real
|
||||
** flags may coexist with the MEM_Str flag.
|
||||
*/
|
||||
#define MEM_Null 0x0001 /* Value is NULL */
|
||||
#define MEM_Str 0x0002 /* Value is a string */
|
||||
#define MEM_Int 0x0004 /* Value is an integer */
|
||||
#define MEM_Real 0x0008 /* Value is a real number */
|
||||
#define MEM_Blob 0x0010 /* Value is a BLOB */
|
||||
|
||||
#define MEM_Term 0x0200 /* String rep is nul terminated */
|
||||
#define MEM_Dyn 0x0400 /* Need to call Mem.xDel() on Mem.z */
|
||||
#define MEM_Static 0x0800 /* Mem.z points to a static string */
|
||||
#define MEM_Ephem 0x1000 /* Mem.z points to an ephemeral string */
|
||||
#define MEM_Zero 0x4000 /* Mem.i contains count of 0s appended to blob */
|
||||
|
||||
/*
|
||||
** Internally, the vdbe manipulates nearly all SQL values as Mem
|
||||
** structures. Each Mem struct may cache multiple representations (string,
|
||||
** integer etc.) of the same value.
|
||||
*/
|
||||
struct Mem {
|
||||
union MemValue {
|
||||
double r; /* Real value used when MEM_Real is set in flags */
|
||||
i64 i; /* Integer value used when MEM_Int is set in flags */
|
||||
int nZero; /* Used when bit MEM_Zero is set in flags */
|
||||
} u;
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
|
||||
u8 eSubtype; /* Subtype for this value */
|
||||
int n; /* Number of characters in string value, excluding '\0' */
|
||||
char *z; /* String or BLOB value */
|
||||
/* ShallowCopy only needs to copy the information above */
|
||||
char *zMalloc; /* Space to hold MEM_Str or MEM_Blob if szMalloc>0 */
|
||||
int szMalloc; /* Size of the zMalloc allocation */
|
||||
u32 uTemp; /* Transient storage for serial_type in OP_MakeRecord */
|
||||
Btree *pBtree; /* The associated database connection */
|
||||
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
|
||||
#ifdef SQLITE_DEBUG
|
||||
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
|
||||
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
** Values that may be OR'd together to form the second argument of an
|
||||
** sqlite3BtreeCursorHints() call.
|
||||
**
|
||||
** The BTREE_BULKLOAD flag is set on index cursors when the index is going
|
||||
** to be filled with content that is already in sorted order.
|
||||
**
|
||||
** The BTREE_SEEK_EQ flag is set on cursors that will get OP_SeekGE or
|
||||
** OP_SeekLE opcodes for a range search, but where the range of entries
|
||||
** selected will all have the same key. In other words, the cursor will
|
||||
** be used only for equality key searches.
|
||||
**
|
||||
*/
|
||||
#define BTREE_BULKLOAD 0x00000001 /* Used to full index in sorted order */
|
||||
#define BTREE_SEEK_EQ 0x00000002 /* EQ seeks only - no range seeks */
|
||||
|
||||
int sqlite3BtreeCursor(
|
||||
Btree*, /* BTree containing table to open */
|
||||
int iTable, /* Index of root page */
|
||||
int wrFlag, /* 1 for writing. 0 for read-only */
|
||||
int N, int X, /* index of N key columns and X extra columns */
|
||||
BtCursor **ppCursor /* Space to write cursor pointer */
|
||||
);
|
||||
int sqlite3BtreeCursorSize(void);
|
||||
|
||||
int sqlite3BtreeCloseCursor(BtCursor*);
|
||||
void sqlite3BtreeInitUnpackedRecord(
|
||||
UnpackedRecord *pUnKey,
|
||||
BtCursor* pCur,
|
||||
int nField,
|
||||
int default_rc,
|
||||
Mem* pMem);
|
||||
int sqlite3BtreeMovetoUnpacked(
|
||||
BtCursor*,
|
||||
UnpackedRecord *pUnKey,
|
||||
i64 intKey,
|
||||
int bias,
|
||||
int *pRes
|
||||
);
|
||||
int sqlite3BtreeCursorHasMoved(BtCursor*);
|
||||
int sqlite3BtreeCursorRestore(BtCursor*, int*);
|
||||
int sqlite3BtreeDelete(BtCursor*, int);
|
||||
int sqlite3BtreeInsert(BtCursor*, const void *pKey, i64 nKey,
|
||||
const void *pData, int nData,
|
||||
int nZero, int bias, int seekResult);
|
||||
int sqlite3BtreeFirst(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeLast(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeNext(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeEof(BtCursor*);
|
||||
int sqlite3BtreePrevious(BtCursor*, int *pRes);
|
||||
int sqlite3BtreeKeySize(BtCursor*, i64 *pSize);
|
||||
int sqlite3BtreeKey(BtCursor*, u32 offset, u32 amt, void*);
|
||||
const void *sqlite3BtreeKeyFetch(BtCursor*, u32 *pAmt);
|
||||
const void *sqlite3BtreeDataFetch(BtCursor*, u32 *pAmt);
|
||||
int sqlite3BtreeDataSize(BtCursor*, u32 *pSize);
|
||||
int sqlite3BtreeData(BtCursor*, u32 offset, u32 amt, void*);
|
||||
|
||||
char *sqlite3BtreeIntegrityCheck(Btree*, int *aRoot, int nRoot, int, int*);
|
||||
struct Pager *sqlite3BtreePager(Btree*);
|
||||
|
||||
int sqlite3BtreePutData(BtCursor*, u32 offset, u32 amt, void*);
|
||||
void sqlite3BtreeIncrblobCursor(BtCursor *);
|
||||
void sqlite3BtreeClearCursor(BtCursor *);
|
||||
int sqlite3BtreeSetVersion(Btree *pBt, int iVersion);
|
||||
void sqlite3BtreeCursorHints(BtCursor *, unsigned int mask);
|
||||
#ifdef SQLITE_DEBUG
|
||||
int sqlite3BtreeCursorHasHint(BtCursor*, unsigned int mask);
|
||||
#endif
|
||||
int sqlite3BtreeIsReadonly(Btree *pBt);
|
||||
|
||||
#ifndef NDEBUG
|
||||
int sqlite3BtreeCursorIsValid(BtCursor*);
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_BTREECOUNT
|
||||
int sqlite3BtreeCount(BtCursor *, i64 *);
|
||||
#endif
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
int sqlite3BtreeCursorInfo(BtCursor*, int*, int);
|
||||
void sqlite3BtreeCursorList(Btree*);
|
||||
#endif
|
||||
|
||||
#ifndef SQLITE_OMIT_WAL
|
||||
int sqlite3BtreeCheckpoint(Btree*, int, int *, int *);
|
||||
#endif
|
||||
|
||||
/*
|
||||
** If we are not using shared cache, then there is no need to
|
||||
** use mutexes to access the BtShared structures. So make the
|
||||
** Enter and Leave procedures no-ops.
|
||||
*/
|
||||
#ifndef SQLITE_OMIT_SHARED_CACHE
|
||||
void sqlite3BtreeEnter(Btree*);
|
||||
#else
|
||||
# define sqlite3BtreeEnter(X)
|
||||
#endif
|
||||
|
||||
#if !defined(SQLITE_OMIT_SHARED_CACHE) && SQLITE_THREADSAFE
|
||||
int sqlite3BtreeSharable(Btree*);
|
||||
void sqlite3BtreeLeave(Btree*);
|
||||
void sqlite3BtreeEnterCursor(BtCursor*);
|
||||
void sqlite3BtreeLeaveCursor(BtCursor*);
|
||||
#else
|
||||
|
||||
# define sqlite3BtreeSharable(X) 0
|
||||
# define sqlite3BtreeLeave(X)
|
||||
# define sqlite3BtreeEnterCursor(X)
|
||||
# define sqlite3BtreeLeaveCursor(X)
|
||||
#endif
|
||||
|
||||
u32 sqlite3BtreeSerialType(Mem *pMem, int file_format);
|
||||
u32 sqlite3BtreeSerialTypeLen(u32);
|
||||
u32 sqlite3BtreeSerialGet(const unsigned char*, u32, Mem *);
|
||||
u32 sqlite3BtreeSerialPut(u8*, Mem*, u32);
|
||||
|
||||
/*
|
||||
** Routines to read and write variable-length integers. These used to
|
||||
** be defined locally, but now we use the varint routines in the util.c
|
||||
** file.
|
||||
*/
|
||||
int sqlite3BtreePutVarint(unsigned char*, u64);
|
||||
u8 sqlite3BtreeGetVarint(const unsigned char *, u64 *);
|
||||
u8 sqlite3BtreeGetVarint32(const unsigned char *, u32 *);
|
||||
int sqlite3BtreeVarintLen(u64 v);
|
||||
|
||||
/*
|
||||
** The common case is for a varint to be a single byte. They following
|
||||
** macros handle the common case without a procedure call, but then call
|
||||
** the procedure for larger varints.
|
||||
*/
|
||||
#define getVarint32(A,B) \
|
||||
(u8)((*(A)<(u8)0x80)?((B)=(u32)*(A)),1:sqlite3BtreeGetVarint32((A),(u32 *)&(B)))
|
||||
#define putVarint32(A,B) \
|
||||
(u8)(((u32)(B)<(u32)0x80)?(*(A)=(unsigned char)(B)),1:\
|
||||
sqlite3BtreePutVarint((A),(B)))
|
||||
#define getVarint sqlite3BtreeGetVarint
|
||||
#define putVarint sqlite3BtreePutVarint
|
||||
|
||||
|
||||
int sqlite3BtreeIdxRowid(Btree*, BtCursor*, i64*);
|
||||
|
||||
int sqlite3BtreeRecordCompare(int,const void*,UnpackedRecord*);
|
||||
|
||||
const char *sqlite3BtreeErrName(int rc);
|
||||
|
||||
#endif /* _BTREE_H_ */
|
||||
@@ -531,12 +531,6 @@ foreign import ccall "pgf/pgf.h pgf_print"
|
||||
foreign import ccall "pgf/expr.h pgf_read_expr"
|
||||
pgf_read_expr :: Ptr GuIn -> Ptr GuPool -> Ptr GuPool -> Ptr GuExn -> IO PgfExpr
|
||||
|
||||
foreign import ccall "pgf/expr.h pgf_read_expr_tuple"
|
||||
pgf_read_expr_tuple :: Ptr GuIn -> CSizeT -> Ptr PgfExpr -> Ptr GuPool -> Ptr GuExn -> IO CInt
|
||||
|
||||
foreign import ccall "pgf/expr.h pgf_read_expr_matrix"
|
||||
pgf_read_expr_matrix :: Ptr GuIn -> CSizeT -> Ptr GuPool -> Ptr GuExn -> IO (Ptr GuSeq)
|
||||
|
||||
foreign import ccall "pgf/expr.h pgf_read_type"
|
||||
pgf_read_type :: Ptr GuIn -> Ptr GuPool -> Ptr GuPool -> Ptr GuExn -> IO PgfType
|
||||
|
||||
|
||||
@@ -1,349 +0,0 @@
|
||||
{-# LANGUAGE DeriveDataTypeable, ExistentialQuantification #-}
|
||||
|
||||
#include <pgf/pgf.h>
|
||||
#include <gu/exn.h>
|
||||
#include <sg/sg.h>
|
||||
|
||||
module SG( SG, openSG, closeSG
|
||||
, beginTrans, commit, rollback, inTransaction
|
||||
, SgId
|
||||
, insertExpr, getExpr, queryExpr
|
||||
, updateFtsIndex
|
||||
, queryLinearization
|
||||
, readTriple, showTriple
|
||||
, insertTriple, getTriple
|
||||
, queryTriple
|
||||
, query
|
||||
) where
|
||||
|
||||
import Foreign hiding (unsafePerformIO)
|
||||
import Foreign.C
|
||||
import SG.FFI
|
||||
import PGF2.FFI
|
||||
import PGF2.Expr
|
||||
|
||||
import Data.Typeable
|
||||
import Control.Exception(Exception,SomeException,catch,throwIO)
|
||||
import System.IO.Unsafe(unsafePerformIO,unsafeInterleaveIO)
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Global database operations and types
|
||||
|
||||
newtype SG = SG {sg :: Ptr SgSG}
|
||||
|
||||
openSG :: FilePath -> IO SG
|
||||
openSG fpath =
|
||||
withCString fpath $ \c_fpath ->
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg <- sg_open c_fpath exn
|
||||
failed <- gu_exn_is_raised exn
|
||||
if failed
|
||||
then do is_errno <- gu_exn_caught exn gu_exn_type_GuErrno
|
||||
if is_errno
|
||||
then do perrno <- (#peek GuExn, data.data) exn
|
||||
errno <- peek perrno
|
||||
ioError (errnoToIOError "openSG" (Errno errno) Nothing (Just fpath))
|
||||
else do is_sgerr <- gu_exn_caught exn gu_exn_type_SgError
|
||||
if is_sgerr
|
||||
then do c_msg <- (#peek GuExn, data.data) exn
|
||||
msg <- peekUtf8CString c_msg
|
||||
throwIO (SGError msg)
|
||||
else throwIO (SGError "The database cannot be opened")
|
||||
else return (SG sg)
|
||||
|
||||
closeSG :: SG -> IO ()
|
||||
closeSG (SG sg) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg <- sg_close sg exn
|
||||
handle_sg_exn exn
|
||||
|
||||
beginTrans :: SG -> IO ()
|
||||
beginTrans (SG sg) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg <- sg_begin_trans sg exn
|
||||
handle_sg_exn exn
|
||||
|
||||
commit :: SG -> IO ()
|
||||
commit (SG sg) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg <- sg_commit sg exn
|
||||
handle_sg_exn exn
|
||||
|
||||
rollback :: SG -> IO ()
|
||||
rollback (SG sg) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg <- sg_rollback sg exn
|
||||
handle_sg_exn exn
|
||||
|
||||
inTransaction :: SG -> IO a -> IO a
|
||||
inTransaction sg f =
|
||||
catch (beginTrans sg >> f >>= \x -> commit sg >> return x)
|
||||
(\e -> rollback sg >> throwIO (e :: SomeException))
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Expressions
|
||||
|
||||
insertExpr :: SG -> Expr -> IO SgId
|
||||
insertExpr (SG sg) (Expr expr touch) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
id <- sg_insert_expr sg expr 1 exn
|
||||
touch
|
||||
handle_sg_exn exn
|
||||
return id
|
||||
|
||||
getExpr :: SG -> SgId -> IO (Maybe Expr)
|
||||
getExpr (SG sg) id = do
|
||||
exprPl <- gu_new_pool
|
||||
exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
c_expr <- sg_get_expr sg id exprPl exn
|
||||
handle_sg_exn exn
|
||||
if c_expr == nullPtr
|
||||
then do touchForeignPtr exprFPl
|
||||
return Nothing
|
||||
else do return $ Just (Expr c_expr (touchForeignPtr exprFPl))
|
||||
|
||||
queryExpr :: SG -> Expr -> IO [(SgId,Expr)]
|
||||
queryExpr (SG sg) (Expr query touch) =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
res <- sg_query_expr sg query tmpPl exn
|
||||
touch
|
||||
handle_sg_exn exn
|
||||
fetchResults res exn
|
||||
where
|
||||
fetchResults res exn = do
|
||||
exprPl <- gu_new_pool
|
||||
(key,c_expr) <- alloca $ \pKey -> do
|
||||
c_expr <- sg_query_next sg res pKey exprPl exn
|
||||
key <- peek pKey
|
||||
return (key,c_expr)
|
||||
failed <- gu_exn_is_raised exn
|
||||
if failed
|
||||
then do gu_pool_free exprPl
|
||||
sg_query_close sg res exn
|
||||
handle_sg_exn exn
|
||||
return []
|
||||
else if c_expr == nullPtr
|
||||
then do gu_pool_free exprPl
|
||||
sg_query_close sg res exn
|
||||
return []
|
||||
else do exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
rest <- fetchResults res exn
|
||||
return ((key,Expr c_expr (touchForeignPtr exprFPl)) : rest)
|
||||
|
||||
updateFtsIndex :: SG -> PGF -> IO ()
|
||||
updateFtsIndex (SG sg) p = do
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
sg_update_fts_index sg (pgf p) exn
|
||||
handle_sg_exn exn
|
||||
|
||||
queryLinearization :: SG -> String -> IO [Expr]
|
||||
queryLinearization (SG sg) query = do
|
||||
exprPl <- gu_new_pool
|
||||
exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
(withGuPool $ \tmpPl -> do
|
||||
c_query <- newUtf8CString query tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
seq <- sg_query_linearization sg c_query tmpPl exn
|
||||
handle_sg_exn exn
|
||||
len <- (#peek GuSeq, len) seq
|
||||
ids <- peekArray (fromIntegral (len :: CInt)) (seq `plusPtr` (#offset GuSeq, data))
|
||||
getExprs exprFPl exprPl exn ids)
|
||||
where
|
||||
getExprs exprFPl exprPl exn [] = return []
|
||||
getExprs exprFPl exprPl exn (id:ids) = do
|
||||
c_expr <- sg_get_expr sg id exprPl exn
|
||||
handle_sg_exn exn
|
||||
if c_expr == nullPtr
|
||||
then getExprs exprFPl exprPl exn ids
|
||||
else do let e = Expr c_expr (touchForeignPtr exprFPl)
|
||||
es <- getExprs exprFPl exprPl exn ids
|
||||
return (e:es)
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Triples
|
||||
|
||||
readTriple :: String -> Maybe (Expr,Expr,Expr)
|
||||
readTriple str =
|
||||
unsafePerformIO $
|
||||
do exprPl <- gu_new_pool
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple ->
|
||||
do c_str <- newUtf8CString str tmpPl
|
||||
guin <- gu_string_in c_str tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
ok <- pgf_read_expr_tuple guin 3 triple exprPl exn
|
||||
status <- gu_exn_is_raised exn
|
||||
if (ok == 1 && not status)
|
||||
then do c_expr1 <- peekElemOff triple 0
|
||||
c_expr2 <- peekElemOff triple 1
|
||||
c_expr3 <- peekElemOff triple 2
|
||||
exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
let touch = touchForeignPtr exprFPl
|
||||
return $ Just (Expr c_expr1 touch,Expr c_expr2 touch,Expr c_expr3 touch)
|
||||
else do gu_pool_free exprPl
|
||||
return Nothing
|
||||
|
||||
showTriple :: Expr -> Expr -> Expr -> String
|
||||
showTriple (Expr expr1 touch1) (Expr expr2 touch2) (Expr expr3 touch3) =
|
||||
unsafePerformIO $
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
(sb,out) <- newOut tmpPl
|
||||
let printCtxt = nullPtr
|
||||
exn <- gu_new_exn tmpPl
|
||||
pokeElemOff triple 0 expr1
|
||||
pokeElemOff triple 1 expr2
|
||||
pokeElemOff triple 2 expr3
|
||||
pgf_print_expr_tuple 3 triple printCtxt out exn
|
||||
touch1 >> touch2 >> touch3
|
||||
s <- gu_string_buf_freeze sb tmpPl
|
||||
peekUtf8CString s
|
||||
|
||||
insertTriple :: SG -> Expr -> Expr -> Expr -> IO SgId
|
||||
insertTriple (SG sg) (Expr expr1 touch1) (Expr expr2 touch2) (Expr expr3 touch3) =
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
pokeElemOff triple 0 expr1
|
||||
pokeElemOff triple 1 expr2
|
||||
pokeElemOff triple 2 expr3
|
||||
id <- sg_insert_triple sg triple exn
|
||||
touch1 >> touch2 >> touch3
|
||||
handle_sg_exn exn
|
||||
return id
|
||||
|
||||
getTriple :: SG -> SgId -> IO (Maybe (Expr,Expr,Expr))
|
||||
getTriple (SG sg) id = do
|
||||
exprPl <- gu_new_pool
|
||||
exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
let touch = touchForeignPtr exprFPl
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
res <- sg_get_triple sg id triple exprPl exn
|
||||
handle_sg_exn exn
|
||||
if res /= 0
|
||||
then do c_expr1 <- peekElemOff triple 0
|
||||
c_expr2 <- peekElemOff triple 1
|
||||
c_expr3 <- peekElemOff triple 2
|
||||
return (Just (Expr c_expr1 touch
|
||||
,Expr c_expr2 touch
|
||||
,Expr c_expr3 touch
|
||||
))
|
||||
else do touch
|
||||
return Nothing
|
||||
|
||||
queryTriple :: SG -> Maybe Expr -> Maybe Expr -> Maybe Expr -> IO [(SgId,Expr,Expr,Expr)]
|
||||
queryTriple (SG sg) mb_expr1 mb_expr2 mb_expr3 =
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
pokeElemOff triple 0 (toCExpr mb_expr1)
|
||||
pokeElemOff triple 1 (toCExpr mb_expr2)
|
||||
pokeElemOff triple 2 (toCExpr mb_expr3)
|
||||
res <- sg_query_triple sg triple exn
|
||||
handle_sg_exn exn
|
||||
unsafeInterleaveIO (fetchResults res)
|
||||
where
|
||||
toCExpr Nothing = nullPtr
|
||||
toCExpr (Just (Expr expr _)) = expr
|
||||
|
||||
fromCExpr c_expr touch Nothing = Expr c_expr touch
|
||||
fromCExpr c_expr touch (Just e) = e
|
||||
|
||||
fetchResults res = do
|
||||
exprPl <- gu_new_pool
|
||||
alloca $ \pKey ->
|
||||
withGuPool $ \tmpPl ->
|
||||
withTriple $ \triple -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
r <- sg_triple_result_fetch res pKey triple exprPl exn
|
||||
failed <- gu_exn_is_raised exn
|
||||
if failed
|
||||
then do gu_pool_free exprPl
|
||||
sg_triple_result_close res exn
|
||||
handle_sg_exn exn
|
||||
return []
|
||||
else if r == 0
|
||||
then do gu_pool_free exprPl
|
||||
sg_triple_result_close res exn
|
||||
return []
|
||||
else do exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
let touch = touchForeignPtr exprFPl
|
||||
c_expr1 <- peekElemOff triple 0
|
||||
c_expr2 <- peekElemOff triple 1
|
||||
c_expr3 <- peekElemOff triple 2
|
||||
key <- peek pKey
|
||||
rest <- unsafeInterleaveIO (fetchResults res)
|
||||
return ((key,fromCExpr c_expr1 touch mb_expr1
|
||||
,fromCExpr c_expr2 touch mb_expr2
|
||||
,fromCExpr c_expr3 touch mb_expr3) : rest)
|
||||
|
||||
|
||||
query :: SG -> String -> IO [[Expr]]
|
||||
query (SG sg) str =
|
||||
withGuPool $ \tmpPl ->
|
||||
do c_str <- newUtf8CString str tmpPl
|
||||
guin <- gu_string_in c_str tmpPl
|
||||
exn <- gu_new_exn tmpPl
|
||||
seq <- pgf_read_expr_matrix guin 3 tmpPl exn
|
||||
if seq /= nullPtr
|
||||
then do count <- (#peek GuSeq, len) seq
|
||||
q <- sg_query sg (count `div` 3) (seq `plusPtr` (#offset GuSeq, data)) exn
|
||||
handle_sg_exn exn
|
||||
n_cols <- sg_query_result_columns q
|
||||
unsafeInterleaveIO (fetchResults q n_cols)
|
||||
else return []
|
||||
where
|
||||
fetchResults q n_cols =
|
||||
withGuPool $ \tmpPl -> do
|
||||
exn <- gu_new_exn tmpPl
|
||||
pExprs <- gu_malloc tmpPl ((#size PgfExpr) * n_cols)
|
||||
exprPl <- gu_new_pool
|
||||
res <- sg_query_result_fetch q pExprs exprPl exn
|
||||
failed <- gu_exn_is_raised exn
|
||||
if failed
|
||||
then do gu_pool_free exprPl
|
||||
sg_query_result_close q exn
|
||||
handle_sg_exn exn
|
||||
return []
|
||||
else if res /= 0
|
||||
then do exprFPl <- newForeignPtr gu_pool_finalizer exprPl
|
||||
let touch = touchForeignPtr exprFPl
|
||||
row <- fmap (map (flip Expr touch)) $ peekArray (fromIntegral n_cols) pExprs
|
||||
rows <- unsafeInterleaveIO (fetchResults q n_cols)
|
||||
return (row:rows)
|
||||
else do gu_pool_free exprPl
|
||||
sg_query_result_close q exn
|
||||
return []
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
-- Exceptions
|
||||
|
||||
newtype SGError = SGError String
|
||||
deriving (Show, Typeable)
|
||||
|
||||
instance Exception SGError
|
||||
|
||||
handle_sg_exn exn = do
|
||||
failed <- gu_exn_is_raised exn
|
||||
if failed
|
||||
then do is_sgerr <- gu_exn_caught exn gu_exn_type_SgError
|
||||
if is_sgerr
|
||||
then do c_msg <- (#peek GuExn, data.data) exn
|
||||
msg <- peekUtf8CString c_msg
|
||||
throwIO (SGError msg)
|
||||
else throwIO (SGError "Unknown database error")
|
||||
else return ()
|
||||
|
||||
-----------------------------------------------------------------------
|
||||
@@ -1,84 +0,0 @@
|
||||
{-# LANGUAGE ForeignFunctionInterface, MagicHash #-}
|
||||
module SG.FFI where
|
||||
|
||||
import Foreign
|
||||
import Foreign.C
|
||||
import PGF2.FFI
|
||||
import GHC.Ptr
|
||||
import Data.Int
|
||||
|
||||
data SgSG
|
||||
data SgQueryExprResult
|
||||
data SgTripleResult
|
||||
data SgQueryResult
|
||||
type SgId = Int64
|
||||
|
||||
foreign import ccall "sg/sg.h sg_open"
|
||||
sg_open :: CString -> Ptr GuExn -> IO (Ptr SgSG)
|
||||
|
||||
foreign import ccall "sg/sg.h sg_close"
|
||||
sg_close :: Ptr SgSG -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_begin_trans"
|
||||
sg_begin_trans :: Ptr SgSG -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_commit"
|
||||
sg_commit :: Ptr SgSG -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_rollback"
|
||||
sg_rollback :: Ptr SgSG -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_insert_expr"
|
||||
sg_insert_expr :: Ptr SgSG -> PgfExpr -> CInt -> Ptr GuExn -> IO SgId
|
||||
|
||||
foreign import ccall "sg/sg.h sg_get_expr"
|
||||
sg_get_expr :: Ptr SgSG -> SgId -> Ptr GuPool -> Ptr GuExn -> IO PgfExpr
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_expr"
|
||||
sg_query_expr :: Ptr SgSG -> PgfExpr -> Ptr GuPool -> Ptr GuExn -> IO (Ptr SgQueryExprResult)
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_next"
|
||||
sg_query_next :: Ptr SgSG -> Ptr SgQueryExprResult -> Ptr SgId -> Ptr GuPool -> Ptr GuExn -> IO PgfExpr
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_close"
|
||||
sg_query_close :: Ptr SgSG -> Ptr SgQueryExprResult -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_update_fts_index"
|
||||
sg_update_fts_index :: Ptr SgSG -> Ptr PgfPGF -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_linearization"
|
||||
sg_query_linearization :: Ptr SgSG -> CString -> Ptr GuPool -> Ptr GuExn -> IO (Ptr GuSeq)
|
||||
|
||||
foreign import ccall "sg/sg.h sg_insert_triple"
|
||||
sg_insert_triple :: Ptr SgSG -> SgTriple -> Ptr GuExn -> IO SgId
|
||||
|
||||
foreign import ccall "sg/sg.h sg_get_triple"
|
||||
sg_get_triple :: Ptr SgSG -> SgId -> SgTriple -> Ptr GuPool -> Ptr GuExn -> IO CInt
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_triple"
|
||||
sg_query_triple :: Ptr SgSG -> SgTriple -> Ptr GuExn -> IO (Ptr SgTripleResult)
|
||||
|
||||
foreign import ccall "sg/sg.h sg_triple_result_fetch"
|
||||
sg_triple_result_fetch :: Ptr SgTripleResult -> Ptr SgId -> SgTriple -> Ptr GuPool -> Ptr GuExn -> IO CInt
|
||||
|
||||
foreign import ccall "sg/sg.h sg_triple_result_close"
|
||||
sg_triple_result_close :: Ptr SgTripleResult -> Ptr GuExn -> IO ()
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query"
|
||||
sg_query :: Ptr SgSG -> CSizeT -> Ptr PgfExpr -> Ptr GuExn -> IO (Ptr SgQueryResult)
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_result_columns"
|
||||
sg_query_result_columns :: Ptr SgQueryResult -> IO CSizeT
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_result_fetch"
|
||||
sg_query_result_fetch :: Ptr SgQueryResult -> Ptr PgfExpr -> Ptr GuPool -> Ptr GuExn -> IO CInt
|
||||
|
||||
foreign import ccall "sg/sg.h sg_query_result_close"
|
||||
sg_query_result_close :: Ptr SgQueryResult -> Ptr GuExn -> IO ()
|
||||
|
||||
type SgTriple = Ptr PgfExpr
|
||||
|
||||
withTriple :: (SgTriple -> IO a) -> IO a
|
||||
withTriple = allocaArray 3
|
||||
|
||||
gu_exn_type_SgError = Ptr "SgError"# :: CString
|
||||
@@ -14,17 +14,17 @@ extra-source-files: README
|
||||
cabal-version: >=1.10
|
||||
|
||||
library
|
||||
exposed-modules: PGF2, PGF2.Internal, SG
|
||||
exposed-modules: PGF2, PGF2.Internal
|
||||
-- backwards compatibility API:
|
||||
--, PGF, PGF.Internal
|
||||
other-modules: PGF2.FFI, PGF2.Expr, PGF2.Type, SG.FFI
|
||||
other-modules: PGF2.FFI, PGF2.Expr, PGF2.Type
|
||||
build-depends: base >=4.3,
|
||||
containers, pretty
|
||||
-- hs-source-dirs:
|
||||
default-language: Haskell2010
|
||||
build-tools: hsc2hs
|
||||
|
||||
extra-libraries: sg pgf gu
|
||||
extra-libraries: pgf gu
|
||||
cc-options: -std=c99
|
||||
c-sources: utils.c
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
INSTALL_PATH = /usr/local
|
||||
|
||||
C_SOURCES = jpgf.c jsg.c jni_utils.c
|
||||
JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java) \
|
||||
$(wildcard org/grammaticalframework/sg/*.java)
|
||||
C_SOURCES = jpgf.c jni_utils.c
|
||||
JAVA_SOURCES = $(wildcard org/grammaticalframework/pgf/*.java)
|
||||
|
||||
JNI_INCLUDES = $(if $(wildcard /usr/lib/jvm/default-java/include/.*), -I/usr/lib/jvm/default-java/include -I/usr/lib/jvm/default-java/include/linux, \
|
||||
$(if $(wildcard /usr/lib/jvm/java-1.11.0-openjdk-amd64/include/.*), -I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include/ -I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include/linux, \
|
||||
@@ -28,13 +27,13 @@ LIBTOOL = $(if $(shell command -v glibtool 2>/dev/null), glibtool, libtool) --t
|
||||
all: libjpgf.la jpgf.jar
|
||||
|
||||
libjpgf.la: $(patsubst %.c, %.lo, $(C_SOURCES))
|
||||
$(LIBTOOL) --mode=link $(GCC) $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH)/lib -lgu -lpgf -lsg $(WINDOWS_LDFLAGS)
|
||||
$(LIBTOOL) --mode=link $(GCC) $(CFLAGS) -g -O -o libjpgf.la -shared $^ -rpath $(INSTALL_PATH)/lib -lgu -lpgf $(WINDOWS_LDFLAGS)
|
||||
|
||||
%.lo : %.c
|
||||
$(LIBTOOL) --mode=compile $(GCC) $(CFLAGS) -g -O -c $(JNI_INCLUDES) $(WINDOWS_CCFLAGS) -std=c99 -shared $< -o $@
|
||||
|
||||
jpgf.jar: $(patsubst %.java, %.class, $(JAVA_SOURCES))
|
||||
jar -cf $@ org/grammaticalframework/pgf/*.class org/grammaticalframework/sg/*.class
|
||||
jar -cf $@ org/grammaticalframework/pgf/*.class
|
||||
|
||||
%.class : %.java
|
||||
javac $<
|
||||
@@ -45,7 +44,7 @@ install: libjpgf.la jpgf.jar
|
||||
|
||||
|
||||
doc:
|
||||
javadoc org.grammaticalframework.pgf org.grammaticalframework.sg -d java-api
|
||||
javadoc org.grammaticalframework.pgf -d java-api
|
||||
|
||||
clean:
|
||||
rm -f *.lo
|
||||
|
||||
@@ -1,339 +0,0 @@
|
||||
#include <jni.h>
|
||||
#include <sg/sg.h>
|
||||
#include <pgf/expr.h>
|
||||
#include <pgf/linearizer.h>
|
||||
#include "jni_utils.h"
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_openSG(JNIEnv *env, jclass cls, jstring path)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
const char *fpath = (*env)->GetStringUTFChars(env, path, 0);
|
||||
|
||||
// Read the PGF grammar.
|
||||
SgSG* sg = sg_open(fpath, err);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, path, fpath);
|
||||
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The database cannot be opened";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(J)V");
|
||||
return (*env)->NewObject(env, cls, constrId, p2l(sg));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_close(JNIEnv *env, jobject self)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
sg_close(get_ref(env, self), err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The database cannot be closed";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
JNIEXPORT jobjectArray JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_readTriple(JNIEnv *env, jclass cls, jstring s)
|
||||
{
|
||||
GuPool* pool = gu_new_pool();
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuString buf = j2gu_string(env, s, tmp_pool);
|
||||
GuIn* in = gu_data_in((uint8_t*) buf, strlen(buf), tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
const int len = 3;
|
||||
|
||||
PgfExpr exprs[len];
|
||||
int res = pgf_read_expr_tuple(in, 3, exprs, pool, err);
|
||||
if (!gu_ok(err) || res == 0) {
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The expression cannot be parsed");
|
||||
gu_pool_free(tmp_pool);
|
||||
gu_pool_free(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
jclass pool_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Pool");
|
||||
jmethodID pool_constrId = (*env)->GetMethodID(env, pool_class, "<init>", "(J)V");
|
||||
jobject jpool = (*env)->NewObject(env, pool_class, pool_constrId, p2l(pool));
|
||||
|
||||
jclass expr_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Expr");
|
||||
jmethodID expr_constrId = (*env)->GetMethodID(env, expr_class, "<init>", "(Lorg/grammaticalframework/pgf/Pool;Ljava/lang/Object;J)V");
|
||||
|
||||
jobjectArray array = (*env)->NewObjectArray(env, len, expr_class, NULL);
|
||||
for (int i = 0; i < len; i++) {
|
||||
jobject obj = (*env)->NewObject(env, expr_class, expr_constrId, jpool, NULL, p2l(gu_variant_to_ptr(exprs[i])));
|
||||
(*env)->SetObjectArrayElement(env, array, i, obj);
|
||||
(*env)->DeleteLocalRef(env, obj);
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_queryTriple(JNIEnv *env, jobject self,
|
||||
jobject jsubj,
|
||||
jobject jpred,
|
||||
jobject jobj)
|
||||
{
|
||||
SgSG *sg = get_ref(env, self);
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
SgTriple triple;
|
||||
triple[0] = (jsubj == NULL) ? gu_null_variant
|
||||
: gu_variant_from_ptr((void*) get_ref(env, jsubj));
|
||||
triple[1] = (jpred == NULL) ? gu_null_variant
|
||||
: gu_variant_from_ptr((void*) get_ref(env, jpred));
|
||||
triple[2] = (jobj == NULL) ? gu_null_variant
|
||||
: gu_variant_from_ptr((void*) get_ref(env, jobj));
|
||||
|
||||
SgTripleResult* res = sg_query_triple(sg, triple, err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The query failed";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
jclass res_class = (*env)->FindClass(env, "org/grammaticalframework/sg/TripleResult");
|
||||
jmethodID constrId = (*env)->GetMethodID(env, res_class, "<init>", "(JLorg/grammaticalframework/pgf/Expr;Lorg/grammaticalframework/pgf/Expr;Lorg/grammaticalframework/pgf/Expr;)V");
|
||||
jobject jres = (*env)->NewObject(env, res_class, constrId, p2l(res), jsubj, jpred, jobj);
|
||||
|
||||
return jres;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_org_grammaticalframework_sg_TripleResult_hasNext(JNIEnv *env, jobject self)
|
||||
{
|
||||
SgTripleResult *res = get_ref(env, self);
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuPool* out_pool = gu_new_pool();
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
SgId key;
|
||||
SgTriple triple;
|
||||
int r = sg_triple_result_fetch(res, &key, triple, out_pool, err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The fetch failed";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(out_pool);
|
||||
gu_pool_free(tmp_pool);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
if (r) {
|
||||
SgTriple orig_triple;
|
||||
sg_triple_result_get_query(res, orig_triple);
|
||||
|
||||
jclass pool_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Pool");
|
||||
jmethodID pool_constrId = (*env)->GetMethodID(env, pool_class, "<init>", "(J)V");
|
||||
jobject jpool = (*env)->NewObject(env, pool_class, pool_constrId, p2l(out_pool));
|
||||
|
||||
jclass expr_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Expr");
|
||||
jmethodID constrId = (*env)->GetMethodID(env, expr_class, "<init>", "(Lorg/grammaticalframework/pgf/Pool;Ljava/lang/Object;J)V");
|
||||
|
||||
jclass result_class = (*env)->GetObjectClass(env, self);
|
||||
|
||||
jfieldID keyId = (*env)->GetFieldID(env, result_class, "key", "J");
|
||||
(*env)->SetLongField(env, self, keyId, key);
|
||||
|
||||
if (triple[0] != orig_triple[0]) {
|
||||
jfieldID subjId = (*env)->GetFieldID(env, result_class, "subj", "Lorg/grammaticalframework/pgf/Expr;");
|
||||
jobject jsubj = (*env)->NewObject(env, expr_class, constrId, jpool, jpool, p2l(gu_variant_to_ptr(triple[0])));
|
||||
(*env)->SetObjectField(env, self, subjId, jsubj);
|
||||
}
|
||||
|
||||
if (triple[1] != orig_triple[1]) {
|
||||
jfieldID predId = (*env)->GetFieldID(env, result_class, "pred", "Lorg/grammaticalframework/pgf/Expr;");
|
||||
jobject jpred = (*env)->NewObject(env, expr_class, constrId, jpool, jpool, p2l(gu_variant_to_ptr(triple[1])));
|
||||
(*env)->SetObjectField(env, self, predId, jpred);
|
||||
}
|
||||
|
||||
if (triple[2] != orig_triple[2]) {
|
||||
jfieldID objId = (*env)->GetFieldID(env, result_class, "obj", "Lorg/grammaticalframework/pgf/Expr;");
|
||||
jobject jobj = (*env)->NewObject(env, expr_class, constrId, jpool, jpool, p2l(gu_variant_to_ptr(triple[2])));
|
||||
(*env)->SetObjectField(env, self, objId, jobj);
|
||||
}
|
||||
|
||||
return JNI_TRUE;
|
||||
} else {
|
||||
gu_pool_free(out_pool);
|
||||
return JNI_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_grammaticalframework_sg_TripleResult_close(JNIEnv *env, jobject self)
|
||||
{
|
||||
SgTripleResult *res = get_ref(env, self);
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
sg_triple_result_close(res, err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "Closing the result failed";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_beginTrans(JNIEnv *env, jobject self)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
sg_begin_trans(get_ref(env, self), err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The transaction cannot be started";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_commit(JNIEnv *env, jobject self)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
sg_commit(get_ref(env, self), err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The transaction cannot be commited";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_rollback(JNIEnv *env, jobject self)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an exception frame that catches all errors.
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
sg_rollback(get_ref(env, self), err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The transaction cannot be rolled back";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_grammaticalframework_sg_SG_insertTriple(JNIEnv *env, jobject self,
|
||||
jobject jsubj,
|
||||
jobject jpred,
|
||||
jobject jobj)
|
||||
{
|
||||
SgSG *sg = get_ref(env, self);
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
SgTriple triple;
|
||||
triple[0] = gu_variant_from_ptr((void*) get_ref(env, jsubj));
|
||||
triple[1] = gu_variant_from_ptr((void*) get_ref(env, jpred));
|
||||
triple[2] = gu_variant_from_ptr((void*) get_ref(env, jobj));
|
||||
|
||||
SgId id = sg_insert_triple(sg, triple, err);
|
||||
if (!gu_ok(err)) {
|
||||
GuString msg;
|
||||
if (gu_exn_caught(err, SgError)) {
|
||||
msg = (GuString) gu_exn_caught_data(err);
|
||||
} else {
|
||||
msg = "The insertion failed";
|
||||
}
|
||||
throw_string_exception(env, "org/grammaticalframework/sg/SGError", msg);
|
||||
gu_pool_free(tmp_pool);
|
||||
return 0;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package org.grammaticalframework.sg;
|
||||
|
||||
import java.io.Closeable;
|
||||
import org.grammaticalframework.pgf.*;
|
||||
|
||||
/** This class represents a connection to a semantic graph database.
|
||||
* The semantic graph is a graph represented as a set of tripples
|
||||
* of abstract expressions. The graph can be used for instance to store
|
||||
* semantic information for entities in a GF grammar.
|
||||
*/
|
||||
public class SG implements Closeable {
|
||||
/** Opens a new database file. */
|
||||
public static native SG openSG(String path) throws SGError;
|
||||
|
||||
/** Closes an already opened database. */
|
||||
public native void close() throws SGError;
|
||||
|
||||
/** Reads a triple in the format <expr,expr,expr> and returns it as an array. */
|
||||
public static native Expr[] readTriple(String s) throws PGFError;
|
||||
|
||||
/** Simple triple queries.
|
||||
* Each of the arguments subj, pred and obj could be null.
|
||||
* A null argument is interpreted as a wild card.
|
||||
* If one of the arguments is not null then only triples with matching values
|
||||
* will be retrieved.
|
||||
*
|
||||
* @return An iterator over the matching triples.
|
||||
*/
|
||||
public native TripleResult queryTriple(Expr subj, Expr pred, Expr obj) throws SGError;
|
||||
|
||||
/** Starts a new transaction. */
|
||||
public native void beginTrans() throws SGError;
|
||||
|
||||
/** Commits the transaction. */
|
||||
public native void commit() throws SGError;
|
||||
|
||||
/** Rollbacks all changes made in the current transaction. */
|
||||
public native void rollback() throws SGError;
|
||||
|
||||
/** Inserts a new triple.
|
||||
* @return an unique id that identifies this triple in the database
|
||||
*/
|
||||
public native long insertTriple(Expr subj, Expr pred, Expr obj) throws SGError;
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// private stuff
|
||||
private long ref;
|
||||
|
||||
private SG(long ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
|
||||
static {
|
||||
System.loadLibrary("jpgf");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package org.grammaticalframework.sg;
|
||||
|
||||
/** This exception is thrown if an error occurs in the semantic graph.
|
||||
*/
|
||||
public class SGError extends RuntimeException {
|
||||
private static final long serialVersionUID = -6098784400143861939L;
|
||||
|
||||
public SGError(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package org.grammaticalframework.sg;
|
||||
|
||||
import java.io.Closeable;
|
||||
import org.grammaticalframework.pgf.Expr;
|
||||
|
||||
/** This class is used to iterate over a list of triples.
|
||||
* To move to the next triple, call {@link TripleResult#hasNext}.
|
||||
* When you do not need the iterator anymore then call {@link TripleResult#close}
|
||||
* to release the allocated resources.
|
||||
*/
|
||||
public class TripleResult implements Closeable {
|
||||
public native boolean hasNext();
|
||||
|
||||
/** Closes the iterator and releases the allocated resources. */
|
||||
public native void close();
|
||||
|
||||
/** Each triple has an unique integer key. You can get the key for
|
||||
* the current triple by calling {@link TripleResult#getKey}.
|
||||
*/
|
||||
public long getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/** This is the first element of the current triple. */
|
||||
public Expr getSubject() {
|
||||
return subj;
|
||||
}
|
||||
|
||||
/** This is the second element of the current triple. */
|
||||
public Expr getPredicate() {
|
||||
return pred;
|
||||
}
|
||||
|
||||
/** This is the third element of the current triple. */
|
||||
public Expr getObject() {
|
||||
return obj;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// private stuff
|
||||
private long ref;
|
||||
private long key;
|
||||
private Expr subj;
|
||||
private Expr pred;
|
||||
private Expr obj;
|
||||
|
||||
private TripleResult(long ref, Expr subj, Expr pred, Expr obj) {
|
||||
this.ref = ref;
|
||||
this.subj = subj;
|
||||
this.pred = pred;
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user