Summary: mysql c api
# mysql -u $user -p
>CREATE DATABASE control;
>USE control
>CREATE TABLE result(Id int not null auto_increment primary key,Time TimeStamp(14) not null,SP double not null,PV double not null,CV double not null );
>INSERT INTO result (SP,PV,CV) VALUES(1,2,3)
>DELETE FROM result;
>TRUNCATE result;
>DROP result;
>ALTER TABLE `result` CHANGE `number` `Id` DECIMAL( 9, 0 ) DEFAULT '0' NOT NULL;
>SET PASSWORD FOR $user=PASSWORD('password');
mysql = mysql_init((MYSQL*) 0);
res=mysql_use_result(mysql);
fields = mysql_fetch_fields(res);
row = mysql_fetch_row(res);
num_fields = mysql_num_fields(res);
Wyodrębnij szerokości kolumn:
lengths = mysql_fetch_lengths(res);
typedef struct st_mysql {
NET net; /* Communication parameters */
gptr connector_fd; /* ConnectorFd for SSL */
char *host,*user,*passwd,*unix_socket,
*server_version,*host_info,*info,*db;
unsigned int port,client_flag,server_capabilities;
unsigned int protocol_version;
unsigned int field_count;
unsigned int server_status;
unsigned long thread_id; /* Id for connection in server */
my_ulonglong affected_rows;
my_ulonglong insert_id; /* id if insert on table with NEXTNR */
my_ulonglong extra_info; /* Used by mysqlshow */
unsigned long packet_length;
enum mysql_status status;
MYSQL_FIELD *fields;
MEM_ROOT field_alloc;
my_bool free_me; /* If free in mysql_close */
my_bool reconnect; /* set to 1 if automatic reconnect */
struct st_mysql_options options;
char scramble_buff[9];
struct charset_info_st *charset;
unsigned int server_language;
} MYSQL;
typedef struct st_mysql_res {
my_ulonglong row_count;
unsigned int field_count, current_field;
MYSQL_FIELD *fields;
MYSQL_DATA *data;
MYSQL_ROWS *data_cursor;
MEM_ROOT field_alloc;
MYSQL_ROW row; /* If unbuffered read */
MYSQL_ROW current_row; /* buffer to current row */
unsigned long *lengths; /* column lengths of current row */
MYSQL *handle; /* for unbuffered reads */
my_bool eof; /* Used my mysql_fetch_row */
} MYSQL_RES;
typedef struct st_mysql_field {
char *name; /* Name of column */
char *table; /* Table of column if column was a field */
char *def; /* Default value (set by mysql_list_fields) */
enum enum_field_types type; /* Type of field. Se mysql_com.h for types */
unsigned int length; /* Width of column */
unsigned int max_length; /* Max width of selected set */
unsigned int flags; /* Div flags */
unsigned int decimals; /* Number of decimals in field */
} MYSQL_FIELD;
#include <mysql/mysql.h>
MYSQL *STDCALL mysql_init(MYSQL *mysql);
MYSQL *STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
const char *user,
const char *passwd,
const char *db,
unsigned int port,
const char *unix_socket,
unsigned int clientflag);
void STDCALL mysql_close(MYSQL *sock);
int STDCALL mysql_real_query(MYSQL *mysql, const char *q,unsigned long length);
MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql);
MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result);
unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
MYSQL_FIELD *STDCALL mysql_fetch_field(MYSQL_RES *result);
unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
Comments, questions, feedback, criticisms?