xLib/mysql_tool.c File Reference

MySQL用ライブラリ. More...

#include "mysql_tool.h"
Include dependency graph for mysql_tool.c:

Go to the source code of this file.

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)
ライブラリ
--L/usr/local/mysql/lib/mysql -lmysqlclient

Definition in file mysql_tool.c.


Function Documentation

void sql_close ( MYSQL *  mysql  ) 

Definition at line 50 of file mysql_tool.c.

00051 {
00052     if (mysql!=NULL) mysql_close(mysql);
00053 
00054     return;
00055 }

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 }

Here is the call graph for this function:


Generated on 15 Nov 2023 for JunkBox_Lib by  doxygen 1.6.1