JunkBox_Lib  1.10.2
mysql_tool.h File Reference

MySQL用ライブラリ ヘッダ More...

#include "xtools.h"
#include <mysql/mysql.h>
Include dependency graph for mysql_tool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#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)
 

Detailed Description

Author
Fumi.Iseki (C)
コンパイルオプション
–I/usr/local/mysql/include -L/usr/local/mysql/lib/mysql -lmysqlclient

Definition in file mysql_tool.h.

Macro Definition Documentation

◆ SQL_CONF_FILE

#define SQL_CONF_FILE   "/etc/my.cnf"

Definition at line 22 of file mysql_tool.h.

◆ SQL_DEFAULT_TIMEOUT

#define SQL_DEFAULT_TIMEOUT   10

Definition at line 23 of file mysql_tool.h.

Function Documentation

◆ sql_close()

void sql_close ( MYSQL *  mysql)

Definition at line 50 of file mysql_tool.c.

51 {
52  if (mysql!=NULL) mysql_close(mysql);
53 
54  return;
55 }

◆ sql_open()

MYSQL* sql_open ( char *  hostname,
char *  dbname,
char *  username,
char *  passwd,
unsigned int  tmot 
)

Definition at line 14 of file mysql_tool.c.

15 {
16  MYSQL* mysql;
17  MYSQL* cnnct;
18 
19  Buffer host;
20  unsigned short port;
21 
22  if (hostname==NULL || dbname==NULL || username==NULL || passwd==NULL) return NULL;
23 
24  Buffer wrk = make_Buffer_bystr(hostname);
25  decomp_hostport(wrk, &host, &port);
26  free_Buffer(&wrk);
27  if (host.buf==NULL) return NULL;
28 
29  if (tmot==0) tmot = SQL_DEFAULT_TIMEOUT;
30 
31  mysql = mysql_init(NULL);
32  if (mysql==NULL) return NULL;
33 
35  mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, SQL_CONF_FILE);
36  }
37  mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, (char*)&tmot);
38 
39  cnnct = mysql_real_connect(mysql, (char*)host.buf, username, passwd, dbname, (int)port, NULL, 0);
40  if (cnnct==NULL) {
41  mysql_close(mysql);
42  mysql = NULL;
43  return NULL;
44  }
45 
46  return mysql;
47 }
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition: buffer.c:128
#define make_Buffer_bystr(str)
set_Buffer()
Definition: buffer.h:57
#define SQL_CONF_FILE
Definition: mysql_tool.h:22
#define SQL_DEFAULT_TIMEOUT
Definition: mysql_tool.h:23
Definition: buffer.h:35
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.
Definition: buffer.h:39
int file_exist(const char *fn)
ファイルの存在を検査する.
Definition: tools.c:2337
int decomp_hostport(Buffer buf, Buffer *host, unsigned short *port)
"ホスト名:ポート番号" 形式の文字列から,ホスト名とポート番号を分離する.
Definition: xtools.c:720

References Buffer::buf, decomp_hostport(), file_exist(), free_Buffer(), make_Buffer_bystr, SQL_CONF_FILE, and SQL_DEFAULT_TIMEOUT.

Here is the call graph for this function: