Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/mysqlfs/mysql.h

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



enum {	/* commands */
	CMDsleep = 0x00,		/* u/s internal thread state only */
	CMDquit = 0x01,			/* disconnect */
	CMDinit_db = 0x02,		/* sent for the "use" command */
	CMDquery = 0x03,		/* SQL query */
	CMDfield_list = 0x04,		/* show field info only */
	CMDcreate_db = 0x05,		/* create database (deprecated) */
	CMDdrop_db = 0x06,		/* drop database (deprecated) */
	CMDrefresh = 0x07,		/* close & reopen all logs, commit any open transactions */
	CMDshutdown = 0x08,		/* shutdown the database */
	CMDstatistics = 0x09,		/* server stats, returned as a single text packet */
	CMDprocess_info = 0x0a,		/* request process info, returned as a table */
	CMDconnect = 0x0b,		/* u/s internal thread state only */
	CMDprocess_kill = 0x0c,		/* kill process */
	CMDdebug = 0x0d,
	CMDping = 0x0e,
	CMDtime = 0x0f,			/* u/s internal thread state only */
	CMDdelayed_insert = 0x10,	/* u/s internal thread state only */
	CMDchange_user = 0x11,
	CMDbinlog_dump = 0x12,		/* master/slave database only */
	CMDtable_dump = 0x13,		/* master/slave database only */
	CMDconnect_out = 0x14,		/* master/slave database only */
	CMDregister_slave = 0x15,	/* master/slave database only */
	CMDstmt_prepare = 0x16,
	CMDstmt_execute = 0x17,
	CMDstmt_send_long_data = 0x18,
	CMDstmt_close = 0x19,
	CMDstmt_reset = 0x1a,
	CMDset_option = 0x1b,
	CMDstmt_fetch = 0x1c
};


#define MYSQL_SHUTDOWN_KILLABLE_CONNECT    (unsigned char)(1 << 0)
#define MYSQL_SHUTDOWN_KILLABLE_TRANS      (unsigned char)(1 << 1)
#define MYSQL_SHUTDOWN_KILLABLE_LOCK_TABLE (unsigned char)(1 << 2)
#define MYSQL_SHUTDOWN_KILLABLE_UPDATE     (unsigned char)(1 << 3)

enum{	/* shutdown level */
	SHUTdefault = 0,
	SHUTconn = 1,			/* default wait for existing connections to finish */
  	SHUTtrans = 2,			/* wait for existing trans to finish */
  	SHUTupdates = 8,		/* wait for existing updates to finish*/
  	SHUTbuffers = 16,		/* flush InnoDB buffers and other storage engines' buffers*/
  	SHUTcritbuf = 17,		/* don't flush InnoDB buffers, flush other storage engines' buffers*/
	KILLquery = 254,		/* kill the current query */
	KILLconn = 255			/* kill the connection */
};

enum{	/* capabilities negioated at session startup */
	CAPlong_passwords = 1,		/* long passwords */
	CAPfound_rows = 2,		/* Found  rows */
	CAPlong_flag = 4,		/* long column flags */
	CAPconnect_with_db = 8,		/* connect with database */

	CAPno_schema = 0x10,		/* Don't allow database.table.column */
	CAPcompression = 0x20,		/* Can use compression protocol */
	CAPodbc = 0x40,			/* Odbc client */
	CAPlocal_files = 0x80,		/* Can use LOAD DATA LOCAL */

	CAPignore_space = 0x100,	/* Ignore spaces before '(' */
	CAPprotocol_41 = 0x200,		/* speaks 4.1 protocol (new flag)  */
	CAPinteractive = 0x400,		/* interactive client */
	CAPssl = 0x800,			/* Switch to SSL after handshake */

	CAPignore_sigpipe = 0x1000,	/* ignore SIGPIPE */
	CAPtransactions = 0x2000,	/* knows about transactions */
	CAPreserved = 0x4000,		/* for v4.1.0 only (depricated) */
	CAPauthentication_41 = 0x8000,	/* can do 4.1 authentication */

	CAPmulti_statements = 0x10000,	/* supports multiple statments */
	CAPmulti_results = 0x20000	/* supports multiple results */


};

enum {	/* field types */
	FLDdecimal = 0x00,		/* double as a text string */
	FLDtiny = 0x01,			/* 8bit integer */
	FLDshort = 0x02,		/* 16 bit integer */
	FLDlong = 0x03,			/* 24 bit integer */
	FLDfloat = 0x04,		/* 32 bit integer */
	FLDdouble = 0x05,		/* 64 bit integer */
	FLDnull = 0x06,
	FLDtimestamp = 0x07,		/* yymmddhhmmss */
	FLDlonglong = 0x08,
	FLDint24 = 0x09,		/* 24 bit integer */
	FLDdate = 0x0a,			/* yy-mm-dd */
	FLDtime = 0x0b,			/* hh:mm:ss (hh may be hhh) */
	FLDdatetime = 0x0c,		/* yyyy-mm-dd hh:mm:ss */
	FLDyear = 0x0d,			/* yy or yyyy */
	FLDnewdate = 0x0e,
	FLDvarchar = 0x0f,		/* up to 255 char string, case insensitive, trailing whitespace stripped */
	FLDbit = 0x10,
	FLDnewdecimal = 0xf6,		/* double as a text string */
	FLDenum = 0xf7,			/* one of up to 2^16 values */
	FLDset = 0xf8,			/* any number of values from a set of up to 64 members */
	FLDtiny_blob = 0xf9,		/* up to 2^8 byte blob */
	FLDmedium_blob = 0xfa,		/* up to 2^24 byte blob */
	FLDlong_blob = 0xfb,		/* up to 2^32 byte blob */
	FLDblob = 0xfc,
	FLDvar_string = 0xfd,		/* text string */
	FLDstring = 0xfe,		/* text string */
	FLDgeometry = 0xff,
	FLDcom_register_slave = 0x15,
	FLDcom_stmt_prepare = 0x16,
	FLDcom_stmt_execute = 0x17,
	FLDcom_stmt_send_long_data = 0x18,
	FLDcom_stmt_close = 0x19,
	FLDcom_stmt_reset = 0x1a,
	FLDcom_set_option = 0x1b,
	FLDcom_stmt_fetch = 0x1c
};

enum {	/* field flags */
	FLGnot_null = 1,		/* field can't be nil */
	FLGpri_key = 2,			/* part of a primary key */
	FLGunique_key = 4,		/* part of a unique key */
	FLGmultiple_key = 8,		/* part of a key */
	FLGblob = 0x10,			/* binary large object */
	FLGunsigned = 0x20,		/* numeric data is unsigned */
	FLGzerofill = 0x40,
	FLGbinary = 0x80,		/* data is binary (e.g. string is case significant) */
	FLGenum = 0x100,
	FLGauto_increment = 0x200,
	FLGtimestamp = 0x400,
	FLGset = 0x800,
	FLGno_default = 0x1000,		/* no default value */
	FLGnum = 0x2000,		/* numeric (for clients) */
};

enum {	/* server status */
	STin_trans = 1,			/* in transaction */
	STautocommit = 2,		/* AUTO_COMMIT */
	STmore = 4,			/* more results */
	STmore_exists = 8,		/* multi query - more resultsets */
	STbad_index = 16,		/* no good index used */
	STindex_unused = 32,		/* no index used */
	STcursor_exists = 64,		/* cursor exists */
	STlast_sent = 128,		/* last row sent */
	STdropped = 256,		/* database dropped */
	STno_esc = 512			/* no backslash escapes */
	
};

enum {	/* first byte of reply */
	Rok = 0,			/* OK */
	Rerr = 0xff,			/* error */
	Reof = 0xfe			/* end of chunk */
};

enum {
	Nauth = 20,			/* all >= v4.1 authentication strings are this long */
};

typedef struct Field Field;
struct Field {
	Field *next;
	char *cat;		/* catalogue */
	char *db;		/* database */
	char *tab;		/* table */
	char *otab;		/* table name before AS clause */
	char *name;		/* field name */
	char *oname;		/* field name before AS clause */
	int lang;		/* character set ID */
	int size;		/* size (in backing store ?) */
	int type;		/* data type */
	int flags;		/* data type modifier */
	int prec;		/* digits after decimal to display */
	vlong def;		/* default value (in table definitions only) */
	int hasdef;		/* is def field valid ? */

	int start;		/* start collumn if fixed width output */
	int width;		/* field width if fixed width output */
};

typedef struct Col Col;
struct Col {
	Col *next;
	char *str;
};

typedef struct Row Row;
struct Row {
	Row *next;
	Col *cols;
};

typedef struct Results Results;
struct Results {
	Field *fields;
	Row *rows;
	int nf;			/* number of fields */
	int nr;			/* number of rows */

};

typedef struct Pkt Pkt;
struct Pkt {
	uchar *buf;		/* base of buffer */
	uchar *pos;		/* current position in buffer */
	uchar *end;		/* one byte off the end of the buffer */
	Results *results;	/* results */
};

typedef struct Sess Sess;
struct Sess {
	int proto;		/* protocol version */
	char *server;		/* server version */
	int tid;		/* server's thread ID */
	char *salt1;		/* salt part1 for authentication */
	int caps;		/* server capabilities */
	int lang;		/* server's language */
	int stat;		/* server's status */
	char *salt2;		/* salt part1 for authentication */
	int net;		/* network file descriptor */
	Lock lock;		/* lock on network - parallel queries no possible */
	int mtu;		/* maximum transfer unit */
	char *db;		/* the current database */
};

typedef struct Dbgname Dbgname;
struct Dbgname {
	int n;
	char *s;
};

typedef struct Layout Layout;
struct Layout {
	char rowsep;	/* row seperator if not fixed layout */
	char colsep;	/* collumn seperator if not fixed layout */
	int delimited;	/* delimited rather than padded collums */
	int headings;	/* add field headings to collumns */
};


extern vlong gpartnum(Pkt *, int, int *);
extern vlong gnum(Pkt *, int *);
extern void gskip(Pkt *, int);
extern void *gmem(Pkt *, int);
extern char *gstr(Pkt *);
extern char *gnstr(Pkt *);
extern char *gsall(Pkt *);
extern uvlong g64(Pkt *);
extern uint g32(Pkt *);
extern uint g24(Pkt *);
extern uint g16(Pkt *);
extern uint g8(Pkt *);
extern uint peek8(Pkt *);
extern void pnum(Pkt *, vlong, int);
extern void pskip(Pkt *, int);
extern void pmem(Pkt *, void *, int);
extern void pstr(Pkt *, char *);
extern void p64(Pkt *, uvlong);
extern void p32(Pkt *, uint);
extern void p24(Pkt *, uint);
extern void p16(Pkt *, uint);
extern void p8(Pkt *, uint);
extern int remain(Pkt *p);

void prbits(int, int, Dbgname *);

extern void freeres(Results *);
extern Sess *mysql_open(char *);
extern int mysql_auth(Sess *, char *, char *, uchar *);
extern int mysql_query(Sess *, char *, Results **);
extern int mysql_use(Sess *, char *);
extern char *mysql_stats(Sess *);
extern int mysql_kill(Sess *, int id);
extern int mysql_ping(Sess *);
extern int mysql_ps(Sess *, Results **);
extern int mysql_close(Sess *);

extern void widths(Results *);
extern char *fmtdata(Results *, Layout *, int);
extern char *fmtfields(Results *, int);

extern int Verbose;
extern int Debug;

extern Dbgname Cmds[];
extern Dbgname Status[];
extern Dbgname Caps[];
extern Dbgname Fields[];
extern Dbgname Flags[];

extern void xd(void *, int);
extern void dumpfield(Field *);
extern void dumpresults(Results *);

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].