Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
c67d7e67
Commit
c67d7e67
authored
Nov 01, 2007
by
unknown
Browse files
Options
Browse Files
Download
Plain Diff
Merge tulin@bk-internal.mysql.com:/home/bk/mysql-5.1-new-ndb
into whalegate.ndb.mysql.com:/home/tomas/cge-5.1
parents
4ce44da3
6be01f7f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
274 additions
and
1 deletion
+274
-1
storage/ndb/test/include/dbutil.hpp
storage/ndb/test/include/dbutil.hpp
+97
-0
storage/ndb/test/src/Makefile.am
storage/ndb/test/src/Makefile.am
+1
-1
storage/ndb/test/src/dbutil.cpp
storage/ndb/test/src/dbutil.cpp
+176
-0
No files found.
storage/ndb/test/include/dbutil.hpp
0 → 100755
View file @
c67d7e67
// dbutil.h: interface for the database utilities class.
//////////////////////////////////////////////////////////////////////
// Supplies a database to the test application
//////////////////////////////////////////////////////////////////////
#ifndef DBUTIL_HPP
#define DBUTIL_HPP
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <mysql.h>
//include "rand.h"
#include <stdlib.h>
//#define DEBUG
#define DIE_UNLESS(expr) \
((void) ((expr) ? 0 : (Die(__FILE__, __LINE__, #expr), 0)))
#define DIE(expr) \
Die(__FILE__, __LINE__, #expr)
#define myerror(msg) PrintError(msg)
#define mysterror(stmt, msg) PrintStError(stmt, msg)
#define CheckStmt(stmt) \
{ \
if ( stmt == 0) \
myerror(NULL); \
DIE_UNLESS(stmt != 0); \
}
#define check_execute(stmt, r) \
{ \
if (r) \
mysterror(stmt, NULL); \
DIE_UNLESS(r == 0);\
}
#define TRUE 1
#define FALSE 0
class
dbutil
{
public:
dbutil
(
const
char
*
databaseName
);
~
dbutil
();
void
DatabaseLogin
(
const
char
*
system
,
const
char
*
usr
,
const
char
*
password
,
unsigned
int
portIn
,
const
char
*
sockIn
,
bool
transactional
);
char
*
GetDbName
(){
return
dbs
;};
char
*
GetUser
(){
return
user
;};
char
*
GetPassword
(){
return
pass
;};
char
*
GetHost
(){
return
host
;};
char
*
GetSocket
(){
return
socket
;};
const
char
*
GetServerType
(){
return
mysql_get_server_info
(
myDbHandel
);};
MYSQL
*
GetDbHandel
(){
return
myDbHandel
;};
MYSQL_STMT
*
STDCALL
MysqlSimplePrepare
(
const
char
*
query
);
int
Select_DB
();
int
Do_Query
(
char
*
stm
);
const
char
*
GetError
();
int
GetErrorNumber
();
unsigned
long
SelectCountTable
(
const
char
*
table
);
private:
//Connect variables
char
*
databaseName
;
//hold results file name
char
host
[
256
];
// Computer to connect to
char
user
[
256
];
// MySQL User
char
pass
[
256
];
// MySQL User Password
char
dbs
[
256
];
// Database to use (TPCB)
unsigned
int
port
;
// MySQL Server port
char
socket
[
256
];
// MySQL Server Unix Socket
MYSQL
*
myDbHandel
;
void
DatabaseLogout
();
void
SetDbName
(
const
char
*
name
){
strcpy
((
char
*
)
dbs
,
name
);};
void
SetUser
(
const
char
*
userName
){
strcpy
((
char
*
)
user
,
userName
);};
void
SetPassword
(
const
char
*
password
){
strcpy
((
char
*
)
pass
,
password
);};
void
SetHost
(
const
char
*
system
){
strcpy
((
char
*
)
host
,
system
);};
void
SetPort
(
unsigned
int
portIn
){
port
=
portIn
;};
void
SetSocket
(
const
char
*
sockIn
){
strcpy
((
char
*
)
socket
,
sockIn
);};
void
PrintError
(
const
char
*
msg
);
void
PrintStError
(
MYSQL_STMT
*
stmt
,
const
char
*
msg
);
void
Die
(
const
char
*
file
,
int
line
,
const
char
*
expr
);
// stop program
};
#endif
storage/ndb/test/src/Makefile.am
View file @
c67d7e67
...
...
@@ -24,7 +24,7 @@ libNDBT_a_SOURCES = \
NdbRestarter.cpp NdbRestarts.cpp NDBT_Output.cpp
\
NdbBackup.cpp NdbConfig.cpp NdbGrep.cpp NDBT_Table.cpp
\
NdbSchemaCon.cpp NdbSchemaOp.cpp getarg.c
\
CpcClient.cpp NdbMixRestarter.cpp NDBT_Thread.cpp
CpcClient.cpp NdbMixRestarter.cpp NDBT_Thread.cpp
dbutil.cpp
INCLUDES_LOC
=
-I
$(top_srcdir)
/storage/ndb/src/common/mgmcommon
-I
$(top_srcdir)
/storage/ndb/include/mgmcommon
-I
$(top_srcdir)
/storage/ndb/include/kernel
-I
$(top_srcdir)
/storage/ndb/src/mgmapi
...
...
storage/ndb/test/src/dbutil.cpp
0 → 100755
View file @
c67d7e67
// dbutil.cpp: implementation of the database utilities class.
//
//////////////////////////////////////////////////////////////////////
#include "dbutil.hpp"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
dbutil
::
dbutil
(
const
char
*
dbname
)
{
memset
(
host
,
' '
,
sizeof
(
host
));
memset
(
user
,
' '
,
sizeof
(
pass
));
memset
(
dbs
,
' '
,
sizeof
(
dbs
));
port
=
0
;
memset
(
socket
,
' '
,
sizeof
(
socket
));
this
->
SetDbName
(
dbname
);
}
dbutil
::~
dbutil
()
{
this
->
DatabaseLogout
();
}
//////////////////////////////////////////////////////////////////////
// Database Login
//////////////////////////////////////////////////////////////////////
void
dbutil
::
DatabaseLogin
(
const
char
*
system
,
const
char
*
usr
,
const
char
*
password
,
unsigned
int
portIn
,
const
char
*
sockIn
,
bool
transactional
){
if
(
!
(
myDbHandel
=
mysql_init
(
NULL
))){
myerror
(
"mysql_init() failed"
);
exit
(
1
);
}
this
->
SetUser
(
usr
);
this
->
SetHost
(
system
);
this
->
SetPassword
(
password
);
this
->
SetPort
(
portIn
);
this
->
SetSocket
(
sockIn
);
if
(
!
(
mysql_real_connect
(
myDbHandel
,
host
,
user
,
pass
,
"test"
,
port
,
socket
,
0
))){
myerror
(
"connection failed"
);
mysql_close
(
myDbHandel
);
fprintf
(
stdout
,
"
\n
Check the connection options using --help or -?
\n
"
);
exit
(
1
);
}
myDbHandel
->
reconnect
=
1
;
/* set AUTOCOMMIT */
if
(
!
transactional
){
mysql_autocommit
(
myDbHandel
,
TRUE
);
}
else
{
mysql_autocommit
(
myDbHandel
,
FALSE
);
}
fprintf
(
stdout
,
"
\n\t
Connected to MySQL server version: %s (%lu)
\n\n
"
,
mysql_get_server_info
(
myDbHandel
),
(
unsigned
long
)
mysql_get_server_version
(
myDbHandel
));
}
//////////////////////////////////////////////////////////////////////
// Database Logout
//////////////////////////////////////////////////////////////////////
void
dbutil
::
DatabaseLogout
(){
if
(
myDbHandel
){
fprintf
(
stdout
,
"
\n\t
Closing the MySQL database connection ...
\n\n
"
);
mysql_close
(
myDbHandel
);
}
}
//////////////////////////////////////////////////////////////////////
// Prepare MySQL Statements Cont
//////////////////////////////////////////////////////////////////////
MYSQL_STMT
*
STDCALL
dbutil
::
MysqlSimplePrepare
(
const
char
*
query
){
#ifdef DEBUG
printf
(
"Inside dbutil::MysqlSimplePrepare
\n
"
);
#endif
int
result
=
0
;
MYSQL_STMT
*
my_stmt
=
mysql_stmt_init
(
this
->
GetDbHandel
());
if
(
my_stmt
&&
(
result
=
mysql_stmt_prepare
(
my_stmt
,
query
,
strlen
(
query
)))){
printf
(
"res = %s
\n
"
,
mysql_stmt_error
(
my_stmt
));
mysql_stmt_close
(
my_stmt
);
return
0
;
}
return
my_stmt
;
}
//////////////////////////////////////////////////////////////////////
// Error Printing
//////////////////////////////////////////////////////////////////////
void
dbutil
::
PrintError
(
const
char
*
msg
){
if
(
this
->
GetDbHandel
()
&&
mysql_errno
(
this
->
GetDbHandel
())){
if
(
this
->
GetDbHandel
()
->
server_version
){
fprintf
(
stdout
,
"
\n
[MySQL-%s]"
,
this
->
GetDbHandel
()
->
server_version
);
}
else
fprintf
(
stdout
,
"
\n
[MySQL]"
);
fprintf
(
stdout
,
"[%d] %s
\n
"
,
mysql_errno
(
this
->
GetDbHandel
()),
mysql_error
(
this
->
GetDbHandel
()));
}
else
if
(
msg
)
fprintf
(
stderr
,
" [MySQL] %s
\n
"
,
msg
);
}
void
dbutil
::
PrintStError
(
MYSQL_STMT
*
stmt
,
const
char
*
msg
)
{
if
(
stmt
&&
mysql_stmt_errno
(
stmt
))
{
if
(
this
->
GetDbHandel
()
&&
this
->
GetDbHandel
()
->
server_version
)
fprintf
(
stdout
,
"
\n
[MySQL-%s]"
,
this
->
GetDbHandel
()
->
server_version
);
else
fprintf
(
stdout
,
"
\n
[MySQL]"
);
fprintf
(
stdout
,
"[%d] %s
\n
"
,
mysql_stmt_errno
(
stmt
),
mysql_stmt_error
(
stmt
));
}
else
if
(
msg
)
fprintf
(
stderr
,
" [MySQL] %s
\n
"
,
msg
);
}
/////////////////////////////////////////////////////
int
dbutil
::
Select_DB
()
{
return
mysql_select_db
(
this
->
GetDbHandel
(),
this
->
GetDbName
());
}
////////////////////////////////////////////////////
int
dbutil
::
Do_Query
(
char
*
stm
)
{
return
mysql_query
(
this
->
GetDbHandel
(),
stm
);
}
////////////////////////////////////////////////////
const
char
*
dbutil
::
GetError
()
{
return
mysql_error
(
this
->
GetDbHandel
());
}
////////////////////////////////////////////////////
int
dbutil
::
GetErrorNumber
()
{
return
mysql_errno
(
this
->
GetDbHandel
());
}
////////////////////////////////////////////////////
unsigned
long
dbutil
::
SelectCountTable
(
const
char
*
table
)
{
unsigned
long
count
=
0
;
MYSQL_RES
*
result
;
char
query
[
1024
];
MYSQL_ROW
row
;
sprintf
(
query
,
"select count(*) from `%s`"
,
table
);
if
(
mysql_query
(
this
->
GetDbHandel
(),
query
)
||
!
(
result
=
mysql_store_result
(
this
->
GetDbHandel
())))
{
printf
(
"error
\n
"
);
return
1
;
}
row
=
mysql_fetch_row
(
result
);
count
=
(
ulong
)
strtoull
(
row
[
0
],
(
char
**
)
0
,
10
);
mysql_free_result
(
result
);
return
count
;
}
void
dbutil
::
Die
(
const
char
*
file
,
int
line
,
const
char
*
expr
){
fprintf
(
stderr
,
"%s:%d: check failed: '%s'
\n
"
,
file
,
line
,
expr
);
abort
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment