您的位置:首页 > 运维架构 > Linux

Linux 数据库学习---mysql常用的数据类型

2015-08-17 10:00 621 查看
• MYSQL

该结构代表1个数据库连接的句柄。几乎所有的MySQL函数均使用它。不应尝试拷贝MYSQL结构。不保证这类拷贝结果会有用

typedef struct st_mysql

{

NET net;
/* Communication parameters */

unsigned char *connector_fd;
/* ConnectorFd for SSL */

char *host,*user,*passwd,*unix_socket,*server_version,*host_info;

char *info, *db;

struct charset_info_st *charset;

MYSQL_FIELD *fields;

MEM_ROOT field_alloc;

my_ulonglong affected_rows;

my_ulonglong insert_id; /* id if insert on table with NEXTNR */

my_ulonglong extra_info; /* Not used */

unsigned long thread_id; /* Id for connection in server */

unsigned long packet_length;

unsigned int port;

unsigned long client_flag,server_capabilities;

unsigned int protocol_version;

unsigned int field_count;

unsigned int server_status;

unsigned int server_language;

unsigned int warning_count;

struct st_mysql_options options;

enum mysql_status status;

my_bool free_me;
/* If free in mysql_close */

my_bool reconnect;
/* set to 1 if automatic reconnect */

/* session-wide random string */

char scramble[SCRAMBLE_LENGTH+1];

my_bool unused1;

void *unused2, *unused3, *unused4, *unused5;

LIST *stmts; /* list of all statements */

const struct st_mysql_methods *methods;

void *thd;

/*

Points to boolean flag in MYSQL_RES or MYSQL_STMT. We set this flag

from mysql_stmt_close if close had to cancel result set of this object.

*/

my_bool *unbuffered_fetch_owner;

/* needed for embedded server - no net buffer to store the 'info' */

char *info_buffer;

void *extension;

} MYSQL;

• MYSQL_RES

该结构代表返回行的查询结果(SELECT, SHOW, DESCRIBE, EXPLAIN)

typedef struct st_mysql_res {

my_ulonglong row_count;

MYSQL_FIELD *fields;

MYSQL_DATA *data;

MYSQL_ROWS *data_cursor;

unsigned long *lengths; /* column lengths of current row */

MYSQL *handle;
/* for unbuffered reads */

const struct st_mysql_methods *methods;

MYSQL_ROW row;
/* If unbuffered read */

MYSQL_ROW current_row;
/* buffer to current row */

MEM_ROOT field_alloc;

unsigned int field_count, current_field;

my_bool eof;
/* Used by mysql_fetch_row */

/* mysql_stmt_close() had to cancel this result */

my_bool unbuffered_fetch_cancelled;

void *extension;

} MYSQL_RES;

MYSQL_ROW

这是1行数据的“类型安全”表示。它目前是按照计数字节字符串的数组实施的。(如果字段值可能包含二进制数据,不能将其当作由Null终结的字符串对待,这是因为这类值可能会包含Null字节)。行是通过调用mysql_fetch_row()获得的

typedef char **MYSQL_ROW; /* return data as array of strings */

• MYSQL_FIELD

该结构包含关于字段的信息,如字段名、类型和大小。这里详细介绍了其成员。通过重复调用mysql_fetch_field(),可为每个字段获得MYSQL_FIELD结构。字段值不是该结构的组成部份,它们包含在MYSQL_ROW结构中

typedef struct st_mysql_field {

char *name; /* Name of column */

char *org_name; /* Original column name, if an alias */

char *table; /* Table of column if column was a field */

char *org_table; /* Org table name, if table was an alias */

char *db; /* Database for table */

char *catalog; /* Catalog for table */

char *def; /* Default value (set by mysql_list_fields) */

unsigned long length; /* Width of column (create length) */

unsigned long max_length; /* Max width for selected set */

unsigned int name_length;

unsigned int org_name_length;

unsigned int table_length;

unsigned int org_table_length;

unsigned int db_length;

unsigned int catalog_length;

unsigned int def_length;

unsigned int flags; /* Div flags */

unsigned int decimals; /* Number of decimals in field */

unsigned int charsetnr; /* Character set */

enum enum_field_types type; /* Type of field. See mysql_com.h for types */

void *extension;

} MYSQL_FIELD;

• MYSQL_FIELD_OFFSET

这是MySQL字段列表偏移量的“类型安全”表示(由mysql_field_seek()使用)。偏移量是行内的字段编号,从0开始。

typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */

• my_ulonglong

用于行数以及mysql_affected_rows()、mysql_num_rows()和mysql_insert_id()的类型。该类型提供的范围为0~1.84e19。 在某些系统上,不能打印类型my_ulonglong的值。要想打印这类值,请将其转换为无符号长整数类型并使用%lu打印格式

#ifndef _global_h

#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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: