MySQL用ライブラリ ヘッダ. More...
#include "xtools.h"
#include <mysql/mysql.h>
Go to the source code of this file.
Defines | |
#define | SQL_CONF_FILE "/etc/my.cnf" |
#define | SQL_DEFAULT_TIMEOUT 10 |
Functions | |
MYSQL * | sql_open (char *hostname, char *dbname, char *username, char *passwd, unsigned int tmot) |
void | sql_close (MYSQL *mysql) |
Definition in file mysql_tool.h.
#define SQL_CONF_FILE "/etc/my.cnf" |
Definition at line 25 of file mysql_tool.h.
Referenced by sql_open().
#define SQL_DEFAULT_TIMEOUT 10 |
Definition at line 26 of file mysql_tool.h.
Referenced by sql_open().
void sql_close | ( | MYSQL * | mysql | ) |
Definition at line 50 of file mysql_tool.c.
MYSQL* sql_open | ( | char * | hostname, | |
char * | dbname, | |||
char * | username, | |||
char * | passwd, | |||
unsigned int | tmot | |||
) |
Definition at line 14 of file mysql_tool.c.
References Buffer::buf, decomp_hostport(), file_exist(), free_Buffer(), make_Buffer_bystr, SQL_CONF_FILE, and SQL_DEFAULT_TIMEOUT.
00015 { 00016 MYSQL* mysql; 00017 MYSQL* cnnct; 00018 00019 Buffer host; 00020 unsigned short port; 00021 00022 if (hostname==NULL || dbname==NULL || username==NULL || passwd==NULL) return NULL; 00023 00024 Buffer wrk = make_Buffer_bystr(hostname); 00025 decomp_hostport(wrk, &host, &port); 00026 free_Buffer(&wrk); 00027 if (host.buf==NULL) return NULL; 00028 00029 if (tmot==0) tmot = SQL_DEFAULT_TIMEOUT; 00030 00031 mysql = mysql_init(NULL); 00032 if (mysql==NULL) return NULL; 00033 00034 if (file_exist(SQL_CONF_FILE)) { 00035 mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, SQL_CONF_FILE); 00036 } 00037 mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char*)&tmot); 00038 00039 cnnct = mysql_real_connect(mysql, (char*)host.buf, username, passwd, dbname, (int)port, NULL, 0); 00040 if (cnnct==NULL) { 00041 mysql_close(mysql); 00042 mysql = NULL; 00043 return NULL; 00044 } 00045 00046 return mysql; 00047 }