📄 sdmysql.pas
字号:
{*******************************************************}
{ }
{ Delphi SQLDirect Component Library }
{ MySQL API Interface Unit }
{ MySQL API ver.3.23.36 (Date: 23.03.2001) }
{ MySQL API ver.4.00.12 (Date: 15.03.2003) }
{ MySQL API ver.4.1.7 (Date: 25.10.2004) }
{ Copyright (c) 1997,2005 by Yuri Sheino }
{ }
{*******************************************************}
{$I SqlDir.inc}
unit SDMySql {$IFDEF SD_CLR} platform {$ENDIF};
interface
uses
Windows, SysUtils, Classes, Db, Registry, SyncObjs,
{$IFDEF SD_CLR}
System.Runtime.InteropServices,
{$ENDIF}
SDConsts, SDCommon;
{*******************************************************************************
* mysql_com.h - Common definition between mysql server & client *
*******************************************************************************}
const
NAME_LEN = 64; // Field/table name length
HOSTNAME_LENGTH = 60;
USERNAME_LENGTH = 16;
SERVER_VERSION_LENGTH = 60;
LOCAL_HOST = 'localhost';
LOCAL_HOST_NAMEDPIPE = '.';
MYSQL_NAMEDPIPE = 'MySQL';
MYSQL_SERVICENAME = 'MySql';
type
TMyBool = Char;
TMySocket = Integer;
TGPtr = TSDCharPtr;
PCHARSET_INFO = TSDCharPtr;
UInt = Cardinal; { 32 bit unsigned }
ULong = Cardinal; { 32 bit unsigned }
TServerCommand = (
COM_SLEEP,COM_QUIT,COM_INIT_DB,COM_QUERY,
COM_FIELD_LIST,COM_CREATE_DB,COM_DROP_DB,COM_REFRESH,
COM_SHUTDOWN,COM_STATISTICS,
COM_PROCESS_INFO,COM_CONNECT,COM_PROCESS_KILL,
COM_DEBUG,COM_PING,COM_TIME,COM_DELAYED_INSERT,
COM_CHANGE_USER, COM_BINLOG_DUMP,
COM_TABLE_DUMP, COM_CONNECT_OUT, COM_REGISTER_SLAVE,
COM_END
);
const
NOT_NULL_FLAG = 1; // Field can't be NULL
PRI_KEY_FLAG = 2; // Field is part of a primary key
UNIQUE_KEY_FLAG = 4; // Field is part of a unique key
MULTIPLE_KEY_FLAG = 8; // Field is part of a key
BLOB_FLAG = 16; // Field is a blob
UNSIGNED_FLAG = 32; // Field is unsigned
ZEROFILL_FLAG = 64; // Field is zerofill
BINARY_FLAG = 128;
// The following are only sent to new clients
ENUM_FLAG = 256; // field is an enum
AUTO_INCREMENT_FLAG = 512; // field is a autoincrement field
TIMESTAMP_FLAG = 1024; // Field is a timestamp
SET_FLAG = 2048; // field is a set
NUM_FLAG = 32768; // Field is num (for clients)
PART_KEY_FLAG = 16384; // Intern; Part of some key
GROUP_FLAG = 32768; // Intern: Group field
UNIQUE_FLAG = 65536; // Intern: Used by sql_yacc
REFRESH_GRANT = 1; // Refresh grant tables
REFRESH_LOG = 2; // Start on new log file
REFRESH_TABLES = 4; // close all tables
REFRESH_HOSTS = 8; // Flush host cache
REFRESH_STATUS = 16; // Flush status variables
REFRESH_THREADS = 32; // Flush status variables
REFRESH_SLAVE = 64; // Reset master info and restart slave thread
REFRESH_MASTER = 128; // Remove all bin logs in the index and truncate the index
// The following can't be set with mysql_refresh()
REFRESH_READ_LOCK = 16384; // Lock tables for read
REFRESH_FAST = 32768; // Intern flag
// RESET (remove all queries) from query cache
REFRESH_QUERY_CACHE = 65536;
REFRESH_QUERY_CACHE_FREE= $20000; // pack query cache
REFRESH_DES_KEY_FILE = $40000;
REFRESH_USER_RESOURCES= $80000;
CLIENT_LONG_PASSWORD = 1; // new more secure passwords
CLIENT_FOUND_ROWS = 2; // Found instead of affected rows
CLIENT_LONG_FLAG = 4; // Get all column flags
CLIENT_CONNECT_WITH_DB= 8; // One can specify db on connect
CLIENT_NO_SCHEMA = 16; // Don't allow database.table.column
CLIENT_COMPRESS = 32; // Can use compression protocol
CLIENT_ODBC = 64; // Odbc client
CLIENT_LOCAL_FILES = 128; // Can use LOAD DATA LOCAL
CLIENT_IGNORE_SPACE = 256; // Ignore spaces before '('
CLIENT_CHANGE_USER = 512; // Support the mysql_change_user()
CLIENT_INTERACTIVE = 1024; // This is an interactive client
CLIENT_SSL = 2048; // Switch to SSL after handshake
CLIENT_IGNORE_SIGPIPE = 4096; // IGNORE sigpipes
CLIENT_TRANSACTIONS = 8192; // Client knows about transactions
SERVER_STATUS_IN_TRANS = 1; // Transaction has started
SERVER_STATUS_AUTOCOMMIT= 2; // Server in auto_commit mode
MYSQL_ERRMSG_SIZE = 200;
NET_READ_TIMEOUT = 30; // Timeout on read
NET_WRITE_TIMEOUT = 60; // Timeout on write
NET_WAIT_TIMEOUT = 8*60*60; // Wait for new query
MAX_CHAR_WIDTH = 255; // Max length for a CHAR colum
MAX_BLOB_WIDTH = 8192; // Default width for blob
type
TNET = packed record
vio: TSDPtr;
fd: TMySocket;
fcntl: Integer; // For Perl DBI/dbd
buff: TSDCharPtr;
buff_end: TSDCharPtr;
write_pos: TSDCharPtr;
read_pos: TSDCharPtr;
last_error: array[0..MYSQL_ERRMSG_SIZE] of Char;
last_errno: Integer;
max_packet: Integer;
timeout: Integer;
pkt_nr: Integer;
error: Char;
return_errno: TMyBool;
compress: TMyBool;
no_send_ok: TMyBool; // needed if we are doing several queries in one command ( as in LOAD TABLE ... FROM MASTER ),
// and do not want to confuse the client with OK at the wrong time
remain_in_buf: LongInt;
length: LongInt;
buf_length: LongInt;
where_b: LongInt;
return_status: PInteger;
reading_or_writing: Char;
save_char: Char;
end;
const
// Enum Field Types
FIELD_TYPE_DECIMAL = 0;
FIELD_TYPE_TINY = 1;
FIELD_TYPE_SHORT = 2;
FIELD_TYPE_LONG = 3;
FIELD_TYPE_FLOAT = 4;
FIELD_TYPE_DOUBLE = 5;
FIELD_TYPE_NULL = 6;
FIELD_TYPE_TIMESTAMP = 7;
FIELD_TYPE_LONGLONG = 8;
FIELD_TYPE_INT24 = 9;
FIELD_TYPE_DATE = 10;
FIELD_TYPE_TIME = 11;
FIELD_TYPE_DATETIME = 12;
FIELD_TYPE_YEAR = 13;
FIELD_TYPE_NEWDATE = 14;
FIELD_TYPE_ENUM = 247;
FIELD_TYPE_SET = 248;
FIELD_TYPE_TINY_BLOB = 249;
FIELD_TYPE_MEDIUM_BLOB = 250;
FIELD_TYPE_LONG_BLOB = 251;
FIELD_TYPE_BLOB = 252;
FIELD_TYPE_VAR_STRING= 253;
FIELD_TYPE_STRING = 254;
FIELD_TYPE_GEOMETRY = 255;
// For Compatibility
FIELD_TYPE_CHAR = FIELD_TYPE_TINY;
FIELD_TYPE_INTERVAL = FIELD_TYPE_ENUM;
{*******************************************************************************
* mysql.h - defines for the libmysql library *
*******************************************************************************}
type
TOnMyErrorProc = procedure;
{$IFDEF SD_CLR}
PULong = TSDPtr;
PUSED_MEM = TSDPtr;
PMEM_ROOT = TSDPtr;
POnMyErrorProc= TSDPtr;
{$ELSE}
PULong = ^ULong;
PUSED_MEM = ^TUSED_MEM;
PMEM_ROOT = ^TMEM_ROOT;
POnMyErrorProc = ^TOnMyErrorProc;
{$ENDIF}
TUSED_MEM = packed record // struct for once_alloc
next: PUSED_MEM; // Next block in use
left: Integer; // memory left in block
size: Integer; // size of block
end;
TMEM_ROOT = packed record
free: PUSED_MEM;
used: PUSED_MEM;
pre_alloc: PUSED_MEM;
min_malloc: Integer;
block_size: Integer;
error_handler: POnMyErrorProc;
end;
(*
// extern unsigned int mysql_port;
// extern char *mysql_unix_port;
#define IS_PRI_KEY(n) ((n) & PRI_KEY_FLAG)
#define IS_NOT_NULL(n) ((n) & NOT_NULL_FLAG)
#define IS_BLOB(n) ((n) & BLOB_FLAG)
#define IS_NUM(t) ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
#define IS_NUM_FIELD(f) ((f)->flags & NUM_FLAG)
#define INTERNAL_NUM_FIELD(f) (((f)->type <= FIELD_TYPE_INT24 && ((f)->type != FIELD_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == FIELD_TYPE_YEAR)
*)
TMYSQL_FIELD_V3 = record
name: TSDCharPtr; // Name of column
table: TSDCharPtr; // Table of column if column was a field
def: TSDCharPtr; // Default value (set by mysql_list_fields)
ftype: Byte; // Type of field. Se mysql_com.h for types
length: Integer; // Width of column
max_length: Integer; // Max width of selected set
flags: Integer; // Div flags
decimals: Integer; // Number of decimals in field
end;
TMYSQL_FIELD_V4 = record
name: TSDCharPtr; // Name of column
table: TSDCharPtr; // Table of column if column was a field
org_table: TSDCharPtr; // Org table name if table was an alias
db: TSDCharPtr; // Database for table
def: TSDCharPtr; // Default value (set by mysql_list_fields)
length: ULong; // Width of column
max_length: ULong; // Max width of selected set
flags: UInt; // Div flags
decimals: UInt; // Number of decimals in field
ftype: Byte; // Type(enum in C decl.) of field. Se mysql_com.h for types
end;
TMYSQL_FIELD_V41 = record
name: TSDCharPtr; // Name of column
org_name: TSDCharPtr; // Original column name, if an alias
table: TSDCharPtr; // Table of column if column was a field
org_table: TSDCharPtr; // Org table name, if table was an alias
db: TSDCharPtr; // Database for table
catalog: TSDCharPtr; // Catalog for table
def: TSDCharPtr; // Default value (set by mysql_list_fields)
length: ULong; // Width of column (create length)
max_length: ULong; // Max width for selected set
name_length: UInt;
org_name_length: UInt;
table_length: UInt;
org_table_length: UInt;
db_length: UInt;
catalog_length: UInt;
def_length: UInt;
flags: UInt; // Div flags
decimals: UInt; // Number of decimals in field
charsetnr: UInt; // Character set
ftype: Byte; // Type of field. See mysql_com.h for types
end;
{$IFDEF SD_CLR}
PMYSQL_V3 = TSDPtr;
PMYSQL_V4 = TSDPtr;
PMYSQL_FIELD_V3 = TSDPtr;
PMYSQL_FIELD_V4 = TSDPtr;
PMYSQL_ROW = TSDPtr;
{$ELSE}
PMYSQL_V3 = ^TMYSQL_V3;
PMYSQL_V4 = ^TMYSQL_V4;
PMYSQL_FIELD_V3 = ^TMYSQL_FIELD_V3;
PMYSQL_FIELD_V4 = ^TMYSQL_FIELD_V4;
PMYSQL_ROW = ^TMYSQL_ROW;
{$ENDIF}
PMYSQL_FIELD = TSDPtr;
TMYSQL_ROW = array[00..$FF] of TSDCharPtr; // return data as array of pointers to strings
TMYSQL_FIELD_OFFSET = UInt; // offset to current field
(*
#if defined(NO_CLIENT_LONG_LONG)
typedef unsigned long my_ulonglong;
#elif defined (__WIN__)
typedef unsigned __int64 my_ulonglong;
#else
typedef unsigned long long my_ulonglong;
#endif
#define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
*)
TMyInt64 = TInt64;
{$IFDEF SD_CLR}
PMYSQL_ROWS = TSDPtr;
PMYSQL_DATA = TSDPtr;
{$ELSE}
PMYSQL_ROWS = ^TMYSQL_ROWS;
PMYSQL_DATA = ^TMYSQL_DATA;
{$ENDIF}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -