JunkBox_Lib 1.10.1
Loading...
Searching...
No Matches
mysql_tool.c
Go to the documentation of this file.
1
11#include "mysql_tool.h"
12
13
14MYSQL* sql_open(char* hostname, char* dbname, char* username, char* passwd, unsigned int tmot)
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}
48
49
50void sql_close(MYSQL* mysql)
51{
52 if (mysql!=NULL) mysql_close(mysql);
53
54 return;
55}
56
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Definition buffer.c:128
#define make_Buffer_bystr(str)
set_Buffer()
Definition buffer.h:57
MYSQL * sql_open(char *hostname, char *dbname, char *username, char *passwd, unsigned int tmot)
Definition mysql_tool.c:14
void sql_close(MYSQL *mysql)
Definition mysql_tool.c:50
MySQL用ライブラリ ヘッダ
#define SQL_CONF_FILE
Definition mysql_tool.h:22
#define SQL_DEFAULT_TIMEOUT
Definition mysql_tool.h:23
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