⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapi.mx

📁 这个是内存数据库的客户端
💻 MX
📖 第 1 页 / 共 5 页
字号:
a buffer linked with the query handle from which selective fields canbe extracted.  It returns the number of fields recognized.  A zero isreturned upon encountering end of sequence or error. This can beanalyzed in using @code{mapi_error()}.@item int mapi_fetch_all_rows(MapiHdl hdl)All rows are cached at the client side first. Subsequent calls to@code{mapi_fetch_row()} will take the row from the cache. The number orrows cached is returned.@item int mapi_quick_response(MapiHdl hdl, FILE *fd)Read the answer to a query and pass the results verbatim to astream. The result is not analyzed or cached.@item MapiMsg mapi_seek_row(MapiHdl hdl, int rownr, int whence)Reset the row pointer to the requested row number.  If whence is@code{MAPI_SEEK_SET} (0), rownr is the absolute row number (0 being thefirst row); if whence is @code{MAPI_SEEK_CUR} (1), rownr is relative to thecurrent row; if whence is MAPI\_SEEK\_END (2), rownr is relative tothe last row.@item MapiMsg mapi_fetch_reset(MapiHdl hdl)Reset the row pointer to the first line in the cache.  This need notbe a tuple.  This is mostly used in combination with fetching alltuples at once.@item char **mapi_fetch_field_array(MapiHdl hdl)Return an array of string pointers to the individual fields.  A zerois returned upon encountering end of sequence or error. This can beanalyzed in using mapi\_error().@item char *mapi_fetch_field(MapiHdl hdl, int fnr)Return a pointer a C-string representation of the value returned.  Azero is returned upon encountering an error or when the database valueis NULL; this can be analyzed in using mapi\_error().@item MapiMsg mapi_next_result(MapiHdl hdl)Go to the next result set, discarding the rest of the output of thecurrent result set.@end itemize@- Errors@itemize@item MapiMsg mapi_error(Mapi mid)Return the last error code or 0 if there is no error.@item char *mapi_error_str(Mapi mid)Return a pointer to the last error message.@item char *mapi_result_error(MapiHdl hdl)Return a pointer to the last error message from the server.@item MapiMsg mapi_explain(Mapi mid, FILE *fd)Write the error message obtained from Mserver to a file.@item MapiMsg mapi_explain_query(MapiHdl hdl, FILE *fd)Write the error message obtained from Mserver to a file.@item MapiMsg mapi_explain_result(MapiHdl hdl, FILE *fd)Write the error message obtained from Mserver to a file.@end itemize@- Parameters@itemize@item MapiMsg mapi_bind(MapiHdl hdl, int fldnr, char **val)Bind a string variable with a field in the return table.  Upon asuccessful subsequent @code{mapi_fetch_row()} the indicated field is storedin the space pointed to by val.  Returns an error if the fieldidentified does not exist.@item MapiMsg mapi_bind_var(MapiHdl hdl, int fldnr, int type, void *val)Bind a variable to a field in the return table.  Upon a successfulsubsequent @code{mapi_fetch_row()}, the indicated field is converted to thegiven type and stored in the space pointed to by val.  The typesrecognized are @verb{ { } @code{MAPI_TINY, MAPI_UTINY, MAPI_SHORT, MAPI_USHORT,MAPI_INT, MAPI_UINT, MAPI_LONG, MAPI_ULONG, MAPI_LONGLONG,MAPI_ULONGLONG, MAPI_CHAR, MAPI_VARCHAR, MAPI_FLOAT, MAPI_DOUBLE,MAPI_DATE, MAPI_TIME, MAPI_DATETIME} @verb{ } }.  The binding operationsshould be performed after the mapi_execute command.  Subsequently allrows being fetched also involve delivery of the field values in theC-variables using proper conversion. For variable length strings apointer is set into the cache.@item MapiMsg mapi_bind_numeric(MapiHdl hdl, int fldnr, int scale, int precision, void *val)Bind to a numeric variable, internally represented by MAPI_INTDescribe the location of a numeric parameter in a query template.@item MapiMsg mapi_clear_bindings(MapiHdl hdl)Clear all field bindings.@item MapiMsg mapi_param(MapiHdl hdl, int fldnr, char **val)Bind a string variable with the n-th placeholder in the querytemplate.  No conversion takes place.@item MapiMsg mapi_param_type(MapiHdl hdl, int fldnr, int ctype, int sqltype, void *val)Bind a variable whose type is described by ctype to a parameter whosetype is described by sqltype.@item MapiMsg mapi_param_numeric(MapiHdl hdl, int fldnr, int scale, int precision, void *val)Bind to a numeric variable, internally represented by MAPI_INT.@item MapiMsg mapi_param_string(MapiHdl hdl, int fldnr, int sqltype, char *val, int *sizeptr)Bind a string variable, internally represented by MAPI_VARCHAR, to aparameter.  The sizeptr parameter points to the length of the stringpointed to by val.  If sizeptr == NULL or *sizeptr == -1, the stringis NULL-terminated.@item MapiMsg mapi_clear_params(MapiHdl hdl)Clear all parameter bindings.@end itemize@- Miscellaneous@itemize@item MapiMsg mapi_setAutocommit(Mapi mid, int autocommit)Set the autocommit flag (default is on).  This only has an effectwhen the language is SQL.  In that case, the server commits after eachstatement sent to the server.@item MapiMsg mapi_cache_limit(Mapi mid, int maxrows)A limited number of tuples are pre-fetched after each @code{execute()}.  Ifmaxrows is negative, all rows will be fetched before the applicationis permitted to continue. Once the cache is filled, a number of tuplesare shuffled to make room for new ones, but taking into accountnon-read elements.  Filling the cache quicker than reading leads to anerror.@item MapiMsg mapi_cache_shuffle(MapiHdl hdl, int percentage)Make room in the cache by shuffling percentage tuples out of thecache.  It is sometimes handy to do so, for example, when yourapplication is stream-based and you process each tuple as it arrivesand still need a limited look-back.  This percentage can be setbetween 0 to 100.  Making shuffle= 100% (default) leads to pagingbehavior, while shuffle==1 leads to a sliding window over a tuplestream with 1% refreshing.@item MapiMsg mapi_cache_freeup(MapiHdl hdl, int percentage)Forcefully shuffle the cache making room for new rows.  It ignores theread counter, so rows may be lost.@item char * mapi_quote(const char *str, int size)Escape special characters such as \n, \t in str withbackslashes.  The returned value is a newly allocated string whichshould be freed by the caller.@item char * mapi_unquote(const char *name)The reverse action of @code{mapi_quote()}, turning the databaserepresentation into a C-representation. The storage space isdynamically created and should be freed after use.@item MapiMsg  mapi_output(Mapi mid, char *output)Set the output format for results send by the server.@item MapiMsg  mapi_stream_into(Mapi mid, char *docname, char *colname)Stream a document into the server.@item MapiMsg  mapi_profile(Mapi mid, int flag)Set the profile flag to time commands send to the server.@item MapiMsg  mapi_trace(Mapi mid, int flag)Set the trace flag to monitor interaction with the server.@item int mapi_get_trace(Mapi mid)Return the current value of the trace flag.@item MapiMsg  mapi_trace_log(Mapi mid, const char *fname)Log the interaction between the client and server for offlineinspection. Beware that the log file overwrites any previous log. Itis not intended for recovery.@end itemizeThe remaining operations are wrappers around the data structuresmaintained. Note that column properties are derived from the tableoutput returned from the server.@itemize@item  char *mapi_get_name(MapiHdl hdl, int fnr)@item  char *mapi_get_type(MapiHdl hdl, int fnr)@item  char *mapi_get_table(MapiHdl hdl, int fnr)@item  int mapi_get_len(Mapi mid, int fnr)@item  char *mapi_get_dbname(Mapi mid)@item  char *mapi_get_host(Mapi mid)@item  char *mapi_get_user(Mapi mid)@item  char *mapi_get_lang(Mapi mid)@item  char *mapi_get_motd(Mapi mid)@item char **mapi_tables(Mapi mid)Return a list of accessible database tables.@item char **mapi_fields(Mapi mid)Return a list of accessible tables fields. This can also be obtainedby inspecting the field descriptor returned by @code{mapi_fetch_field()}.@end itemize@@{@- Implementation@c#include "clients_config.h"#include <monet_utils.h>#include <stream.h>		/* include before Mapi.h */#include "Mapi.h"#ifdef HAVE_UNISTD_H# include <unistd.h>#endif#include  <stdio.h>#ifdef HAVE_PWD_H#include  <pwd.h>#endif#include  <sys/types.h>#ifdef HAVE_SYS_SOCKET_H# include <sys/socket.h>#endif#ifdef NATIVE_WIN32# include <winsock.h>#endif#ifdef HAVE_SYS_UN_H#include <sys/un.h>#endif#include  <signal.h>#include  <string.h>#include  <memory.h>#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif#ifdef NATIVE_WIN32#define strdup _strdup#endif#ifdef HAVE_CRYPT_H# include <crypt.h>#else# if defined(HAVE_CRYPT) && defined(__MINGW32__)_CRTIMP char * __cdecl crypt(const char *key, const char *salt);# endif#endif#ifdef HAVE_OPENSSL# include <openssl/sha.h># include <openssl/md5.h>#endif@h#ifndef _MAPI_H_INCLUDED#define _MAPI_H_INCLUDED#include <stdio.h>		/* for FILE * */#define MAPI_AUTO	0	/* automatic type detection */#define MAPI_TINY	1#define MAPI_UTINY	2#define MAPI_SHORT	3#define MAPI_USHORT	4#define MAPI_INT	5#define MAPI_UINT	6#define MAPI_LONG	7#define MAPI_ULONG	8#define MAPI_LONGLONG	9#define MAPI_ULONGLONG	10#define MAPI_CHAR	11#define MAPI_VARCHAR	12#define MAPI_FLOAT	13#define MAPI_DOUBLE	14#define MAPI_DATE	15#define MAPI_TIME	16#define MAPI_DATETIME	17#define MAPI_NUMERIC	18#define PLACEHOLDER	'?'#define MAPI_SEEK_SET	0#define MAPI_SEEK_CUR	1#define MAPI_SEEK_END	2#define MAPI_TRACE	1#define MAPI_TRACE_LANG	2typedef int MapiMsg;#define MOK		0#define MERROR		(-1)#define MTIMEOUT	(-2)#define MMORE		(-3)#define MSERVER		(-4)#define LANG_MAL	0#define LANG_MIL	1#define LANG_SQL	2#define LANG_XQUERY	3@-The table field information is extracted from the table headersobtained from the server. This list may be extended in the future.The type of both the 'param' and 'binding'variables refer to their underlying C-type. They are used forautomatic type coercion between back-end and application.@c#define MAPIBLKSIZE	256	/* minimum buffer shipped *//* information about the columns in a result set */struct MapiColumn {	char *tablename;	char *columnname;	char *columntype;	int columnlength;};/* information about bound columns */struct MapiBinding {	void *outparam;		/* pointer to application variable */	int outtype;		/* type of application variable */	int precision;	int scale;};/* information about statement parameters */struct MapiParam {	void *inparam;		/* pointer to application variable */	int *sizeptr;		/* if string, points to length of string or -1 */	int intype;		/* type of application variable */	int outtype;		/* type of value */	int precision;	int scale;};@-The row cache contains a string representation of each (non-error) linereceived from the backend. After a mapi_fetch_row() or mapi_fetch_field()this string has been indexed from the anchor table, which holds a pointerto the start of the field. A sliced version is recognized by lookingat the fldcnt table, which tells you the number of fields recognized.Lines received from the server without 'standard' line headers areconsidered a single field.@cstruct MapiRowBuf {	int rowlimit;		/* maximum number of rows to cache */	int shuffle;		/* percentage of rows to shuffle upon overflow */	int limit;		/* current storage space limit */	int writer;	int reader;	int first;		/* row # of first tuple */	int tuplecount;		/* number of tuples in the cache */	struct {		int fldcnt;	/* actual number of fields in each row */		char *rows;	/* string representation of rows received */		int tupleindex;	/* index of tuple rows */		int tuplerev;	/* reverse map of tupleindex */		char **anchors;	/* corresponding field pointers */	} *line;};struct BlockCache {	char *buf;	int lim;	int nxt;	int end;	int eos;		/* end of sequence */};/* A connection to a server is represented by a struct MapiStruct.  An   application can have any number of connections to any number of   servers.  Connections are completely independent of each other.*/@htypedef struct MapiStruct *Mapi;/* this definition is a straight copy from sql/include/sql_query.h */typedef enum sql_query_t {	Q_PARSE = 0,	Q_TABLE = 1,	Q_UPDATE = 2,	Q_SCHEMA = 3,	Q_TRANS = 4,	Q_PREPARE = 5,	Q_BLOCK = 6} sql_query_t;@cstruct MapiStruct {	char *server;		/* server version */	char *mapiversion;	/* mapi version */	char *hostname;	int port;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -